Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 165
  • Last Modified:

Checking databases table

I wanna check if my database (Access)contains certain table. Below is an example how I tryed to do it but it didn't work.

MyData.DatabaseName = MyFile
 
For i = 0 To MyData.Database.TableDefs.Count - 1

 If MyData.Database.TableDefs(i).Name = "MyTable" Then
   ThereIsOne = True
 End If

Next

Could you give an example.

Thanks in advance!
0
majala
Asked:
majala
  • 2
1 Solution
 
pinshahCommented:
Public Function IsTableExist(TableName As String) As Boolean
Dim o As Database
Dim stext As String

On Error Goto DBErrorHandler

Set o = OpenDatabase(DatabaseFile)
o.TableDefs.Count
stext =   o.TableDefs(TableName).Name

IsTableExist = True


Exit Function

DBErrorHandler:
'Handle the errnumber which DAO throws
'if the table entry is not found i think its 3265

if Err.Number = 3265 Then
IsTableExist = False
End if

End Function
0
 
pinshahCommented:
One change remove the o.tabledefs.count
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now