VB connect to Access Database question.

J

jason

my access database name is test.mdb
inside this database have two fields,name and number
and the form have one command and one datagrid.
following is my coding about to link that databse, but
also can't connect,anyone can correct my code or tell me
how to do....thx

Private Sub cmd1_Click()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim cnstr As String
Dim i As Integer
Set cn = New ADODB.Connection
cn.Connectstring = "Provider=Microsoft.Jet.OLEDB.3.51;"
& "Data Source=c:\jason file\testing\test.mdb"

cn.Open cnstr
Set rs = New ADODB.Recordset
rs.Open "test", cn

For i = 1 To 4
data = rs!Name
rs.MoveNext
Next i
rs.Close
cn.Close

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top