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

Using code to change text values in a report header

Status
Not open for further replies.

Mordacia

Technical User
Jan 24, 2002
13
US
I have created a search form for users to select criteria for reports. There are 8 different criteria that can be selected - the user can select any combination of criteria and then select a command button which filters the data.

I would like to just create one report and use code to change the report header depending on the criteria selected. For example, if a user selects to view "Paid" items for "Staples" paid between "03/01/2002" and "03/30/2002," the report header will read "Staples Items Paid Between 3/01/2002 and 3/30/2002."

I have code written right now that references the textbox for the header(Text46) as follows:

Dim rpt As Report
DoCmd.OpenReport RptLink, acViewPreview
For Each rpt In Reports
rpt.Controls.Item("Text46").SetFocus
rpt.Controls.Item("Text46").Text = "Mordacia"
Next rpt

This seems to work except that it doesn't recognize "Mordacia" as text - it recognizes it as a parameter and a parameter box appears. How can I get it to recognize "Mordacia" as text? Eventually, I will be setting up a strtitle(string) that recognizes the criteria in the forms and uses it for the header, but first I need to make it recognize the values in the forms as text.

Any suggestions or help would be appreciated.
 
Thanks for your advice - the code you gave me worked. I actually want to have the text "Mordacia" appearing on all pages of the report, so I put Text46 in the Page header instead of report header. For some reason, though, the text appears on all pages except for the first page. Do you have any idea why and how I can make it appear on the first page of the report, as well?
 
A page header appears on every page of the report, below the report header (if there is one) on the first page, and at the physical top of every subsequent page. I can't see why it's not appearing on the first page. Are you sure it's not there?

Ex-JimAtTheFAA
78.5% of all statistics are made up on the spot.
Another free Access forum:
 
Yes, the page header would normally appear on every page including the first page, but for some reason, it does not appear in this case. I found out that after I open the report from the form, if I go into design mode and then back to print preview, the text does in fact appear on the first page. It just does not appear on the first page if it is opened directly from the form. This might have something to do with where it is placed in the code - I currently open the report with a DoCmd and then try to set the text46.value in the open event of the form. Should I set the value in a different place?
 
I currently open the report with a DoCmd and then try to set the text46.value in the open event of the form.

1) is Text46 an object on your REPORT or your FORM?

2) You should set it on REPORT_Activate or REPORT_Open or something, I'd think, not the Form Open..

3) Do this - set a thick border around the text box - that way, we'll see if any VALUE has been set into it, or that it's 'printing' but there's no value for it...

IF, and I repeat, IF this report is opened ONLY from this form, you could just refer to the form value directly in the control source property of the text box:

"=Forms!MyOtherForm!MyTextBox" or something equally descriptive.

As a general rule, you can refer to ANY object in any OPEN object from any other OPEN object. For example, having a title in a report be set to two or more variables on a form. The form can even be HIDDEN, as long as it's OPEN. Perfectly legal....




Ex-JimAtTheFAA
78.5% of all statistics are made up on the spot.
Another free Access forum:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top