Help with queries

Grek

Board Regular
Joined
May 9, 2004
Messages
90
Hello,

I'm working on my first real access project (database can be downloaded here: https://www.sugarsync.com/pf/D296036_87_6433855088 ), trying to build a form with several list boxes that would be used as filters in a query. Results are then displayed in a sub-form.

Questions:

- How can I make the query work with multi selection? I tried to change the propriety “multi select” to “extended”, but my query stopped working :/

- How can I add a “Null” value in each of my list boxes? (so that when nothing is selected my sub form returns all the results). I do not see how to do that since the values in my list boxes come from the values in my table T_NewLaunches.

Many thanks for you help,

Greg
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Check out this thread:
http://www.access-programmers.co.uk/forums/showthread.php?t=216821
and specifically my answer in post #6. It shows how to use a set of listboxes with multi-select. And for multi-select listboxes, they are null even when selections are made. So you can't check for null. You would check the ItemsSelected.Count to see if anything has been selected.

So change this part in my thread response:
Code:
If Me.lstITLead.Selected(0) <> True Then
to this:
Code:
If Me.lstITLead.ItemsSelected > 0 Then
 
Upvote 0
Thanks - will try to understand your code :)
Is there a way to do this without VBA (I'm using access 2010)
Thanks,
 
Upvote 0
Is there a way to do this without VBA (I'm using access 2010)
For multi-select listboxes, not really. Well, you could probably use the new macros in 2010 to do it as I believe you can loop using those. But VBA would be the way that would probably be the easiest for this type of thing.
 
Upvote 0
Hi,
If it can help someone, I used this for multiselect list boxes, and it works great (not my code - don't know the source)
Not sure to understand how it works though

To put in a module:

Function IsSelectedVar( _
strFormName As String, _
strListBoxName As String, _
varValue As Variant) _
As Boolean
'strFormName is the name of the form
'strListBoxName is the name of the listbox
'varValue is the field to check against the listbox
Dim lbo As ListBox
Dim item As Variant
If IsNumeric(varValue) Then
varValue = Trim(Str(varValue))
End If
Set lbo = Forms(strFormName)(strListBoxName)
For Each item In lbo.ItemsSelected
If lbo.ItemData(item) = varValue Then
IsSelectedVar = True
Exit Function
End If
Next
End Function

To put in your query, as a new field: IsSelectedVar("F_MainSearch","lstClients",[Client Name])
You also need to put -1 as criteria (don't know why)
 
Upvote 0

Forum statistics

Threads
1,225,071
Messages
6,182,685
Members
453,132
Latest member
nsnodgrass73

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top