I am having a problem with my delete button deleting the wrong record.
Consider that I have a form called frmEditProducts
In this form is a list box that displays a list of the Products from the tblProducts.
There are 4 buttons...
Add
Delete
Edit
Cancel
My Add button and Edit button both open pop-up forms
The Add pop-up form starts a new record and the Edit pop-up opens with a record selected from the list box of the parent form.
Both of the function work fine.
Now the frmEditProducts has in its On Activate event the following code
Private Sub Form_Activate()
Me!ListProducts.Requery
End Sub
This is pretty straight forward...whenever the form is activated it requerys the list box which serves to refresh the product list in the list box.
Here is the delete button code
Private Sub Command18_Click()
On Error GoTo Err_Command18_Click
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Exit_Command18_Click:
Exit Sub
Err_Command18_Click:
MsgBox Err.Description
Resume Exit_Command18_Click
End Sub
Now for the problem....whenever I try to delete a record it does not delete the record I have selected in the list box. INstead it simply deletes the first record in the associated table. Any suggestions on what I can do to the code to make it delete the correct record.
Consider that I have a form called frmEditProducts
In this form is a list box that displays a list of the Products from the tblProducts.
There are 4 buttons...
Add
Delete
Edit
Cancel
My Add button and Edit button both open pop-up forms
The Add pop-up form starts a new record and the Edit pop-up opens with a record selected from the list box of the parent form.
Both of the function work fine.
Now the frmEditProducts has in its On Activate event the following code
Private Sub Form_Activate()
Me!ListProducts.Requery
End Sub
This is pretty straight forward...whenever the form is activated it requerys the list box which serves to refresh the product list in the list box.
Here is the delete button code
Private Sub Command18_Click()
On Error GoTo Err_Command18_Click
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Exit_Command18_Click:
Exit Sub
Err_Command18_Click:
MsgBox Err.Description
Resume Exit_Command18_Click
End Sub
Now for the problem....whenever I try to delete a record it does not delete the record I have selected in the list box. INstead it simply deletes the first record in the associated table. Any suggestions on what I can do to the code to make it delete the correct record.