Check if item is selected on list

yippie_ky_yay

Registered User.
Local time
Today, 16:56
Joined
Jul 30, 2002
Messages
338
Hello all,

I have a bit of a confusing problem! One of my subforms has a listbox displaying n record(s). I require the user to select a record on the listbox by single or double cliking and then, if they want to delete it, they just hit the Delete command button I created.

This works great unless they forget to select a record first before trying to delete it. I tried putting in a check like this:

If IsNull(lstboxGroups) Then
MsgBox "Please select an item from the listbox to delete."
Exit Sub
Else
...go on and delete the record

Now the weird part - this seemed to work for awhile, then the msgbox started popping up even when I did select a record. To solve this I added "Not" infront of the IsNull test and that seemed to work for awhile - until it happened again! It keeps flipping between the two it seems. Does anyone know why the test criteria would keep reversing?

(I should mention that I did solve this by not enabling the Delete button until the user selects an item - I'm just curious about the test behaviour)

Thanks,

-Sean
 
Last edited:
Is the bound column for the listbox a numeric field or text? It could be that the value of the field is sometimes null, but sometimes it might be an empty string i.e., "".

So you could add another check to handle both possibilities:

If isnull(me.listbox) or me.listbox.value = "" then
msgbox "Please select a record"
exit sub
else
do something else
end if
 
Last edited:
You were right on the money Elana!

My bound column was set to the wrong one (to a column that may occasionally be blank).

With it being Friday today I won't beat myself up too much for it:-)

Thanks alot and have a great weekend!

-Sean
 

Users who are viewing this thread

Back
Top Bottom