Solved

Checking databases table

Posted on 2000-03-21
2
142 Views
Last Modified: 2010-05-02
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
Comment
Question by:majala
  • 2
2 Comments
 

Accepted Solution

by:
pinshah earned 50 total points
ID: 2643435
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
 

Expert Comment

by:pinshah
ID: 2643438
One change remove the o.tabledefs.count
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question