Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to update fields in database using DAO

Status
Not open for further replies.

JIL143

MIS
Feb 6, 2002
2
AU
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
 
Your code is opening an entire table so it will by default update the first record. Try opening the recordset using an SQL statement to just retrieve the record you need:

sSQL = "SELECT * FROM Client WHERE Client.Name = '" & txtName & "'"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top