Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing Multiple Reports Using a Command Button 4

Status
Not open for further replies.

sera

Technical User
Jun 29, 2000
360
US
Hello,
I have created reports that are based on queries. Before a report can be printed it
needs a parameter. All of the reports use the same parameter to print. I now want to
be able to create a command button that will print all the reports using that parameter. When I print, or preview a report, a message box asks for the parameter.
What I need to do is allow the users to input the parameter only once and somehow pass the parameter to the preceeding message boxes. I hope this makes sense. Any help I can get will be greatly appreciated.
Thank You
Sera
 
Run the report from a form that has a text box containing the parameter that you want used. Have the queries access the parameter using:

forms!formname!textboxname

Then have the button run a Docmd.Openreport statements.
Mike Rohde
rohdem@marshallengines.com
 
Hey Rodhem,
I have been trying what you are saying(obviously not exactly what you are saying or it would be working)... I think the problem is where do I put the
command
forms!formname!textboxname
I hope this makes sense.
Sera
 
Put the
forms!formname!textbox in the criteria section of each of the queries.

Put brackets [] around the names if they contain spaces, i.e.

[forms]![form name]![text box]
Mike Rohde
rohdem@marshallengines.com
 
Do you know what? Well probably not so I'll tell you....I mispelled the name of the form and have spent the last five hours(or so) messing around with this. So what is the lesson I have learned....over and over again....Check the spelling!!! Thank you for your help.
Sera
 
Spelling error causing the problem
Hmmmmmm.....
If I had a nickel.......

It happens to all of us!!
Glad you got it fixed!!
Mike Rohde
rohdem@marshallengines.com
 
Hello,

This post is very helpful. I resolved most of the problems.

I have a little problem on the reports that I designed. I built the "Start Date:" and "End Date:" in each report. I used the following phase in the Control Source Property:

=[forms]![form name]![Startdate] for the Start Date and
=[forms]![form name]![Enddate] for the End Date.

The record sources came from the Queries which I used the same criteria.

When the reports printed, the first page (header) gave me the correct starting and ending dates. However, from the second page and until the end of the report, the date fields displayed "#Name?" (on both start and end dates.)

What did I do wrong? My property set up looks correct because all reports printed the first page correctly. The data are correct (on the first page.) It is just the starting date and ending date heading, from the second page, that give me a problem.

Can you recommend the resolution? Thanks.


 
Don't know why this is happening, but if your report is based directly on your query which already contains your Start and End dates, try using the query fields as your control source instead of referring back to the form.
 
I also am confused by this, but you could try making the text boxes in the header unbound and assigning them using the 'on format' event of the header section of the report.

Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)
Me.startdatetextbox = [forms]![form name]![Startdate]
Me.enddatetextbox = [forms]![form name]![Enddate]

End Sub

I don't know if this will help or not, but it's worth a shot. Mike Rohde
"I don't have a god complex, god has a me complex!"
 
Hello,

What I did was:

1. Built a query with one of the fields, received_date (date), had a following criteria -> Between [Forms]![Frm_Test]![StartDate] And [Forms]![Frm_Test]![EndDate]. The query was based on Totals, with the field name, table name, Total = where and show = skip.

2. Created a blank form called "Frm_Test", with two unbound fields. I formated with the dates. I inserted a command button with the following statement on the "on-Click" Event:

Private Sub Print_Report_Click()
DoCmd.OpenReport "Receivable Report", acViewPreview
DoCmd.OpenReport "Receivable Monthly", acViewPreview
Forms![Frm_Test].SetFocus
DoCmd.Close
End Sub

3. On the "Receivable Report", I do not have a report header. I have a page header. I inserted two additional unbound fields with the date format. I also named the fields ->Startdate and EndDate. Since they are unbounded, the control sources are blank.

4. I put the following code in the "on format" at the Page Header.

Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As Integer)
Me.StartDate = [Forms]![Frm_Test]![StartDate]
Me.EndDate = [Forms]![Frm_Test]![EndDate]
End Sub


5. After open the "Frm_Test" and put in the dates parameters, the preview looks OK. This time, when I went to view the second page, the error message popped up:

Run-Time error '2450':
Can't find the form 'Frm_Test' referred to in a macro expression or visual basic code.

The program asked for a debug. The correct form was in there (or else) I should not see the print preview of the report.

Any suggestions? Thanks.


 
Hello again,

Look like I found the solution regarding the 2450 error.

It appears that the DoCmd.Close on the form was the problem. When I deleted that line, I could print the reports with exact parameters.

Now, my next question is:

How can I close this "Frm_Test" form or put it invisible, so, the users cannot see it? The form was in front of the reports preview.

When the users close the reports, after preview, I would like the "Frm_Test" to be closed as well.

I think, it might be a simple code to close it. Any help? Thanks.

p.S. That page format command did the trick! Thanks.


 
In the properties of the the report, go to the "On Close" line and do an "Event procedure" with this coding

DoCmd.Close acForm, "frmName", acSave

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top