ListBox value when nothing selected

J

jpalmerx

Hi,


I have a form in Access with a listbox containing some choices. Thereis
a "Select" button underneath that runs a macro opening a form thatacts
on the selected value.
What I can't figure out is how to display an error, eg. "Please make a
selection" if nothing is selected and the "Select" button is clicked.

I'm trying an If Then Else statement worked into the button such as:
If listbox value=null, then error message. Else, run macro.
This hasnt worked, but it could just be that I don't know how to do it
properly.
The listbox is apparently unbound. (It's choices are derived from the
selection of another listbox)

Thanks in advance,
Josh
 
D

Dirk Goldgar

And then I found the answer somewhere else:

If listindex=-1 Then ...

Assuming that the list box is unbound, checking for a Null value is
better. But you probably did it the wrong way when you tried it; I
guess you wrote:

If YourListbox = Null Then

but nothing is ever equal to Null, not even Null. You should write

If IsNull(YourListbox) Then
 
J

jpalmerx

Ok thanks a lot. I'll use your way instead. Do you mind if I ask why
it's better?

-Josh
 
D

Dirk Goldgar

Ok thanks a lot. I'll use your way instead. Do you mind if I ask why
it's better?

Mainly because it makes sense that when you're interested in the value
of a control, you interrogate the control's Value property. But aside
from that, and potentially significant, is the fact that a list box or
combo box can have a non-Null value and still have its ListIndex
property equal to -1. ListIndex = -1 just means that the value of the
control is not in the list; it doesn't necessarily mean that the control
has no value.
 
Top