Vulpeccula
New member
- Local time
- Today, 12:40
- Joined
- Sep 5, 2020
- Messages
- 23
Hi people,
I have a problem deleting an item from a listbox. I have a project which is a fairly simple Point-of Sale system (screen shot below).
In this system, the server selects from the menu on the left (lstProducts) and that product is added to the list on the right (lstItemsSelected), all pretty straightforward thus far, yes?
Okay, so I need to delete the last item entered but when I hit the "Delete Item" button it deletes all three 'Addleston's Cloudy' items. Aha! you say. Thats because the delete query references the Product_ID (which it does). So here's my question to you guys. How do I do it?
Here is the existing (obvious) code:
Private Sub cmdDelItem_Click()
If IsNull(Me.lstSelectedItems) Then
MsgBox "Please select a record from the list to delete", vbCritical
Else
DoCmd.SetWarnings False
If MsgBox("Are you sure you want to remove '" & Me.lstSelectedItems.Column(2) & "' from the list?", vbYesNo + vbDefaultButton2 + vbCritical, "Warning") = vbYes Then
DoCmd.RunSQL "DELETE * FROM tmpSelectedItems WHERE Product_ID = " & Me.lstSelectedItems.Column(1) & ";"
Me.lstSelectedItems.Requery
End If
DoCmd.SetWarnings True
End If
End Sub
I'm sure I have been here before but a series of strokes have wreaked havoc with my memory (so please excuse any inane drivel). Any help would be very gratefully recieved.
My thanks in advance,
GF
I have a problem deleting an item from a listbox. I have a project which is a fairly simple Point-of Sale system (screen shot below).
In this system, the server selects from the menu on the left (lstProducts) and that product is added to the list on the right (lstItemsSelected), all pretty straightforward thus far, yes?
Okay, so I need to delete the last item entered but when I hit the "Delete Item" button it deletes all three 'Addleston's Cloudy' items. Aha! you say. Thats because the delete query references the Product_ID (which it does). So here's my question to you guys. How do I do it?
Here is the existing (obvious) code:
Private Sub cmdDelItem_Click()
If IsNull(Me.lstSelectedItems) Then
MsgBox "Please select a record from the list to delete", vbCritical
Else
DoCmd.SetWarnings False
If MsgBox("Are you sure you want to remove '" & Me.lstSelectedItems.Column(2) & "' from the list?", vbYesNo + vbDefaultButton2 + vbCritical, "Warning") = vbYes Then
DoCmd.RunSQL "DELETE * FROM tmpSelectedItems WHERE Product_ID = " & Me.lstSelectedItems.Column(1) & ";"
Me.lstSelectedItems.Requery
End If
DoCmd.SetWarnings True
End If
End Sub
I'm sure I have been here before but a series of strokes have wreaked havoc with my memory (so please excuse any inane drivel). Any help would be very gratefully recieved.
My thanks in advance,
GF