how can we connect with ms-access?
Printable View
how can we connect with ms-access?
It can be in this way
<vbcode>
Public conn As ADODB.Connection
Public rsWord As ADODB.Recordset
Set conn = New Connection
With conn
.Provider = "Microsoft.Jet.OLEDB.4.0"
' or you can use 3.51 also
.ConnectionString = App.Path & "\YourDatabase.mdb"
' specify path if database not located in project directory and then mdb name
.Open
End With
Set rsWord = New Recordset
If rsWord .State = adStateOpen Then rsWord .Close
rsWord .Open "Select * from employee ", conn, adOpenKeyset, adLockOptimistic
txtempno = rsWord !empno ' or rsGmHira.Fields(0) like that
</vbcode>
Regards
Gary
Just to expand on champgary's information a little:
1. For this code to work you will need to set a reference (Project | References) to Microsoft ActiveX Data Objects 2.x
2. This provider string: .Provider = "Microsoft.Jet.OLEDB.4.0" is appropriate for Access 2000 mdb's
3. You can use this provider string: .Provider = "Microsoft.Jet.OLEDB.3.51" for Access97