Hello all,
The noob is back again. I've spent all day trying to figure out how to code an edit button to update a record in a table. I have made progress, but now I am getting some kind of "locking violation". When I tell the query to run despite the locking violation, it doesn't update the record, it just adds the record onto the end. Also, neither the table or the list box I refer to in the code are requerying.
The table I'm working with is: "DMListTbl"
The fields are:
Code
DM
Status
ID (This is an autonumber)
The form I'm working with is: "DMList"
The controls are:
txtCode
txtDM
txtStatus
txtID
I'm not sure if it is relevant, but I have a list box on the form called "SPList", which is pulling data from "DMListTbl" . In the event property of the list box, when a record is double-clicked the data is moved into the controls.
This is the code:
This has been driving me insane, so thank you in advance for any help on this issue!!
Best,
Eric
The noob is back again. I've spent all day trying to figure out how to code an edit button to update a record in a table. I have made progress, but now I am getting some kind of "locking violation". When I tell the query to run despite the locking violation, it doesn't update the record, it just adds the record onto the end. Also, neither the table or the list box I refer to in the code are requerying.
The table I'm working with is: "DMListTbl"
The fields are:
Code
DM
Status
ID (This is an autonumber)
The form I'm working with is: "DMList"
The controls are:
txtCode
txtDM
txtStatus
txtID
I'm not sure if it is relevant, but I have a list box on the form called "SPList", which is pulling data from "DMListTbl" . In the event property of the list box, when a record is double-clicked the data is moved into the controls.
This is the code:
Code:
Public Sub Command28_Click() Dim strSQL As String Dim db As DAO.Database Dim DMListTbl As DAO.Recordset Set db = CurrentDb Set DMListTbl = db.OpenRecordset("DMListTbl") With DMListTbl .Edit DMListTbl!Code = Forms!DMList!txtCode DMListTbl!DM = Forms!DMList!txtDM DMListTbl!Status = Forms!DMList!txtStatus strSQL = "UPDATE DMListTbl SET DMListTbl!Code = Forms!DMList![txtCode], DMListTbl![DM] = Forms!DMList![txtDM] ,DMListTbl![Status] = Forms!DMList![txtStatus]" _ & "WHERE DMListTbl![ID] = Forms!DMList![txtID]" End With If Me.Dirty Then Me.Dirty = False DoCmd.RunSQL (strSQL) Me.Requery Me.SPList.Requery MsgBox ("Updated") End Sub
This has been driving me insane, so thank you in advance for any help on this issue!!
Best,
Eric
Comment