I'm doing a project using VB 6. I'm using DAO, everything works except when I want to update a certain fields it only updates the first entry, not the one that I intend to. After I make a query to see the particular row in the database I put the data in a form so that I can edit it. Then I used this code to update it. The problem is if the row that I want to update is not the first row, it's not updated. The first entry is the one that is un-intinionally updated.
What should I do. Please help.
Private Sub cmdupdate_Click()
Set rst = New ADODB.Recordset
rst.Source = "CLIENT"
rst.CursorType = adOpenStatic
rst.LockType = adLockPessimistic
rst.ActiveConnection = _
"Provider=Microsoft.JET.OLEDB.4.0; " & _
"Data Source= " & App.Path & "\NA.MDB"
rst.Open Options:=adCmdTable
rst(0) = txtCName.Text
rst(1) = txtCAddress.Text
rst(2) = txtCPhone.Text
rst(3) = txtCFax.Text
rst(4) = txtCPostCode.Text
rst(5) = txtCNumber.Text
rst.Update
rst.Close
Set rst = Nothing
Dim answer As Integer
answer = MsgBox("Client details have been updated! " & (Chr(13)) & _
"Do you want to make another change?", _
vbYesNo + vbInformation + vbMsgBoxSetForeground, "Confirmed"
End Sub
What should I do. Please help.
Private Sub cmdupdate_Click()
Set rst = New ADODB.Recordset
rst.Source = "CLIENT"
rst.CursorType = adOpenStatic
rst.LockType = adLockPessimistic
rst.ActiveConnection = _
"Provider=Microsoft.JET.OLEDB.4.0; " & _
"Data Source= " & App.Path & "\NA.MDB"
rst.Open Options:=adCmdTable
rst(0) = txtCName.Text
rst(1) = txtCAddress.Text
rst(2) = txtCPhone.Text
rst(3) = txtCFax.Text
rst(4) = txtCPostCode.Text
rst(5) = txtCNumber.Text
rst.Update
rst.Close
Set rst = Nothing
Dim answer As Integer
answer = MsgBox("Client details have been updated! " & (Chr(13)) & _
"Do you want to make another change?", _
vbYesNo + vbInformation + vbMsgBoxSetForeground, "Confirmed"
End Sub