ADawn
asked on
Check for Table in Database
Hello,
VB6(sp4), ADO, Access 97
Prior to my starting application, I check for the proper database and path:
If Dir$(App_Inventory) = 0 then ...do somthing
Next, I want check to see if the database that my application is about to connect to is (in fact) the correct database. To verify this, I'd like to check the first table ( tbl_KGRM ) to make sure it is the correct database.
Thanks,
-ADawn
VB6(sp4), ADO, Access 97
Prior to my starting application, I check for the proper database and path:
If Dir$(App_Inventory) = 0 then ...do somthing
Next, I want check to see if the database that my application is about to connect to is (in fact) the correct database. To verify this, I'd like to check the first table ( tbl_KGRM ) to make sure it is the correct database.
Thanks,
-ADawn
Here is the function I use. It uses DAO, but it should give you an idea of how to do it.
Public Function dbTableExists(sTableName As String) As Boolean
' returns true if the table exists in the database
Dim i As Integer
Dim Db As DAO.Database
dbTableExists = False
Set Db = OpenDatabase(dbName$)
For i = 0 To Db.TableDefs.Count - 1
If Trim(UCase(Db.TableDefs(i) .Name)) = Trim(UCase(sTableName)) Then dbTableExists = True
Next i
Db.Close
End Function
Public Function dbTableExists(sTableName As String) As Boolean
' returns true if the table exists in the database
Dim i As Integer
Dim Db As DAO.Database
dbTableExists = False
Set Db = OpenDatabase(dbName$)
For i = 0 To Db.TableDefs.Count - 1
If Trim(UCase(Db.TableDefs(i)
Next i
Db.Close
End Function
For i = 0 To Db.TableDefs.Count - 1
If Trim(UCase(Db.TableDefs(i) .Name)) = Trim(UCase(sTableName)) Then
dbTableExists = True
Exit Function
endif
Next i
If Trim(UCase(Db.TableDefs(i)
dbTableExists = True
Exit Function
endif
Next i
anybody have it in ADO?
set a reference to the Microsoft ADO Ext 2.1 for DLL and Security then paste this code:
Dim SourceCat as ADOX.Catalog
Dim SrcTbl as ADOX.Table
Dim oColumn as ADOX.Column
Dim x as as Integer
set SourceCat = new ADOX.Catalog
SourceCat.ActiveConnection = "Your Regular ADO connecionstring"
for x = 1 to SourceCat.Tables.Count
List1.AddItem SourceCat.Tables(x).Name
next x
set SourceCat = nothing
Instead of adding table to the listbox you can check if it is a desired table name
Dim SourceCat as ADOX.Catalog
Dim SrcTbl as ADOX.Table
Dim oColumn as ADOX.Column
Dim x as as Integer
set SourceCat = new ADOX.Catalog
SourceCat.ActiveConnection
for x = 1 to SourceCat.Tables.Count
List1.AddItem SourceCat.Tables(x).Name
next x
set SourceCat = nothing
Instead of adding table to the listbox you can check if it is a desired table name
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
TimCottee
Works great - Thanks for the extra insight.
iboutchkine
I have posted points for you as well. Thanks
Works great - Thanks for the extra insight.
iboutchkine
I have posted points for you as well. Thanks
Data1.RecordSource = "Select * from Lead"
Data1.Refresh
For i = 1 To Data1.Database.TableDefs.C
List2.AddItem Data1.Database.TableDefs(i
Next i
'Hope can help you little.