Require 2 listbox selections

S

shmoussa

I have 2 listboxes on my forms, list1 and list2. When both are
selected and my command button is pressed, a query is run- based on
the two selections. How can I make it so that when I click my command
button, it checks to see that selections were made in list1 and list2-
if no selection was made- I would like a popup that explains which
selection needs to be made, and then proceed on to run my query once
selections are made in both listboxes. Thanks!!
 
J

Jeanette Cunningham

Hi shmoussa
If the list boxes have their multi select property set to None, use
something like this

If Len(Me.listBox1 & vbNullString) >0 Then
If Len(Me.listBox2 & vbNullString) >0 Then
'code here to run the query
Else
'call the msgbox
End If
End If


If the list boxes have multi select turned on, you use ItemsSelected to see
if the user has chosen anything.

If Me.listBox1.ItemsSelected.Count > 0 Then
If Me.listBox2.ItemsSelected.Count > 0 Then
'code here to run the query
Else
'call the msgbox
End If
End If


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 

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

Top