473,387 Members | 1,578 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,387 software developers and data experts.

how to check if table exists in Access with ADO?

G G
I need to check if a table exists in Access using ADO externally. I
tried

"Select Name from MSysObjects Where Name = 'myTable'"

with the ADO command object, but I got an error than I don't have
permission to read MySysObjects. Is there another way to check without
having to use On Error Resume Next?

Thanks,
GG

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #1
7 14487
ADO is only half the story. For information on the database schema, you need
the ADOX library so you can examine the Tables collection of the Catalog.

Unfortunately, ADOX is really half-baked and unreliable.

It should be possible to read MSysObjects though (unless you are blocked by
MDW security).

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"G G" <an*******@discussions.com> wrote in message
news:40*********************@news.frii.net...
I need to check if a table exists in Access using ADO externally. I
tried

"Select Name from MSysObjects Where Name = 'myTable'"

with the ADO command object, but I got an error than I don't have
permission to read MySysObjects. Is there another way to check without
having to use On Error Resume Next?

Nov 12 '05 #2
G G
Thanks. Basically, I want to drop a table if it exists and then
recreate it. I guess On Error Resume Next it is.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3
G G <an*******@discussions.com> wrote in news:4097c919$0$202$75868355
@news.frii.net:
I need to check if a table exists in Access using ADO externally. I
tried

"Select Name from MSysObjects Where Name = 'myTable'"

with the ADO command object, but I got an error than I don't have
permission to read MySysObjects. Is there another way to check without
having to use On Error Resume Next?

Thanks,
GG


You could try

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

--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)
Nov 12 '05 #4
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in
news:40**********************@freenews.iinet.net.a u:
ADO is only half the story. For information on the database schema, you
need the ADOX library so you can examine the Tables collection of the
Catalog.


Why do you say that?

--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)
Nov 12 '05 #5
G G
There was actually one other thing I tried, along the same vein as ADOX.
I created a DropTable Function and a CreateTable Function. If the
DropTable function errors out I just resume next within the function and
exit out to the next call. Now, at least, the Resume Next's are
isolated within a function instead of all over the whole routine. I
can't figure out why I can't read MSysObjects with this:

strSql = "Select Name From MSysObjects Where Name = 'tbl1'"
cmd.CommandType = adCmdText
cmd.CommandText = strSql
cmd.Execute i

using acc97. will try later on a2k, a2002. In the meantime, the
functions seem to do the trick.

Thanks all for your replies.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #6
Will the new table have the same structure as the one you're deleting? If
so, it may be easier to just delete all of the data in the table.

--
Wayne Morgan
Microsoft Access MVP
"G G" <an*******@discussions.com> wrote in message
news:40*********************@news.frii.net...
Thanks. Basically, I want to drop a table if it exists and then
recreate it. I guess On Error Resume Next it is.

Nov 12 '05 #7
G G
Well, in this particular project, an end user will be selecting any
arbitrary (already existing) mdb file from an Open/Save Dialog box
(using api code) to pass specifically selected records from a
Non-Microsoft datasource. XYZ.mdb probably won't contain the temp table
tblxxxyyyzzz. But say the end user has already retrieved records from
the external datasource to the selected mdb file XYZ.mdb. If the end
user decides to select other records from the datasource to the same mdb
file, tblxxxyyyzzz will be dropped and a new tblxxxyyyzzz will be
re-created on the fly and the new selection of records will be
transferred to the table. If the end user wants to accumulate the
records, the records will have to be transferred to another table with
the same schema as tblxxxyyyzzz.

GG

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #8

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

Similar topics

2
by: Jonathan | last post by:
I am looking for a simple way to check if a database table exists. I keep getting advice to use "Try.. Catch" and other error handling methods, but I obviously don't want to have to display an...
1
by: G G | last post by:
I need to check if a table exists in Access using ADO externally. I tried "Select Name from MSysObjects Where Name = 'myTable'" with the ADO command object, but I got an error than I don't...
3
by: Anthony Bowman | last post by:
Hello, I have a access application that resides locally on users desk, I am writing a VB.Net interface that let's the users pull data down from a SQL server database and populate the local access...
10
by: Geoff Jones | last post by:
Hi I'm trying to drop a table by using: Dim cmd As New OleDbCommand("DROP TABLE IF EXISTS books", myconnection) cmd.ExecuteNonQuery() but I get a syntax error: "Syntax error in DROP TABLE...
9
by: Carl Fenley | last post by:
I am successfully adding stored procedures to an Access database. However, I need to be able to check if the stored procedure of the same name already exists. Is there a way to do this other...
5
by: Mike Charney | last post by:
I have an Access data project. In this project I have a form that when Access starts is loaded and this form has VBA code attached to it. One of the first things I need to do is check if a table...
2
by: RLN | last post by:
Re: Access 2003 I have code to check to see if a table exists. There are several other tables (tblQ12, tblQ13, etc) that do already exist & this code runs fine; msgbox says the value returned is...
6
by: BrianDP | last post by:
I have a table that has always been in my back-end of this application. The table is getting quite large, and, on top of that, we lose records out of this table. They just dissappear! No rhyme or...
16
by: Brian Tkatch | last post by:
Is there a way to check the order in which SET INTEGRITY needs to be applied? This would be for a script with a dynamic list of TABLEs. B.
4
by: jaishu | last post by:
Hi all, I am in the process of developing a small Access application. i have the table locally in Access and I am using the following code to get the recordcount ( or to check if any record...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
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...

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.