Connect to MSAccess database using data control


The following code will connect to MSAccess database using datacontrol and sql syntax.



'add a data control to your application
'add a command button

‘form load add the following code
Private Sub Form_Load()

    Data1.RecordsetType = 1
    Data1.DatabaseName = Your Database Path 'ex. c:\\batabasename.mdb

End Sub

Private Sub Command1_Click

     With Data1
          .RecordSource = "SELECT * FROM tablename"
          .Refresh
          With .Recordset
               If .BOF = True Then
                    Msgbox "No Current Record"
               Else
                    Msgbox "Current Records Found"
               End If
          End With
     End With

End Sub




Added on September 1, 2008 Comment
}