Greetings Gurus
Some advice or help please...
My form has a listbox (list42) which contains names looked up from a table called AllNames. It also has a combobox which contains the possible status of the list42 names.
For e.g. "Bob" on list42 can be selected as "absent", "present" etc.
I am trying to code an event whereby, depending on the status set in the combobox, I can edit the name in AllNames & requery the form.
My code thus far:
Whenever the code executes I get an error "Update or CancelUpdate without AddNew or Edit"
If I remove the "ID" line then the code runs but it updates the wrong name (the first one in the table because it doesn't know which record to change) but I cannot find a way to get it to update the record selected in the listbox.
Thank you in advance.
Some advice or help please...
My form has a listbox (list42) which contains names looked up from a table called AllNames. It also has a combobox which contains the possible status of the list42 names.
For e.g. "Bob" on list42 can be selected as "absent", "present" etc.
I am trying to code an event whereby, depending on the status set in the combobox, I can edit the name in AllNames & requery the form.
My code thus far:
Code:
Private Sub Status_AfterUpdate()
If Me.Status = "Do Not Contact" Then
Dim coName As String
coName = Me.List42.Column(1)
Dim db As Database, tb As DAO.Recordset
Set db = CurrentDb
Set tb = db.OpenRecordset("AllNames", dbOpenDynaset, dbSeeChanges)
tb.FindFirst "ID" = Me.List42.Column(0)
tb.Edit
tb!Status = Me.Status
tb!Name = "XXX " & coName
tb.Update
tb.Close
db.Close
End If
End Sub
Whenever the code executes I get an error "Update or CancelUpdate without AddNew or Edit"
If I remove the "ID" line then the code runs but it updates the wrong name (the first one in the table because it doesn't know which record to change) but I cannot find a way to get it to update the record selected in the listbox.
Thank you in advance.