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
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
Comment