|
-
Feb 17th, 2000, 10:39 AM
#1
Thread Starter
Lively Member
Hello...
How to test whether the table is exist or not like we test the file.
ex:
if Dir(myFile)<>"" Then
msgbox"Your File is =>" & myFile
else
msgbox"Your File doesn't exist
endif
-
Feb 17th, 2000, 08:24 PM
#2
Addicted Member
If you are using ADO, try this way:
Dim Conn As Connection
Dim RecSet As ADODB.Recordset
Dim Counter As Integer,Found As Boolean
Set Conn=New Connection
Conn.Open ...
Set RecSet=Conn.OpenSchema(adSchemaTables)
RecSet.MoveFirst
Counter=1
Found=False
Do While Not Found And _ Counter<=RecSet.RecordCount
If RecSet.Fields("TABLE_NAME")=Table Then
Found=True
End If
Counter=Counter+1
RecSet.MoveNext
Loop
If Found Then
MsgBox "Found"
Else MsgBox "Not Found"
End If
-
Feb 20th, 2000, 10:34 PM
#3
Thread Starter
Lively Member
Thanks Forest Dragon..
But how if i'm using DAO, because i'm not familiar with ADO.
-
Feb 22nd, 2000, 01:27 AM
#4
Lively Member
I tested this in an Access environment and it worked spiffy.
On error goto Oops
Dim db as Database
Dim rst as Recordset
Dim tbl as String ' This is the Table you're looking for
' Set up some kind of input to bind tbl to the recordset you're looking for. I used the following:
tbl = InputBox("Do it")
Set db = CurrentDB ' Or the proper DB string
Set rst = db.OpenRecordset(tbl)
msgbox "Recordset " & tbl & " is open and ready for manipulation"
Exit Sub
Oops:
'This is the real meat of the code to do it.
If err.number = 3078 Then
msgbox "Recordset " & tbl & " doesn't exist."
Else
msgbox" Error: " & err.number & " - " & err.description
Exit Sub
End If
End Sub
[This message has been edited by JohnAtWork (edited 02-22-2000).]
-
Feb 23rd, 2000, 01:11 PM
#5
Thread Starter
Lively Member
Yes John, In Access it's work but in vb error number 91.
Hope someone can help.
-
Feb 23rd, 2000, 02:01 PM
#6
Guru
Code:
Dim db As Database
Dim tbl As TableDef
Dim blnExists As Boolean
Set db = DBEngine.OpenDatabase("Nwind.mdb")
For Each tbl In db.TableDefs
If tbl.Name = "Customers" Then
blnExists = True
End If
Next tbl
MsgBox blnExists
db.Close
Set db = Nothing
-
Feb 23rd, 2000, 02:02 PM
#7
Guru
wow! color coded. I like the new layout, despite the fact that this server probably runs linux....
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
|