Does Object (a Table) exist

  • Thread starter Thread starter Greg Jackson
  • Start date Start date
G

Greg Jackson

I am using Access 2002. I am using the TransferDatabase
Action within a macro to import a table from one DB to
another. When I run the macro, it adds the table and
appends a 1 to the end of the table name. I then use the
DeleteObject action to delete the old table and the
Rename action to rename the new table. (Example: Table
name is Trucks. I Delete Trucks and rename Trucks1 to
Trucks). However, If the table didn't exist, the macro
simply deletes the new file. I need to find a way to
determine if the table exists in Access 2002. Thanks in
advance!
 
I don't use macros (except Autoexec or Autokeys) but a solution to your
question could be to copy and paste this function in a standar module

Function FindTable(TableName As String) As Boolean
Dim tdf As Object

On Error GoTo TableNotFound
Set tdf = CurrentDb.TableDefs(TableName)
Set tdf = Nothing
FindTable = True

Exit Function

TableNotFound:

End Function

and then, in your macro

condition: FindTable("Here_your_table_name") = True
action: TransferDatabase ...

etc, etc

HTH

Saludos,
Juan M Afan de Ribera
[MVP Access]
http://www.mvp-access.com/juanmafan
 
Back
Top