Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Check if table exists

Status
Not open for further replies.

humpydumpy2000

IS-IT--Management
Aug 18, 2016
30
0
0
PH
Hi, I do have a temporary table that is automatically deleted on application exit. However there are instances where I have to kill the app of course the temporary table will not be deleted. I can error trap when table exists to replace or delete temporary table however my problem is how to check if table exists at start up and delete it using vba function. Any suggestion would be highly appreciated. Thanks in advance :)
 

for starters
Code:
 if not isnull(dlookup("Name"  ,"MSysObjects","type in(1,6) and Name='Tablename'" )) then msgbox "Table Exist"
 
You can use this function. Put in a standard module.
Code:
Function TableExists(strTableName As String) As Boolean
'[URL unfurl="true"]http://www.pcreview.co.uk/forums/there-way-test-if-table-exists-vba-t1145544.html[/URL]
On Error Resume Next
TableExists = IsObject(CurrentDb.TableDefs(strTableName))
End Function

Then to call it

Code:
If TableExists("YourTableName") = True Then
 
For additional help you may want to look here and here

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top