open report vba filter

ayh1

Registered User.
Local time
Today, 01:08
Joined
Dec 19, 2014
Messages
29
Hi

I have vba code

PHP:
    DoCmd.OpenReport "MonthlyData2", acPreview, , " YEAR(CourseDate) = '" & Me.txtCourseDateMonth & "' "

this works sucessfuly how can I add the following to the code so it filters month and year?

PHP:
'" MONTH(CourseDate) = '" & Me.txtCourseDateYear & "' "
 
Maybe?
Code:
DoCmd.OpenReport "MonthlyData2", acPreview, , _
                 "YEAR(CourseDate) = '" & Me.txtCourseDateMonth & _
                 "' AND MONTH(CourseDate) = '" & Me.txtCourseDateYear & "'"
 
Maybe?
Code:
DoCmd.OpenReport "MonthlyData2", acPreview, , _
                 "YEAR(CourseDate) = '" & Me.txtCourseDateMonth & "' AND MONTH(CourseDate) = '" & Me.txtCourseDateYear & "'"

i tried that but it does not filter as when i try each filter seperately it brings up all the records
 
its working thanks had year and month mixed up
 
This shoudlnt work (properly and all the time) since year will return an integer...

Code:
DoCmd.OpenReport "MonthlyData2", acPreview, , " YEAR(CourseDate) = " & Me.txtCourseDateMonth & " "

That should work more consistantly. Though your naming convention leaves something to be desired.... though perhaps it is a simple copy/paste problem swapping month/year

The adding of month and year is simple enough:
Code:
DoCmd.OpenReport "MonthlyData2", acPreview, , " YEAR (CourseDate) = " & Me.txtCourseDateMonth & " "   & _
                                          " AND MONTH(CourseDate) = " & Me.txtCourseDateYear & " "

Edit: I see my replying to another thread first, has given you time to get the answer from paul already
 
But namliam, you were spot on the swapping of names. ;)
 

Users who are viewing this thread

Back
Top Bottom