-
can't open my database
hello everyone,
i'm newbie to ado, i wrote the folowing code, and i get
an error message on the bold row:
" method 'open' of object '_recordset' failed"
my code is:
Dim oCn As ADODB.Connection
Dim oRs As ADODB.Recordset
Private Sub cmdAdd_Click()
With oRs
.AddNew
.Fields("name") = txtName.Text
.Fields("age") = txtAge.Text
.Update
End With
End Sub
Private Sub Form_Load()
Set oCn = New ADODB.Connection
Set oRs = New ADODB.Recordset
Dim sConnect As String
sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Documents and Settings\ofir\Desktop\vb\database\VBtest.mdb"
oCn.Open sConnect
oRs.Open "names", oCn, adOpenKeyset, adLockOptimistic, adCmdTable
End Sub
does anyone knows how to solve it?
-
After the oCn line, check if ocn.State = adStateOpen. What do you get?
-
do have table 'names' at ur 'VBTest.mdb'?
-
i've checked it
i get oCn.state=1
and yes i've got "names" table on my database
-
Names is a Keyword or a Reserved word. When a Keyword is usesd to name a database object, you must surround it with square brackets in your sql statement.
oRs.Open "[names]", oCn, adOpenKeyset, adLockOptimistic, adCmdTable
-
you're a jenius
where have you been all day?
it's working, thanks! :)
-
All day! The day just started....;)