This code need Notes to understand

1

1aae

If I have table name (tblemployee) How to find out if a table exists in a database using this code from MVP Access Site:
If You could please give Notes For the next code...
or how to use the next code to find out if a table exists in a database (tblemployee)..by using command button
(I'm just a user)
example if the tblemployee in the data base display message box (The table exist)

---Posted by Dev Ashish---
---------------------------------------------------------------------------
Tables: How to find out if a table exists in a database
---------------------------------------------------------------------------

(Q) How do I find out if a table exists in a database?

(A) One simple way is to recurse through the TableDefs collection of the database. For example, the following function will return true if the specified table exists, False if it doesn't.

'******************** Code Start ************************
'This code was originally written by Dev Ashish.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
Function fExistTable(strTableName As String) As Integer
Dim db As Database
Dim i As Integer
Set db = DBEngine.Workspaces(0).Databases(0)
fExistTable = False
For i = 0 To db.TableDefs.Count - 1
If strTableName = db.TableDefs(i).Name Then
'Table Exists
fExistTable = True
Exit For
End If
Next i
Set db = Nothing
End Function
'******************** Code End ************************
 

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