List box loop where clause

10kz

Registered User.
Local time
Today, 10:06
Joined
Jan 9, 2017
Messages
21
I have a list box (ReportList) with 5 options

Y1 Report
Y10 Report
Y15 Report
Y20 Report
Y25 Report

I also have a button that when triggered opens any of the selected reports along with a where condition:

DoCmd.Open Report Me!ReportList, 2, WhereCondition:="[Page] like '*" & Me.cboPageNumber & "*' and [Category] like '*" & Me.cboCategory & "*'", WindowMode:=acWindowNormal​


The reports have different where conditions. For example Y10 Report will have a page condition but not a category condition.

I would like to have a If loop that determines if Y1 selected then the where condition for Y1 is inputted into the DoCmd.

-------------------------

I've come up with the following, any feedback would be appreciated:

Dim y1 as String
Dim y10 as String
Dim y15 as String
Dim y20 as String
Dim y25 as String
Dim strCriteria as String​

If Me!ReportList = Y1 Report then
Y1 = "[Setting] like '*" & Me.cboSetting & "*' and [Category] like '*" & Me.cboCategory & "*'"
Else 0

If Me!ReportList = Y10 Report then
Y10 = "[Setting] like '*" & Me.cboSetting & "*' and [Category] like '*" & Me.cboCategory & "*'"
Else 0

If Me!ReportList = Y15 Report then
y15 = "[Author] like '*" & Me.cboAuthor & "*' and [Category] like '*" & Me.cboCategory & "*'"
Else 0

If Me!ReportList = Y20 Report then
y20 = "[Volume] like '*" & Me.cboVolume & "*' and [Category] like '*" & Me.cboCategory & "*'"
Else 0

If Me!ReportList = Y25 Report then
y25 = "[Country] like '*" & Me.cboCountry & "*' and [Category] like '*" & Me.cboCategory & "*'"
Else 0

strCriteria = >0

DoCmd.Open Report Me!ReportList, 2, WhereCondition:=strCriteria, WindowMode:=acWindowNormal
 
Use CASE statement.

Code:
Select case me.lstReport
  Case "y10"
        SWhere=....
  Case "y20"
       SWhere= ....
End select

Docmd.openReport lstReport,acPreview,,sWhere
 
Code:
Select Case Me!ReportList
  Case "Y1 Report"
     strCriteria = "[Setting] like '*" & Me.cboSetting & "*' and [Category] like '*" & Me.cboCategory & "*'"
  case "Y10 Report'
          strCriteria =  "[Setting] like '*" & Me.cboSetting & "*' and [Category] like '*" & Me.cboCategory & "*'"
  case ...

end select
 
Thank you very much, works perfectly now :)
 

Users who are viewing this thread

Back
Top Bottom