Solved Need Correct Where Condition

Eljefegeneo

Still trying to learn
Local time
Today, 01:34
Joined
Jan 10, 2011
Messages
899
I have the following code that opens the report correctly:
Code:
Daily Followup:  DoCmd.OpenReport "rptSalesContactsOpen", acViewReport, , WhereCondition:="[FollowUpDate] = Date()"
Weekly Followup: DoCmd.OpenReport "rptSalesContactsOpen", acViewReport, , WhereCondition:="DatePart('ww',[FollowUpDate]) =  DatePart('ww',Date()) "
Mothly Followup: DoCmd.OpenReport "rptSalesContactsOpen", acViewReport, , WhereCondition:="DatePart('m',[FollowUpDate]) =  DatePart('m',Date()) "

But when I try to set the filter for plus or minus two weeks:
Code:
DoCmd.OpenReport "rptSalesContactsOpen", acViewReport, , WhereCondition:="[FollowUpDate] = Between DatePart('ww',-2,Date())And DatePart('ww',2,Date())"
Or
Code:
DoCmd.OpenReport "rptSalesContactsOpen", acViewReport, , WhereCondition:="[FollowUpDate] = Between [FollowUpDate]('ww',-2,Date())And [FollowUpDate]('ww',2,Date())"
I keep getting a syntax error missing operator.
I don't know which code (or neither one) to use that is missing the "operator".
 
Did that and the error is Runtime error 307 Between Operator Without And
 
Perhaps you should be using DateAdd() rather than DatePart(). Something like:
WhereCondition:="[FollowUpDate] = Between DateAdd("ww",-2,[FollowUpDate] ) AND DateAdd("ww",2,[FollowUpDate] )
 
Same error message. Syntax error missing operator.

I did a work around by putting two hidden text boxes on the form from which the report is run.

Minus2Weeks with it =DateAdd('ww',-2,Date())
Plus2Weeks with it =DateAdd('ww',2,Date())
and used the code
Code:
DoCmd.OpenReport "rptSalesContactsOpen", acViewReport, , WhereCondition:="[FollowUpDate] Between Forms!frmMainMenu!Minus2Weeks And Forms!frmMainMenu!Plus2Weeks"
and the report runs as it should.

so I tried:
Code:
DoCmd.OpenReport "rptSalesContactsOpen", acViewReport, , WhereCondition:="[FollowUpDate] Between DateAdd('ww',-2,[FollowUpDate]) AND DateAdd('ww',2,[FollowUpDate])"
And Volia!
Thanks for the suggestions. Much appreciated.
 
Having read this more carefully, I agree.
If Bob's answer doesn't work, try this
Code:
DoCmd.OpenReport "rptSalesContactsOpen", acViewReport, , WhereCondition:="FollowUpDate >= DateAdd("ww",-2,Date) And FollowUpDate <= DateAdd("ww",2,Date)"
 
think you have a typo

so I tried:
Code:Copy to clipboard
DoCmd.OpenReport "rptSalesContactsOpen", acViewReport, , WhereCondition:="[FollowUpDate] Between DateAdd('ww',-2,[FollowUpDate]) AND DateAdd('ww',2,[FollowUpDate])"
And Volia!

followupdate will always be between plus or minus two weeks of itself;)
 

Users who are viewing this thread

Back
Top Bottom