Delete item from Listbox

jekirksey

Registered User.
Local time
Today, 16:17
Joined
Feb 11, 2001
Messages
27
This is driving me crazy. I have a listbox that is generated from the selection in a combo box on the same form (the listbox data is determined by the combo box value and After_update of the combo box refreshes the listbox. Here's the issue. If you highlight a record in the listbox and then change the combo box to a value that has no records in the listbox and highlight the "empty" value in the listbox and hit the delete button (code below) it deletes the record previously highlighted! Any ideas? I'm checking for null values which I would assume would be the empty listbox, but it's not working.

'Check for null value
If IsNull(Me!lstNotes) Then
MsgBox "There is no Note highlighted!"
Exit Sub
End If

'Delete the highlighted Note
DoCmd.RunSQL "DELETE * from tblNotes Where NoteID = " & Me.lstNotes & ";"

'Refresh the list
lstNotes.Requery
 
Use this code in the After Update event of the Combo box to set the Listbox value to null...

If IsNull(Me.ComboBoxName) Then
Me.lstNotes.Requery
Me.lstNotes = Null
End If
Me.lstNotes.Requery

Or you could change your current code to this:

If IsNull(Me.ComboBoxName) Then
Msgbox...
Exit Sub
End if


hth,
Jack
 
You could try

If lstNotes.listcount > 1 then
' Delete the item selected
...
End if
 

Users who are viewing this thread

Back
Top Bottom