Multiple criteria for Query from List Box (1 Viewer)

DALeffler

Registered Perpetrator
Local time
Yesterday, 19:20
Joined
Dec 5, 2000
Messages
263
I have a form with a list box showing the user rows he/she can select to generate a report. The user selects multiple rows (or one row, or no row) and those choices are used in another query to base a report on.

In order to do this, the QBE criteria field has to call a function for as many times as I allow the user to make selections in that list box.

So the criteria field in the QBE for the report query looks like this:

List6Items(1)Or List6Items(2)Or List6Items(3)Or(Etc....)

However many times the criteria field makes the function call is the limit to the number of selections a user can make in the forms' list box (List6Items() is the function call - List6 just happens to be the name of the list box; it's not how many selections will be returned).

Now the module where the function code is and determines the value the function returns by looping through the ItemsSelected collection of the list box looks like this:

Option Compare Database
Option Explicit
Private frm As Form, ctl As Control
Private varItm As Variant
Private Count As Integer
-------------------------
Function List6Items(ByVal StringIDtoReturn As Integer)
'frm is the open form
Set frm = Forms![Batt Report Dialog Form]
'ctl is listbox6 on open form
Set ctl = frm!List6

If StringIDtoReturn > ctl.ItemsSelected.Count Then
List6Items = 0
GoTo Done
End If

Count = 1

'set the return value of this function to
'the bound column for each selection made by
'the user in the list box on the open form
'by looping through the collection
'"ItemsSelected", stopping the List6Items
'assignment when the loop iteration equals
'the value passed by the calling procedure...

For Each varItm In ctl.ItemsSelected
List6Items = ctl.ItemData(varItm)
If Count = StringIDtoReturn Then
Exit For
End If
Count = Count + 1
Next varItm

Done:

Set frm = Nothing
Set ctl = Nothing

End Function
--------------------

This works.

But isn't there an easier way of assigning the multiple selections a user made in a list box so's a query can "parse"?

Comments appreciated.

Doug.
 

Jack Cowley

Registered User.
Local time
Today, 02:20
Joined
Aug 7, 2000
Messages
2,639
I have sent a demo to your email address. I hope this is what you are trying to do.
 

DALeffler

Registered Perpetrator
Local time
Yesterday, 19:20
Joined
Dec 5, 2000
Messages
263
Excellent!!!

Exactly what I needed. Much better than the bull in the china shop approach I was trying to do above.

Many Thanks!

Doug.
 

mboe

Registered User.
Local time
Today, 02:20
Joined
Dec 27, 2000
Messages
51
I would be interested in seeing that demo as well. Would either of you be willing to email it to me?
 

DALeffler

Registered Perpetrator
Local time
Yesterday, 19:20
Joined
Dec 5, 2000
Messages
263
Jack C. was kind enough to permit the attachment below - hope you get as much out of it as I did!

Doug.
 

Attachments

  • multicrit.zip
    20.8 KB · Views: 1,673

John liem

Registered User.
Local time
Today, 03:20
Joined
Jul 15, 2002
Messages
112
multicrit.zip sample

DALeffler said:
Jack C. was kind enough to permit the attachment below - hope you get as much out of it as I did!

Doug.

Hi Doug,
Do you have any ideas how I can deselect the highlighted selection after the result button is pressed using a command/statement in Access?
Thanks in advance, John
 

Users who are viewing this thread

Top Bottom