By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,495 Members | 994 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,495 IT Pros & Developers. It's quick & easy.

how to check if table exists in Access with ADO?

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.