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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing values from a form to a report 1

Status
Not open for further replies.

TerryEA

Technical User
Jun 20, 2004
99
GB
Hi all

Just when you think you've got Access sus'd, something happens to confound you!

I've read from other posts that I can enter, say, start date and end date parameters for a report into controls on an unbound form, and then, for example, show the start date and end date by entering the following into the record source for a text field on the report header:

= "Between " & forms!frmReport.startDate & " and " & forms!frmReport.endDate

Now this works fine, at least on preview, but when I print the report I get the dreaded message of death, "#Name?" in the text field that did succeeded in showing the dates on preview.

Anyone know what's going on?

Terry
 
Try this!

Code:
="Between '" & forms!frmReport.startDate & "' and '" & forms!frmReport.endDate & "'"
 
Hi jkl0

Thanks for your reply.

Your code works just like mine, in preview, but not in print. But just to clarify:

If I use this:

DoCmd.OpenReport ReportName:=strRptName, View:=acPreview, WhereCondition:=strWhere

It works in the preview on the screen but doesn't if I go straight on to print what I've just previewed, using the Printer icon, or File, Print from the the toolbar.

If I use this:

DoCmd.OpenReport ReportName:=strRptName, View:=acNormal, WhereCondition:=strWhere

Of course it doesn't then preview, but prints straight away perfectly. Both your code and mine work like this.

I want the user in this application to be able to preview all the reports before printing. So there's something else I'm missing, to do with previewing before print.

Any further thoughts?

Terry
 
The only other thing that I can think of is to enclose the dates in "#"

Code:
="Between #" & forms!frmReport.startDate & "# and #" & forms!frmReport.endDate & "#"
 
jk10

OK, I'll give that a try when I get home, and let you know later. Many thanks

Terry
 
Hi jk10

Same result I'm afraid. I'll just have a to have two command buttons - one for preview and one for print. Not ideal! What's more interesting is that it only works on the first page if it's a multi-page report. Wish I knew what was going on.

If anyone's got a better way of doing this I'd love to know.

Thanks anyway

Terry
 
jk10

just read another similar post and dhookom (Programmer)had the answer as follows:

"Don't close the form if you need values from it in the report. Just set its visible property to false."

This worked, so thanks to him, and thanks again to your good self.

Terry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top