Results 1 to 8 of 8

Thread: can anyone see an error in this rs.update code?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2005
    Posts
    18

    can anyone see an error in this rs.update code?

    '* Open a new connection
    Set conn2 = New ADODB.Connection
    Set rs2 = New ADODB.Recordset

    conn2.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\atm.mdb;" & _
    "Persist Security Info=False"

    '* update balance information for user
    rs2.Open "UPDATE Users SET Balance = " & balanceleft & "WHERE userID = " & txtuserID.Text, _
    conn2, adOpenForwardOnly, adLockReadOnly, adCmdText

    rs2.Update

    '* close rs connection
    rs2.Close
    Set rs2 = Nothing




    I'm having problems getting the above code to update the database, any ideas? thanks

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: can anyone see an error in this rs.update code?

    First (and without going through your syntax) use connection object to execute update sql statement:

    strSQL = "Update ..."
    conn2.Execute strSQL

    You may need to Resynq your recordset if it's already open:

    RS2.Resync adAffectAllChapters, adResyncAllValues

  3. #3
    Addicted Member Kezmondo's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    166

    Re: can anyone see an error in this rs.update code?

    What's the error?

    Is Balance a string or a number?

    For a start, I think you've missed a space character before the WHERE statement which will make your SQL invalid.
    Should be: ... balanceleft & " WHERE userID = " & ...

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Apr 2005
    Posts
    18

    Re: can anyone see an error in this rs.update code?

    balanceleft is a number, the error says operation not allowed while connection is closed..It now updates the database tho lol

  5. #5
    Junior Member
    Join Date
    Apr 2005
    Posts
    18

    Re: can anyone see an error in this rs.update code?

    Try this one .it will solve ur problem

    Set cn = New ADODB.Connection

    if cn.state=adstateopen then cn.close
    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\atm.mdb;" & _
    "Persist Security Info=False"

    '* update balance information for user
    cn.execute "UPDATE Users SET Balance = " & balanceleft & "WHERE userID = " & txtuserID.Text


    code by ashish sharma

  6. #6
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: can anyone see an error in this rs.update code?

    Quote Originally Posted by ashish sharma
    Try this one .it will solve ur problem

    Set cn = New ADODB.Connection

    if cn.state=adstateopen then cn.close
    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\atm.mdb;" & _
    "Persist Security Info=False"

    '* update balance information for user
    cn.execute "UPDATE Users SET Balance = " & balanceleft & "WHERE userID = " & txtuserID.Text


    code by ashish sharma
    Do you Ashish ever read replies before posting your own ???

    Here is what I suggested more than an hour before you did

    strSQL = "Update ..."
    conn2.Execute strSQL

  7. #7
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: can anyone see an error in this rs.update code?

    thejoker,

    90% of your SQL Statement problems will go away if you use code similar to what RhinoBull suggest and after doing a statement like

    strSQL = "Update ..."

    You do a

    Debug.Print strSQL

    You generally will see obvious typos, Bad SQL syntax and problems of that sort.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Apr 2005
    Posts
    18

    Re: can anyone see an error in this rs.update code?

    thanks a lot for the help guys

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width