Go Back   Access World Forums > Apps and Windows > Visual Basic

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 11-24-2012, 06:09 PM   #1
JRPMD
Newly Registered User
 
Join Date: Nov 2012
Posts: 50
Thanks: 29
Thanked 0 Times in 0 Posts
JRPMD is on a distinguished road
Open report with three conditions

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.

JRPMD is offline   Reply With Quote
Old 11-24-2012, 06:21 PM   #2
Alansidman
AWF VIP
 
Alansidman's Avatar
 
Join Date: Jul 2008
Location: Lake County, IL
Posts: 1,493
Thanks: 40
Thanked 244 Times in 243 Posts
Alansidman will become famous soon enough
Send a message via Skype™ to Alansidman
Re: Open report with three conditions

In your criteria, you will need AND for all three conditions to exist.
__________________
Alan


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Win 7 Office XP, 2007, 2010
Alansidman is offline   Reply With Quote
Old 11-25-2012, 05:51 AM   #3
nanscombe
Newly Registered User
 
nanscombe's Avatar
 
Join Date: Nov 2011
Location: Kent, UK.
Posts: 1,082
Thanks: 0
Thanked 256 Times in 249 Posts
nanscombe will become famous soon enough
Re: Open report with three conditions

Quote:
Originally Posted by JRPMD View Post
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

__________________
Nigel
Ex Tactical Systems developer
nanscombe is offline   Reply With Quote
Old 11-25-2012, 06:46 PM   #4
JRPMD
Newly Registered User
 
Join Date: Nov 2012
Posts: 50
Thanks: 29
Thanked 0 Times in 0 Posts
JRPMD is on a distinguished road
Re: Open report with three conditions

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

JRPMD is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Report using 2 conditions in WHERE Lewinmat Reports 6 08-19-2011 12:49 PM
Open form filtered with multipl conditions tt1611 Modules & VBA 8 10-17-2010 10:25 PM
Open form on All conditions met NigelShaw General 8 02-11-2008 02:34 PM
Conditions on a Report reenie Reports 2 07-25-2005 05:21 AM
Open a form depending on conditions Chunk Forms 3 02-22-2005 11:13 PM




All times are GMT -8. The time now is 05:01 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World