Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 Listboxes on a Form as filter for a Report ?

Status
Not open for further replies.

PcView

Technical User
Aug 13, 2002
14
0
0
BE
Hi. I am new to VB(A) but willing to learn fast (and to make time for it,...) so here is my "very little" problem. I have made a Form in Access2000 and created 2 listboxes on it (both multiselect). The result of those selections should act like an SQL-statement or query
to be used on a Report. I made a Botton on the Form to trigger the Report. This is where VBA or VB comes in and that's why I am new on this forum,... .
The listboxes are filled with the domains of the tables Areas (Stock A - Stock B - Stock Central - All Stocks) and Types (Workstation - Keyboard - Screen - Printer - ....).

The goal is to select for example Screens and Keyboards from Stock A and Stock B and put them in a Report I already created before (so I have a clean output from the inventory). The problem at the moment is that I can't find the right way to "read" the selection in the boxes
and use them as the Query or SQL-statement for the Report.

Please don't solve the problem completly, all hints in the good direction that would help me solve the problem are more than welcome (and I learn the most out of it).

Thanks.
 
Try iterating through all the items in the listbox looking for those items that are selected. When you find them build a string of the results which can be concatenated into the SQL string.
----------------------
scking@arinc.com
Life is filled with lessons.
We are responsible for the
results of the quizzes.
-----------------------
 
Check out this post thread181-324343 It will give you an idea of how to do it.
 
Thanks for the information, it helped a lot. Everything works smootly.

Still a few remarks :

'Check if input in listbox Areas
Dim a As Integer
Dim NoneSelected As Boolean
NoneSelected = True
For a = 0 To Forms!reportMenuForm!ListAreas.ListCount - 1
If Forms!reportMenuForm!ListAreas.Selected(a) Then
NoneSelected = False
End If
Next a
If NoneSelected = True Then
MsgBox "Please Select 1 or more Areas", vbExclamation, "No Areas selected in list box"
Forms!reportMenuForm!ListAreas.SetFocus
End If

I used this code to check the input of the checkbox, and it does,..., the program continues with the next statement. What I mean is I want the program to stop until the user selects at least 1 item in the listbox.

All tips and tricks welcome. I'll keep searching and reading this great resource for a newbie addict like myself! ;-)

Greetz


 
Ok

Nevermind this post, missed the "Exit Sub" on my way to the fridge I supose,... .

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top