473,656 Members | 2,762 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4619
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.ActiveConne ction = 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.goo gle.com...
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.c om (Uttam) wrote in message news:<77******* *************** ****@posting.go ogle.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(st rObjectName 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$(strObjec tType) = "TABLE" Then
For Each tdf In db.TableDefs
If tdf.Name = strObjectName Then
ObjectExists = True
Exit For
End If
Next tdf
ElseIf UCase$(strObjec tType) = "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********@hotm ail.com (Pieter Linden) wrote in message news:<bf******* *************** ****@posting.go ogle.com>...
u0***@hotmail.c om (Uttam) wrote in message news:<77******* *************** ****@posting.go ogle.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(st rObjectName 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$(strObjec tType) = "TABLE" Then
For Each tdf In db.TableDefs
If tdf.Name = strObjectName Then
ObjectExists = True
Exit For
End If
Next tdf
ElseIf UCase$(strObjec tType) = "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.Open Schema(adSchema Tables, Array(Empty,
Empty, "Name of Particular Table")).BOF

CurrentProject. Connection.Open Schema(adSchema Views, Array(Empty,
Empty, "Name of Particular Table")).BOF
Nov 12 '05 #4
ly******@yahoo. com (Lyle Fairfield) wrote in
news:42******** *************** ***@posting.goo gle.com:
pi********@hotm ail.com (Pieter Linden) wrote in message news:

<bf************ **************@ posting.google. com>...
u0***@hotmail.c om (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(st rObjectName 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$(strObjec tType) = "TABLE" Then
For Each tdf In db.TableDefs
If tdf.Name = strObjectName Then
ObjectExists = True
Exit For
End If
Next tdf
ElseIf UCase$(strObjec tType) = "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.Open Schema(adSchema Tables, Array(Empty,
Empty, "Name of Particular Table")).BOF

CurrentProject. Connection.Open Schema(adSchema Views, Array(Empty,
Empty, "Name of Particular Table")).BOF


should be:

CurrentProject. Connection.Open Schema(adSchema Views, 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
1309
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 names but also output the sql code required to CREATE the table (i.e. CREATE TABLE example (exampleid auto_increment not null primary key integer, name text, email text);) - Is this pretty simple to do? Are there any free scripts online that...
1
1572
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 amount of queries.....I would also like to cycle through this and neatly associate notes with them to remind me of their specific purpose. The naming of the query can only go so far.
4
5824
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
23921
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 but the table column names. I've seen other posts that suggest using the SQL command DESCRIBE but I can't get it to work for some reason. Other posts have code samples but they're written in VB which I am not familiar with. I
5
1472
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
23905
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 populate a combo with this information? Then, once this value is selected, how can I populate other combos with the column names of the selected table? Thanks,
1
3334
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
10291
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 can't figure out the coding to accomplish this. I have an Excel application that is a monster and it has become too much to maintain and test. I didn't write it but i support it. I am trying to convert this application to Access and it is not as...
4
8863
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 the tables together with various queries using a unique id. My task is to generate reports from these tables dynamically. The user will select the data they want to see and the script will export a spreadsheet containing this data. I've got the...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8717
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8498
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8600
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7311
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1930
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1600
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.