Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Passing a string to a report label.


Message #1 by "Terrence P. Franklin" <tfrankli@k...> on Fri, 31 Aug 2001 20:44:53
I am learning VBA via Beginning Access 2000 VBA.  I am working through the 

exercises in chpt 7.  I would like to be able to pass the "strWhere" 

string (it contains part of the SQL) to the report that is ultimately 

created.  I would like to put this in the report so that it tells what the 

criteria are for the report creation.  I am new at this type of 

programming.  It is probably easy, I just have not found any examples. I 

would like to put it in the Report label or in a text field.  How?
Message #2 by "Pardee, Roy E" <roy.e.pardee@l...> on Fri, 31 Aug 2001 13:38:58 -0700
It's not as easy as I would like (tho I may also be laboring in ignorance of

the easier way).  Here's the deal as I understand it:



While they are open, Reports are contained in the Reports collection of the

Application object.



Report Labels are contained in the Controls collection of their report.



Labels have Caption properties, which is what controls their content.



So you want a statement like:



Application.Reports("rptMyReport").Controls("lblMyLabel").Caption = strWhere



The catch is that you've got to set the caption property of your label

before it's painted on the screen--you can make all the changes you want to

a label caption after it's painted, but you'll only ever see the original

text.  (I don't know of any way of refreshing a report shown in design

view--maybe somebody else on the list does).



So one way to do this is to first open the report in design view, then set

the label caption, and then open it up in print preview view, e.g.,



With DoCmd

   .Echo EchoOn:=False, StatusBarText:="Formatting report..."

   .OpenReport ReportName:="rptMyReport", View:= acViewDesign

   Application.Reports("rptMyReport").Controls("lblMyLabel").Caption 

strWhere

   .OpenReport ReportName:="rptMyReport", View:= acViewPreview

   .Echo EchoOn:=True

End With



You can also get to the label before the report prints in the report's Open

method.  If you can make strWhere accessible from the Open method of the

report (e.g., if strWhere's defined in a form module, give it Public scope,

or write it to an invisible text box control), you can set the label's

.Caption there.  That's actually a better method for apps you want to deploy

as .mde files, since you can't open a report in design view in an .mde.



HTH,



-Roy



-----Original Message-----

From: Terrence P. Franklin [mailto:tfrankli@k...]

Sent: Friday, August 31, 2001 1:45 PM

To: Access

Subject: [access] Passing a string to a report label.





I am learning VBA via Beginning Access 2000 VBA.  I am working through the 

exercises in chpt 7.  I would like to be able to pass the "strWhere" 

string (it contains part of the SQL) to the report that is ultimately 

created.  I would like to put this in the report so that it tells what the 

criteria are for the report creation.  I am new at this type of 

programming.  It is probably easy, I just have not found any examples. I 

would like to put it in the Report label or in a text field.  How?


  Return to Index