INDEX

VBA - Table existence check in the MDB.

VBA - Table existence check in the MDB.

Sub btn1_Click()
    Dim dbCon As New ADODB.Connection
    Dim dbCat As New ADOX.Catalog
    Dim dbTbl As New ADOX.Table
    Dim blChk As Boolean
    
    blChk = False
    
    Set dbCon = New ADODB.Connection
    
    dbCon.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
        "Data Source=sample.mdb;" & _
        "Jet OLEDB:Database Password=password;"
    
    dbCon.Open
    
    Set dbCat = New ADOX.Catalog
    Set dbCat.ActiveConnection = dbCon
    For Each dbTbl In dbCat.Tables
        If dbTbl.Type = "TABLE" And dbTbl.Name = "table name" Then
            blChk = True
        End If
    Next dbTbl
    
    Set dbCat = Nothing
    
    dbCon.Close
    Set dbCon = Nothing
    
    If blChk Then
        MsgBox "OK"
    Else
        MsgBox "NG"
    End If
End Sub


Copyright(c) 2007-2020 coding.dojeun.com All Rights Reserved.