|
-
Nov 17th, 2000, 09:57 AM
#1
Thread Starter
Addicted Member
How can I check if a table exist in a database using VB?
"It wasn't the booze that made me snooze, It was the Gin that did me in!"
-
Nov 17th, 2000, 10:40 AM
#2
Hyperactive Member
try this:
Note: I declared here the database, but you have to use your main connection (of your app).
Function f_ExistYourTable(str_Table As String) As Boolean
Dim int_I As Integer
Dim db As Database
f_ExistYourTable = False
For int_I = 0 To db.TableDefs.Count - 1
If UCase$(Trim$(str_Table)) = UCase$(Trim$(db.TableDefs(int_I).Name)) Then
f_ExistYourTable = True
Exit Function
End If
Next
End Function
If things were easy, users might be programmers.
-
Nov 17th, 2000, 09:48 PM
#3
Well ...
There are a number of ways to do this:
You can follow JP's way with Access. With other databases, it may not work. What you can use is :
System tables: In Oracle, SQL Server or even in Access you have system tables in the database to store information about all objects in the database. Use these tables to find out if your table exists in them.
Error Trapping: You can trap almost all database errors in VB. So just put the error handler where you are accessing a table. If the table does not exist, you can trap the specific error and take necessary action.
You will try to discard the second approach, but it has a big advantage over others. You don't have to check for the existence of a table every time you use it in a query.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|