W
wheat
I'm trying to delete a record from my table based on the current
selected item in a combo box. The user should be able to make a
selection and press a button labled "delete record" to delete the
record. So far, my delete button just deletes the first record in the
combo box (it will do this each time until there are no remaining
records). I'm assuming the bookmark method will be of help here, but
I haven't had any luck with it. Here's the code for the subroutine
called by the button on click (the combo box is named
"existing_contact":
Private Sub delete_contact_button_Click()
' ----------------------------------------
' delete a record from the 'contacts' table via the combobox
' ----------------------------------------
Dim db As DAO.Database
Dim rs As DAO.Recordset
' use the 'contacts' table of the current database
Set db = CurrentDb()
Set rs = db.OpenRecordset("contacts")
With rs
' check for nulls
existing_contact.SetFocus
If existing_contact.Text = "" Then
MsgBox ("Please select a record to delete")
End
Else
.Delete
.MoveNext
End If
' refresh the combo box listing
existing_contact.Requery
End With
rs.Close
Exit_add_contact_Click:
Exit Sub
Err_add_contact_Click:
MsgBox Err.Description
Resume Exit_add_contact_Click
End Sub
selected item in a combo box. The user should be able to make a
selection and press a button labled "delete record" to delete the
record. So far, my delete button just deletes the first record in the
combo box (it will do this each time until there are no remaining
records). I'm assuming the bookmark method will be of help here, but
I haven't had any luck with it. Here's the code for the subroutine
called by the button on click (the combo box is named
"existing_contact":
Private Sub delete_contact_button_Click()
' ----------------------------------------
' delete a record from the 'contacts' table via the combobox
' ----------------------------------------
Dim db As DAO.Database
Dim rs As DAO.Recordset
' use the 'contacts' table of the current database
Set db = CurrentDb()
Set rs = db.OpenRecordset("contacts")
With rs
' check for nulls
existing_contact.SetFocus
If existing_contact.Text = "" Then
MsgBox ("Please select a record to delete")
End
Else
.Delete
.MoveNext
End If
' refresh the combo box listing
existing_contact.Requery
End With
rs.Close
Exit_add_contact_Click:
Exit Sub
Err_add_contact_Click:
MsgBox Err.Description
Resume Exit_add_contact_Click
End Sub