Monday, August 22, 2011

Check if the Table is Exist or Not In Access DataBase

If you want to Check the particular table is exist in Access Database or Not  You Can use this Function :



Option Compare Text
Sub IsExist()
Dim cn As ADODB.Connection
    Dim rst As Recordset
    Dim MyConn As String
    MyConn = "D:\MyDataBase.accdb"
    Set cn = New ADODB.Connection


    With cn
    .Provider = "Microsoft.ace.Oledb.12.0"
    .Open MyConn
    End With
            
        Set rst = cn.OpenSchema(adSchemaTables)
        rst.MoveFirst
        Do Until rst.EOF
                If rst!Table_Name = "MyTable1" Then
                MsgBox "Table Exist "
                Exit Do
                End If
                rst.MoveNext
        Loop
        
        rst.Close
        cn.Close
End Sub





No comments: