Deleting record problem (1 Viewer)

Prysson

Registered User.
Local time
Today, 20:24
Joined
Sep 23, 2002
Messages
45
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.
 

Travis

Registered User.
Local time
Today, 12:24
Joined
Dec 17, 1999
Messages
1,332
Those commands are to delete the current record not records from other tables.

Use the CurrentDB.Execute (See Execute Method in the Help File) with a Delete query SQL string that limits the record from the other table.
 

Users who are viewing this thread

Top Bottom