Open a report using a dialogue box (1 Viewer)

LinaRose

Registered User.
Local time
Today, 10:13
Joined
May 21, 2013
Messages
18
Hello,

I am using a form to filter information so that I can open a report. The report displays information pertaining job costs. Each month the company I work for records their labor, costs, and travel in a form with a year to date amount. Right now, I am having a problem opening up a report for one specific job and a specific month. So what I want the dialogue box to do is to pick from a list of jobs then pick from a list of months, click a button that prompts a preview of the report and voila! Can somebody help me? :banghead:because this is how I feel.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:13
Joined
Feb 19, 2002
Messages
42,970
Create a form that contains the unbound combo boxes to choose the criteria. Add a "run" button. In the click event of the run button, use the OpenReport method to open the report, use the Where argument to pass along the selection criteria.
 

LinaRose

Registered User.
Local time
Today, 10:13
Joined
May 21, 2013
Messages
18
Could you be a little more specific about the "where statement"? I'm still pretty new to the VBA and macros.
 

LinaRose

Registered User.
Local time
Today, 10:13
Joined
May 21, 2013
Messages
18
Thank you!

Wouldn't I need to enter a filter name also? I am using a dialogue box to open a report based on a specific job and month. My task is to build a report that displays monthly job costs. I have an unbound combo box for both the job and the month in the dialogue form so how would I tell the Where clause to search for the report based on the selections made in the two combo boxes?

I apologize for all the questions. I'm trying to teach myself and I keep running into brick walls :banghead:
 

MikeLeBen

Still struggling
Local time
Today, 15:13
Joined
Feb 10, 2011
Messages
187
You would use something along the lines of:
Code:
DoCmd.OpenReport "YourReport", acViewPreview, , "[Job] = " & Me.cboJob & " AND [Month] = '" & Me.cboMonth & "'"

Note: the above has not been tested, and variable names need to be adapted to your needs.
 

LinaRose

Registered User.
Local time
Today, 10:13
Joined
May 21, 2013
Messages
18
Well thank you that was very specific, except I think I'm entering it wrong because it's not working. I changed the variables and it's still not working. :(

The error message says there is a syntax error and there are missing operators. I put everything in exactly aligned with the variables I have in place. What could I be doing wrong?
 

MikeLeBen

Still struggling
Local time
Today, 15:13
Joined
Feb 10, 2011
Messages
187
Please note that the where clause in this statement needs to be valid SQL. What comes to my mind is that your combo box has been set-up with month names instead of numbers?

You could try test your query with the query design view, and then make sure the SQL WHERE clause criteria are expressed properly in your OpenReport method.

Posting your code would also be good practice :)
 

Users who are viewing this thread

Top Bottom