Results 1 to 7 of 7

Thread: Define Table

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 1999
    Location
    Malaysia
    Posts
    108

    Post

    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


  2. #2
    Addicted Member
    Join Date
    Oct 1999
    Posts
    253

    Post

    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


  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 1999
    Location
    Malaysia
    Posts
    108

    Post

    Thanks Forest Dragon..

    But how if i'm using DAO, because i'm not familiar with ADO.

  4. #4
    Lively Member
    Join Date
    Jul 1999
    Posts
    78

    Post

    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).]

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 1999
    Location
    Malaysia
    Posts
    108

    Post

    Yes John, In Access it's work but in vb error number 91.
    Hope someone can help.

  6. #6
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    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

  7. #7
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    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
  •  



Click Here to Expand Forum to Full Width