ListBox value when nothing selected

  • Thread starter Thread starter jpalmerx
  • Start date Start date
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
 
And then I found the answer somewhere else:

If listindex=-1 Then ...
 
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
 
Ok thanks a lot. I'll use your way instead. Do you mind if I ask why
it's better?

-Josh
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Access Cannot select items in listbox 1
ListBox value when nothing selected 1
Requery listbox 1
Listbox Selection 2
Listbox beforeupdate 2
Deselecting items in a listbox 2
Listbox query 3
Selecting Listbox items in code 2

Back
Top