Re: How to open a report based on a multi-select listBox
From: Ken Snell [MVP] (kthsneisllis9_at_ncoomcastt.renaetl)
Date: 01/31/05
- Next message: Dave: "Re: Simple Question on Variable Scope"
- Previous message: Dave: "run time 2110"
- In reply to: Frederick Wilson: "Re: How to open a report based on a multi-select listBox"
- Next in thread: Fred Wilson: "Re: How to open a report based on a multi-select listBox"
- Reply: Fred Wilson: "Re: How to open a report based on a multi-select listBox"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 30 Jan 2005 21:54:51 -0500
I admit that I don't fully "see" your setup in my head, but what you would
"build" as the WHERE clause from your multiselect listbox might look
somethinng like this:
Dim strWhere As String
strWhere = "[Field1]=" & Me.lstGroupsSelect.Column (0) & _
" And [Field2]=" & Me.lstGroupsSelect.Column(1)
DoCmd.OpenReport "ReportName", , , strWhere
If you have multiple values for a single field, then something like this as
you cycle through your listbox's selections:
Dim strWhere_Field1 As String, strWhere_Field2 As String
Dim strWhere As String
Dim lngLoop As Long
strWhere_Field1 = ""
strWhere_Field2 = ""
For lngLoop = 0 To Me.lstGroupsSelect.ListCount - 1
If Me.lstGroupsSelect.Selected(lngLoop) = True Then
strWhere_Field1 = "[Field1]=" & Me.lstGroupsSelect.Column (0) & _
" And "
strWhere_Field2 = "[Field2]=" & Me.lstGroupsSelect.Column (1) & _
" And "
End If
Next lngLoop
If strWhere_Field1 <> "" Then strWhere_Field1 = Left(strWhere_Field1, _
Len(strWhere_Field1) - 5)
If strWhere_Field2 <> "" Then strWhere_Field2 = Left(strWhere_Field2, _
Len(strWhere_Field1) - 5)
strWhere = strWhere_Field1 & " And " & strWhere_Field2
DoCmd.OpenReport "ReportName", , , strWhere
--
Ken Snell
<MS ACCESS MVP>
"Frederick Wilson" <faNOTTHISwilson@comcast.net> wrote in message
news:Jf-dnYcPU5SVDWDcRVn-2A@comcast.com...
> So let me get this right
> with the where clause in the openreport I would do something like
> Field1=something1 or something2, field2=something1 or something2.
>
> I do not have any code because I do not know how to do this. I know what I
> want to do but I can not figure it out.
>
> I have a report setup that gets everything from qrySignUpReport
>
> I have an unbound form frmSignUpReport with txtTitle, txtDate, ckActive,
> lstGroupsSelect.
>
> The user types a name for the sign up in txtTitle
> The user types a date for the sign up in txtDate
> ckActive is a checkbox which will be used to match a checkbox in a
> personnel list. If the person in tblPersonnel is active they have a
> checkbox.
>
> Finally, the list box has two columns. I have my personnel broken down in
> groups such as females, males and further defined as young, middle age,
> seniors SOOOO
>
> you can have Female - young and/or female - middle age and so one.
>
> The idea of the list box is that you can select any of the combinations.
>
> I was thinking that the query would be something like
> field1=lstGroupsSelect.column (0)
> field2=lstGroupsSelect.column (1)
>
> but when you can have a multi select I am not sure how to deal with it.
>
> Thanks,
> Fred
>
>
>
> Ken Snell [MVP] wrote:
>> If you're using ACCESS 2002 or 2003, yes, you can pass the SQL string in
>> the OpenArgs argument of a DoCmd.OpenReport command. Although I'm not
>> sure what you plan to do with the SQL statement then; I suppose you could
>> use it in the report's Open event procedure to filter the report's
>> recordsource.
>>
>> However, if you just want to filter the report when it's opened, use the
>> fourth argument (the WhereCondition argument) of the DoCmd.OpenReport
>> method to pass the filtering string. That filtering string would be a
>> WHERE clause construction without the WHERE word.
>>
- Next message: Dave: "Re: Simple Question on Variable Scope"
- Previous message: Dave: "run time 2110"
- In reply to: Frederick Wilson: "Re: How to open a report based on a multi-select listBox"
- Next in thread: Fred Wilson: "Re: How to open a report based on a multi-select listBox"
- Reply: Fred Wilson: "Re: How to open a report based on a multi-select listBox"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|