Populating unbound text box on a report

ontopofmalvern

Registered User.
Local time
Today, 11:56
Joined
Mar 24, 2017
Messages
64
Hi when I run this code on an open Form the unbound text box called "txtBox" gets filled with the word "bob"

Code:
Forms!frmMyForm!txtBox = "bob"

but when I run this on an open Report

Code:
Reports!rptMyReprt!txtBox = "bob"

I get the error "Argument not optional" (also VBA editor changes "Reports!" to "reports!" which I think is a clue ..)

I have a nasty workaround for my current problem using TempVars to pass the value to the Report then having an onload event like this

Code:
Me.txtBox = TempVars!strText

There must be a better way which I feel must be dead obvious but I can't find it.
 
Hi. Not in front of a computer now, so I could be wrong, but I think reports can't usually be changed once it's already rendered, not like forms, which are dynamic objects.
 
rather than using tempvars, you can use the openargs parameter for docmd.openreport. AS DBG say, reports are not dynamic once opened. As you have discovered you need to use report events to modify report contents.
 
Many thanks, that makes sense now and is obvious (isn't always once you know?)

Couldn't get openargs to work, I don't think I have the syntax right, if my control is called "txtBox" and report "rptMyReport"
what do I replace "??" with below?

DoCmd.OpenReport "rptMyReport", acViewReport, "", "", acNormal, "??"
 
DoCmd.OpenReport "rptMyReport", acViewReport, "", "", acNormal, "bob"

and in the form open or load event

me.txtBox=openargs
 
When your code is running IN the class module of a form or report, use "Me." to refer to controls in the form/report. Using the external reference - Forms!.... and Reports!.... just adds unnecessary overhead.

Also, keep in mind that Report View does NOT run code in all events so unless you need some particular feature of ReportView such as drill down, always open in PrintPreview for best results.
 
Many thanks for all the helpful tips here. Especially useful is the difference between ReportView and PrintView, never really considered it before.
 
People who like web pages, like ReportView. I don't like the absence of page breaks so I almost never use it.
 

Users who are viewing this thread

Back
Top Bottom