DAO Edit Method Problem

10-18-2004, 12:51 PM

I have created a VB 6.0 application that uses an Access database. My application allows you to add, edit, delete, find, and view all records, i'm using DAO code. I have everything working correctly except for the edit option. The way it's set up, you simply type in a name to find, it finds the record and displays the related fields in textboxes on a form. Then the user can make changes to the record and hit the save button. It updates the right record correctly, the problem is it also deletes the last record in the recordset and leaves the orignal unedited record in there. :confused: I'm really not sure what's wrong, here's the code that finds and populates the textboxes:

Set EmpRS = EmpDB.OpenRecordset("select * from EmpInfo where [FirstName] = '" & txtfname30.Text & "' AND [LastName] ='" & txtlname3.Text & "' ")

If EmpRS.RecordCount > 0 Then
frmEditEmpInfo.txtfname2.Text = EmpRS.Fields("FirstName").Value
frmEditEmpInfo.txtlname2.Text = EmpRS.Fields("LastName").Value
frmEditEmpInfo.txtphone2.Text = EmpRS.Fields("PhoneNumber").Value
frmEditEmpInfo.txtaddress2.Text = EmpRS.Fields("Address").Value
frmEditEmpInfo.txtcity2.Text = EmpRS.Fields("City").Value
frmEditEmpInfo.txtstate2.Text = EmpRS.Fields("State").Value
frmEditEmpInfo.txtzip2.Text = EmpRS.Fields("ZipCode").Value
frmEditEmpInfo.txtssn2.Text = EmpRS.Fields("SSN").Value
frmEditEmpInfo.txtdh2.Text = EmpRS.Fields("DateHired").Value
frmEditEmpInfo.txtposition2.Text = EmpRS.Fields("Position").Value

Else: MsgBox "Record not found!", vbExclamation, "No Matches"
End If

End Sub

Once they make changes, here's the code in the save button:

Set EmpRS = EmpDB.OpenRecordset("EmpInfo")


EmpRS.Fields("FirstName") = txtfname2.Text
EmpRS.Fields("LastName") = txtlname2.Text
EmpRS.Fields("PhoneNumber") = txtphone2.Text
EmpRS.Fields("Address") = txtaddress2.Text
EmpRS.Fields("City") = txtcity2.Text
EmpRS.Fields("State") = txtstate2.Text
EmpRS.Fields("ZipCode") = txtzip2.Text
EmpRS.Fields("DateHired") = txtdh2.Text
EmpRS.Fields("Position") = txtposition2.Text
EmpRS.Fields("SSN") = txtssn2.Text



Select Case MsgBox("Do you want to edit another employee?", 4, "Your Changes Have Been Saved")

Case vbYes
Unload frmEditEmpInfo

Set colbind = Nothing
frmFindEmp2Edit.txtfname30 = ""
frmFindEmp2Edit.txtlname3 = ""

Case vbNo
Unload frmEditEmpInfo
Unload frmFindEmp2Edit

End Select

End Sub

I'd really appreciate any suggestions and help...Thanks

10-18-2004, 01:35 PM
When you are saving you are just opening up a full-table recordset. You need to put a condition when opening it to get the correct record, just like you do on your populate routine.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum