Open report with three conditions

JRPMD

Registered User.
Local time
Today, 05:12
Joined
Nov 24, 2012
Messages
52
Hello I'm trying to open a report only if fields age>50 , gender = male , language = french and type this :

If Me.Age >= 50 Then DoCmd.OpenReport " Rpt1", acViewPreview
If Me.Gender = Male Then DoCmd.OpenReport "Rpt1", acViewPreview
If Me.language= french DoCmd.OpenReport "Rpt1" , acViewPreview

The report is open with only one condition , but I need it with three conditions. Should I use AND ?
Thank you very much.
 
In your criteria, you will need AND for all three conditions to exist.
 
Hello I'm trying to open a report only if fields age>50 , gender = male , language = french and type this :

If Me.Age >= 50 Then DoCmd.OpenReport " Rpt1", acViewPreview
If Me.Gender = Male Then DoCmd.OpenReport "Rpt1", acViewPreview
If Me.language= french DoCmd.OpenReport "Rpt1" , acViewPreview

The report is open with only one condition , but I need it with three conditions. Should I use AND ?
Thank you very much.

One way I like to tackle this sort of task is to use multiple logic statements.

Code:
Private Sub openMyReport()
Dim blOpenReport as Boolean

  blOpenReport = TRUE ' Start with the value set to TRUE
  blOpenReport = blOpenReport AND (Me.Age >= 50)
  blOpenReport = blOpenReport AND (Me.Gender = Male)
  blOpenReport = blOpenReport AND (Me.language= french)

' If any of the above statements is FALSE then blOpenReports is also FALSE
' Therefore blOpenReports is only TRUE if ALL of the statements are TRUE

  if blOpenReport = TRUE Then DoCmd.OpenReport "Rpt1" , acViewPreview

End Sub

Or if there are only one or two statements

Code:
Private Sub openMyReport()

  If (Me.Age >= 50) AND (Me.Gender = Male) AND (Me.language= french) = TRUE Then DoCmd.OpenReport "Rpt1" , acViewPreview

End Sub
 
Thank you very much , Alan and Nanscombe. It works!
 

Users who are viewing this thread

Back
Top Bottom