views:

53

answers:

4

Hi friends, i am new to vba macros. Any idea to check the table if it is exists or not? I check with previous post and idea, but not got clear solution for this. Please provide your idea.

Thanks in Advance Friends.

+2  A: 
Exists = IsObject(CurrentDb.TableDefs(tablename))
Tobiasopdenbrouw
Karthik
Practically speaking, you can't use it by itself. It has to be wrapped in an error handler so that it returns false when it encounters error 3265. See http://stackoverflow.com/questions/2985513/check-if-access-table-exists/2992743#2992743 for 3 different implementations of a TableExists() function.
David-W-Fenton
A: 

Access has some sort of system tables You can read about it a little here you can fire the folowing query to see if it exists ( 1 = it exists, 0 = it doesnt ;))

SELECT Count([MSysObjects].[Name]) AS [Count]
FROM MSysObjects
WHERE (((MSysObjects.Name)="TblObject") AND ((MSysObjects.Type)=1));
Sjuul Janssen
That will miss linked tables, type=4.
Remou
+1  A: 

This is not a new question. I addresed it in comments in one SO post, and posted my alternative implementations in another post. The comments in the first post actually elucidate the performance differences between the different implementations.

Basically, which works fastest depends on what database object you use with it.

David-W-Fenton
A: 

Finally i search and got the result,

I used this function,

Public Function ifTableExists(tblName As String) As Boolean

ifTableExists = False
If DCount("[Name]", "MSysObjects", "[Name] = '" & tblName & "'") = 1 Then
ifTableExists = True
End If

End Function

I also verified previous post but not got any correct answer. This is worked for me a great. thanks guys for your help and support.

For this one, have to choose the Microsoft Access 12.0 Object Library. It is in the references in Menu Bar Tools.

Karthik