Click to See Complete Forum and Search --> : Define Table
alwsid
Feb 17th, 2000, 09:39 AM
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
Forest Dragon
Feb 17th, 2000, 07:24 PM
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
alwsid
Feb 20th, 2000, 09:34 PM
Thanks Forest Dragon..
But how if i'm using DAO, because i'm not familiar with ADO.
JohnAtWork
Feb 22nd, 2000, 12:27 AM
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).]
alwsid
Feb 23rd, 2000, 12:11 PM
Yes John, In Access it's work but in vb error number 91.
Hope someone can help.
Clunietp
Feb 23rd, 2000, 01:01 PM
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
Clunietp
Feb 23rd, 2000, 01:02 PM
wow! color coded. I like the new layout, despite the fact that this server probably runs linux....
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.