|
-
Oct 26th, 2004, 03:45 AM
#1
Thread Starter
New Member
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?
-
Oct 26th, 2004, 03:48 AM
#2
After the oCn line, check if ocn.State = adStateOpen. What do you get?
-
Oct 26th, 2004, 03:50 AM
#3
Fanatic Member
do have table 'names' at ur 'VBTest.mdb'?
-
Oct 26th, 2004, 04:30 AM
#4
Thread Starter
New Member
i've checked it
i get oCn.state=1
and yes i've got "names" table on my database
-
Oct 26th, 2004, 10:25 AM
#5
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
Last edited by brucevde; Oct 26th, 2004 at 10:28 AM.
-
Oct 26th, 2004, 10:34 AM
#6
Thread Starter
New Member
you're a jenius
where have you been all day?
it's working, thanks!
-
Oct 26th, 2004, 11:00 AM
#7
All day! The day just started....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|