473,395 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Detecting names of Tables and Queries in Catalog

Hello,

Could someone point me to the syntax required to detected whether a
particular table (say tbl1) and a particular Query (Qry1) exists in
the catalog?

Thank you in advance.

Cheers!

Uttam
Nov 12 '05 #1
4 4608
Presumably you want ADOX, as you use the term "catalog". The Type
distinguishes whether is a Table, View, etc.

Function ShowAllTables()
Dim cat As New ADOX.Catalog 'Root object of ADOX.
Dim tbl As ADOX.Table 'Each Table in Tables.

'Point the catalog to the current project's connection.
Set cat.ActiveConnection = CurrentProject.Connection

'Loop through the tables.
For Each tbl In cat.Tables
Debug.Print tbl.Name, tbl.Type
Next

'Clean up
Set tbl = Nothing
Set cat = Nothing
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html

"Uttam" <u0***@hotmail.com> wrote in message
news:77**************************@posting.google.c om...
Could someone point me to the syntax required to detected whether a
particular table (say tbl1) and a particular Query (Qry1) exists in
the catalog?

Nov 12 '05 #2
u0***@hotmail.com (Uttam) wrote in message news:<77**************************@posting.google. com>...
Hello,

Could someone point me to the syntax required to detected whether a
particular table (say tbl1) and a particular Query (Qry1) exists in
the catalog?

Thank you in advance.

Cheers!

Uttam


Using DAO...
Option Compare Database
Option Explicit

Public Function ObjectExists(strObjectName As String, strObjectType As
String) As Boolean
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim tdf As DAO.TableDef

'Assume failure
ObjectExists = False

Set db = CurrentDb
If UCase$(strObjectType) = "TABLE" Then
For Each tdf In db.TableDefs
If tdf.Name = strObjectName Then
ObjectExists = True
Exit For
End If
Next tdf
ElseIf UCase$(strObjectType) = "QUERY" Then
For Each qdf In db.QueryDefs
If qdf.Name = strObjectName Then
ObjectExists = True
Exit For
End If
Next qdf
End If

Set qdf = Nothing
Set tdf = Nothing
Set db = Nothing
End Function
Nov 12 '05 #3
pi********@hotmail.com (Pieter Linden) wrote in message news:<bf**************************@posting.google. com>...
u0***@hotmail.com (Uttam) wrote in message news:<77**************************@posting.google. com>...
Hello,

Could someone point me to the syntax required to detected whether a
particular table (say tbl1) and a particular Query (Qry1) exists in
the catalog?

Thank you in advance.

Cheers!

Uttam


Using DAO...
Option Compare Database
Option Explicit

Public Function ObjectExists(strObjectName As String, strObjectType As
String) As Boolean
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim tdf As DAO.TableDef

'Assume failure
ObjectExists = False

Set db = CurrentDb
If UCase$(strObjectType) = "TABLE" Then
For Each tdf In db.TableDefs
If tdf.Name = strObjectName Then
ObjectExists = True
Exit For
End If
Next tdf
ElseIf UCase$(strObjectType) = "QUERY" Then
For Each qdf In db.QueryDefs
If qdf.Name = strObjectName Then
ObjectExists = True
Exit For
End If
Next qdf
End If

Set qdf = Nothing
Set tdf = Nothing
Set db = Nothing
End Function

CurrentProject.Connection.OpenSchema(adSchemaTable s, Array(Empty,
Empty, "Name of Particular Table")).BOF

CurrentProject.Connection.OpenSchema(adSchemaViews , Array(Empty,
Empty, "Name of Particular Table")).BOF
Nov 12 '05 #4
ly******@yahoo.com (Lyle Fairfield) wrote in
news:42**************************@posting.google.c om:
pi********@hotmail.com (Pieter Linden) wrote in message news:

<bf**************************@posting.google.com>. ..
u0***@hotmail.com (Uttam) wrote in message news: <77**************************@posting.google.com>. ..
> Hello,
>
> Could someone point me to the syntax required to detected whether a
> particular table (say tbl1) and a particular Query (Qry1) exists in
> the catalog?
>
> Thank you in advance.
>
> Cheers!
>
> Uttam


Using DAO...
Option Compare Database
Option Explicit

Public Function ObjectExists(strObjectName As String, strObjectType As
String) As Boolean
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim tdf As DAO.TableDef

'Assume failure
ObjectExists = False

Set db = CurrentDb
If UCase$(strObjectType) = "TABLE" Then
For Each tdf In db.TableDefs
If tdf.Name = strObjectName Then
ObjectExists = True
Exit For
End If
Next tdf
ElseIf UCase$(strObjectType) = "QUERY" Then
For Each qdf In db.QueryDefs
If qdf.Name = strObjectName Then
ObjectExists = True
Exit For
End If
Next qdf
End If

Set qdf = Nothing
Set tdf = Nothing
Set db = Nothing
End Function

CurrentProject.Connection.OpenSchema(adSchemaTable s, Array(Empty,
Empty, "Name of Particular Table")).BOF

CurrentProject.Connection.OpenSchema(adSchemaViews , Array(Empty,
Empty, "Name of Particular Table")).BOF


should be:

CurrentProject.Connection.OpenSchema(adSchemaViews , Array(Empty,
Empty, "Name of Particular Query")).BOF
--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: bissatch | last post by:
Hi, Is it possible to write a script that, when provided with a database, it will return all the tables names? I will go onto try and put together a script that will not only output the table...
1
by: jason | last post by:
Access 2000 I would like to be able to generate table reports listing all the TABLE NAMES, FIELDS and their datatypes in a neatly formatted table. Additionally I am building up a frightening...
4
by: Mlaky | last post by:
I'm using VB and I need to get all table names in database. How can I do that? Thank you.
2
by: Joe | last post by:
Hi All, I am new to using the Access DB and I need some help if someone is able to give it to me. What I want to do is get the names of the columns of certain tables. Not the data in the table...
5
by: Gavin | last post by:
How do I, in VB get the names of all the tables in an Access data bas Also, how do I programatically get all the field names in a specific table Much appreciated.
4
by: Steven Smith | last post by:
Hello all, I have a vb6 (not .NET) program using MS Access as the backend. As part of an import form, I need to allow the user to select the table containing the data to be imported. How can I...
1
by: racquetballguy | last post by:
Hi I have data tables in the form of 200612... 200701... 200702... etc The user specifies the start date and end date in an input form ie: 12/25/2006 - 1/10/2007.
11
by: Tim Hunter | last post by:
Hi I am using WinXP and Access 2003 Is it possible to store the field names of a table in an array and then loop through the array and update the table using the field names stored in the array? I...
4
by: dreaken667 | last post by:
I have a MySQL database containing 16 tables of data. Each table has a different number of columns and there are few common field names accross tables. I do have one master table with which I connect...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.