RecordSet Update

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • billybaub
    New Member
    • Feb 2008
    • 1

    RecordSet Update

    Hi,

    Im having a few problems with updating and deleting an item out of a recordset.
    I have a list box in a main form that lists all the items in the table. When you click on one it comes up with a new form that displays all the details in text boxes for that record. You are able to edit the text and there is a edit and also a delete record button. When you click them though, the record doesnt update or delete the record that was being viewed but deletes the record previous.

    Used the following code.

    [code=vb]
    Private Sub cmdUpdate_Click ()
    rs.Edit
    rs.Fields("Firs tName") = TextBox(txtFirs tName)
    rs.Fields("Last Name") = TextBox(txtLast Name)
    rs.Fields("Stre et") = TextBox(txtStre et)
    rs.Fields("Subu rb") = TextBox(txtSubu rb)
    rs.Fields("Stat e") = TextBox(txtStat e)
    rs.Fields("Post code") = TextBox(5)
    rs.Fields("Phon eNumber") = TextBox(txtPhon eNumber)
    rs.Fields("Mobi leNumber") = TextBox(txtMobi leNumber)
    rs.Fields("Emai l") = TextBox(txtEmai l)
    rs.Fields("Birt hday") = TextBox(txtBirt hday)
    rs.Update

    MsgBox ("Record Successfully Updated")

    End Sub
    [/code]
    Thanks
    Billybaub
    Last edited by debasisdas; Feb 6 '08, 11:26 AM. Reason: added code=vb tags
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    What is this TextBox in your code ?

    Comment

    • VBWheaties
      New Member
      • Feb 2008
      • 145

      #3
      Originally posted by billybaub
      Hi,

      Im having a few problems with updating and deleting an item out of a recordset.
      I have a list box in a main form that lists all the items in the table. When you click on one it comes up with a new form that displays all the details in text boxes for that record. You are able to edit the text and there is a edit and also a delete record button. When you click them though, the record doesnt update or delete the record that was being viewed but deletes the record previous.

      Used the following code.

      [code=vb]
      Private Sub cmdUpdate_Click ()
      rs.Edit
      rs.Fields("Firs tName") = TextBox(txtFirs tName)
      rs.Fields("Last Name") = TextBox(txtLast Name)
      rs.Fields("Stre et") = TextBox(txtStre et)
      rs.Fields("Subu rb") = TextBox(txtSubu rb)
      rs.Fields("Stat e") = TextBox(txtStat e)
      rs.Fields("Post code") = TextBox(5)
      rs.Fields("Phon eNumber") = TextBox(txtPhon eNumber)
      rs.Fields("Mobi leNumber") = TextBox(txtMobi leNumber)
      rs.Fields("Emai l") = TextBox(txtEmai l)
      rs.Fields("Birt hday") = TextBox(txtBirt hday)
      rs.Update

      MsgBox ("Record Successfully Updated")

      End Sub
      [/code]
      Thanks
      Billybaub
      Make sure the recordset is updateable. By Default, recordsets open as readonly. Programatically , it can be checked this way though you can easily see by viewing cursortype and locktype properties of your recordset object when you opened it:
      Code:
      If rs.supports(adUpdate) Then
         msgbox "recordset is updateable."
      Else
         msgbox "recordset is NOT updateable."
      End If

      Comment

      • werks
        New Member
        • Dec 2007
        • 218

        #4
        Originally posted by billybaub
        Hi,

        [code=vb]
        Private Sub cmdUpdate_Click ()
        rs.Edit
        rs.Fields("Firs tName") = TextBox(txtFirs tName)
        rs.Fields("Last Name") = TextBox(txtLast Name)
        rs.Fields("Stre et") = TextBox(txtStre et)
        rs.Fields("Subu rb") = TextBox(txtSubu rb)
        rs.Fields("Stat e") = TextBox(txtStat e)
        rs.Fields("Post code") = TextBox(5)
        rs.Fields("Phon eNumber") = TextBox(txtPhon eNumber)
        rs.Fields("Mobi leNumber") = TextBox(txtMobi leNumber)
        rs.Fields("Emai l") = TextBox(txtEmai l)
        rs.Fields("Birt hday") = TextBox(txtBirt hday)
        rs.Update

        MsgBox ("Record Successfully Updated")

        End Sub
        [/code]
        try this

        [code=vb]
        Private Sub cmdUpdate_Click ()
        rs.Update 'try this code here
        rs.Fields("Firs tName") = TextBox(txtFirs tName)
        rs.Fields("Last Name") = TextBox(txtLast Name)
        ....
        ....
        .....
        rs.Update

        MsgBox ("Record Successfully Updated")

        End Sub
        [/code]

        Comment

        Working...