Results 1 to 7 of 7

Thread: can't open my database

  1. #1
    New Member
    Join Date
    Oct 04
    Posts
    5

    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?

  2. #2
    ASP.NET Moderator mendhak's Avatar
    Join Date
    Feb 02
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174
    After the oCn line, check if ocn.State = adStateOpen. What do you get?

  3. #3
    Fanatic Member
    Join Date
    Sep 04
    Location
    Jakarta, Indonesia
    Posts
    818
    do have table 'names' at ur 'VBTest.mdb'?

  4. #4
    New Member
    Join Date
    Oct 04
    Posts
    5

    i've checked it

    i get oCn.state=1
    and yes i've got "names" table on my database

  5. #5
    PowerPoster
    Join Date
    Oct 02
    Location
    British Columbia
    Posts
    9,758
    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.

  6. #6
    New Member
    Join Date
    Oct 04
    Posts
    5

    you're a jenius

    where have you been all day?

    it's working, thanks!

  7. #7
    PowerPoster
    Join Date
    Oct 02
    Location
    British Columbia
    Posts
    9,758
    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
  •