Edit a row

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sammentor
    New Member
    • Jan 2007
    • 7

    Edit a row

    I have problem editing a particular row on my table using Update and Set SQL command, any time I click the cmdSave, it updates the first record even if am trying to update the first row. I used the following code:

    Private Sub cmdSave_Click()
    On Error GoTo WhyErrEditSt

    Dim sSQL As String
    Dim StrValue As String

    StrValue = frmAddSt!txtFna me.Text

    Set con = New ADODB.Connectio n
    Set cmd = New ADODB.Command


    sSQL = "update tblStudent Set Firstname='" & txtFname1.Text & vbNullString & "', Surname='" & txtLname1.Text & vbNullString & "' Where Firstname='" & frmAddSt!txtFna me.Text & vbNullString & "'"

    'Open the Dbase connection
    With con
    .Provider = "Microsoft.jet. oledb.4.0"
    .CursorLocation = adUseClient
    .Open "c:\MyProject\S choolbeta.mdb"
    End With
    Debug.Print StrValue
    With cmd
    .ActiveConnecti on = con
    .CommandType = adCmdText
    .CommandText = sSQL
    End With

    'Call the execute method
    cmd.Execute

    MsgBox "Record Successfully Updated", vbInformation, strProjectname

    Unload Me
    frmAddSt.Show

    Error_WhyErr:
    Exit Sub

    WhyErrEditSt:
    MsgBox Err.Description , , strProjectname
    Resume Error_WhyErr

    End Sub
    I wil be glad to see any help, thanx
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Originally posted by sammentor
    I have problem editing a particular row on my table using Update and Set SQL command, any time I click the cmdSave, it updates the first record even if am trying to update the first row. I used the following code:

    Private Sub cmdSave_Click()
    On Error GoTo WhyErrEditSt

    Dim sSQL As String
    Dim StrValue As String

    StrValue = frmAddSt!txtFna me.Text

    Set con = New ADODB.Connectio n
    Set cmd = New ADODB.Command


    sSQL = "update tblStudent Set Firstname='" & txtFname1.Text & vbNullString & "', Surname='" & txtLname1.Text & vbNullString & "' Where Firstname='" & frmAddSt!txtFna me.Text & vbNullString & "'"

    'Open the Dbase connection
    With con
    .Provider = "Microsoft.jet. oledb.4.0"
    .CursorLocation = adUseClient
    .Open "c:\MyProject\S choolbeta.mdb"
    End With
    Debug.Print StrValue
    With cmd
    .ActiveConnecti on = con
    .CommandType = adCmdText
    .CommandText = sSQL
    End With

    'Call the execute method
    cmd.Execute

    MsgBox "Record Successfully Updated", vbInformation, strProjectname

    Unload Me
    frmAddSt.Show

    Error_WhyErr:
    Exit Sub

    WhyErrEditSt:
    MsgBox Err.Description , , strProjectname
    Resume Error_WhyErr

    End Sub
    I wil be glad to see any help, thanx
    Hi. If you leave out all of the vbNullString entries it should work fine. I am assuming that cmd and con are global variables declared elsewhere.

    Comment

    • sammentor
      New Member
      • Jan 2007
      • 7

      #3
      Originally posted by willakawill
      Hi. If you leave out all of the vbNullString entries it should work fine. I am assuming that cmd and con are global variables declared elsewhere.

      Thank you, It is working fine now

      Comment

      Working...