Finding a table in a table collection...

J

jpang

Hello,

I would like to know how I can do the following task. I would like to use
code to find a table with a specific name in my list of tables in my current
database. If the table is found, then refresh link to another table. If the
table is not found, then create the table in my current database.

Thanks for your help.
 
J

John W. Vinson

Hello,

I would like to know how I can do the following task. I would like to use
code to find a table with a specific name in my list of tables in my current
database. If the table is found, then refresh link to another table. If the
table is not found, then create the table in my current database.

Thanks for your help.

Currentdb.Tabledefs("yourtablename").Name

will have a value if the table exists (its value will be "yourtablename" of
course). You can check that condition and then branch to either the
CreateRelation method or the CreateTable method - see the online help for
these.
 
J

jpang

I tried that. I get an error message saying that the item cannot be found in
the collection. I want to be able to use the code to test whether the table
exists in the collection or not without running into the error message. Is
that some sort of .NoMatch property for this sort of finding of tables?

Thanks for your help.
 
J

John W. Vinson

I tried that. I get an error message saying that the item cannot be found in
the collection. I want to be able to use the code to test whether the table
exists in the collection or not without running into the error message. Is
that some sort of .NoMatch property for this sort of finding of tables?

That's the heart of what I'm suggesting. Note the error number and put in an
ON Error condition to trap it:

On Error GoTo Proc_Error
<your code here>
Proc_Exit:
Exit Sub
Proc_Error:
Select Case Err.Num
Case 1234 <or whatever the error number is>
Resume NewTable <jump to the code that creates the table>
Case Else
Resume EditTable <jump to the code that edits the table
End Select
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top