Report Header Variable

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello to all,

Is it possible to change Report Headers from a form using a global variable.
I would like to use the same report for A, B, and C clients instead of having
three different reports.

Can a report header be manipulated with a variable passed from a form?
If so, how would I code this?

My form is named "Control", and the report is named "Client Class".
 
If the form is still open, you could put a text box on your report that
reads the value from the form. The Control Source of the text box would be:
=[Forms].[Control].[YourTextboxNameHere]

(BTW, because there are lots of controls on a form, it is possible that you
could run into trouble with a form named "Control".)

In Access 2002 and 2003, you could also handle this programmatically, by
passing the value in the OpenArgs of the OpenReport action, and then reading
the value in the Format event of the section, and assigning the value to an
unbound text box.
 
Sky said:
Is it possible to change Report Headers from a form using a global variable.
I would like to use the same report for A, B, and C clients instead of having
three different reports.

Can a report header be manipulated with a variable passed from a form?
If so, how would I code this?

My form is named "Control", and the report is named "Client Class".


As long as the form is open, you can use some code in the
report header's format event procedure to copy form control
value to a control in the report header section. For
example:

Me.txtCustomer = Forms![Control].txtClientName
 
OK, so I have the code for the textbox in the report, but now how do I
declare and send the string variable with header text to the report from the
form?

Allen Browne said:
If the form is still open, you could put a text box on your report that
reads the value from the form. The Control Source of the text box would be:
=[Forms].[Control].[YourTextboxNameHere]

(BTW, because there are lots of controls on a form, it is possible that you
could run into trouble with a form named "Control".)

In Access 2002 and 2003, you could also handle this programmatically, by
passing the value in the OpenArgs of the OpenReport action, and then reading
the value in the Format event of the section, and assigning the value to an
unbound text box.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Sky Warren said:
Hello to all,

Is it possible to change Report Headers from a form using a global
variable.
I would like to use the same report for A, B, and C clients instead of
having
three different reports.

Can a report header be manipulated with a variable passed from a form?
If so, how would I code this?

My form is named "Control", and the report is named "Client Class".
 
If you use the Control Source expression, you don't need a string variable
or any code.

If you want to do it programmatically with a string variable, you will need
to declare the public variable in the General Declarations section (top) of
a standard module (one created through the Modules tab of the Database
window), e.g.:
Public gstrReportHeaderString As String

Then open the report via a command button that assigns the string variable
first:
If Not IsNull(Me.[YourTextboxNameHere]) Then
gstrReportHeaderString = Me.[YourTextboxNameHere]
End If
DoCmd.OpenReport "Report1", acViewPreview

Then use the Format event of the Report Header(?) section to assign the
value of the string to an unbound text box and clear the value:
If Len(gstrReportHeaderString) > 0 Then
Me.[NameOfYourUnboundTextBoxOnReportHere] = gstrReportHeaderString
gstrReportHeaderString = vbNullString
End If

Again, you could pass the value in OpenArgs instead of the string variable
in A2002/2003.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Sky Warren said:
OK, so I have the code for the textbox in the report, but now how do I
declare and send the string variable with header text to the report from
the
form?

Allen Browne said:
If the form is still open, you could put a text box on your report that
reads the value from the form. The Control Source of the text box would
be:
=[Forms].[Control].[YourTextboxNameHere]

(BTW, because there are lots of controls on a form, it is possible that
you
could run into trouble with a form named "Control".)

In Access 2002 and 2003, you could also handle this programmatically, by
passing the value in the OpenArgs of the OpenReport action, and then
reading
the value in the Format event of the section, and assigning the value to
an
unbound text box.


Sky Warren said:
Hello to all,

Is it possible to change Report Headers from a form using a global
variable.
I would like to use the same report for A, B, and C clients instead of
having
three different reports.

Can a report header be manipulated with a variable passed from a form?
If so, how would I code this?

My form is named "Control", and the report is named "Client Class".
 
Guys,

This is not working for me. The text box on report page just stays blank.
What I'm trying to do is create a custom report page header that will display
a custom message. Here's what I have setup so far:

Declared the public string variable:

Public gstrReportHeaderString As String

Assigned values to string in form named "Control Panel" in module "Class":

Private Sub Class_AfterUpdate()

Select Case Me.Class.Value

Case "A"
gstrReportHeaderString = "Client Class A"

Case "B"
gstrReportHeaderString = "Client Class B"

Case "C"
gstrReportHeaderString = "Client Class C"

End Select

DoCmd.OpenReport "Client Class", acViewPreview

End Sub

Now, in the report I have the unbound text box "txtCustomer" to which I
assigned the value of "gstrReportHeaderString" in the header format section:

Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)
If Len(gstrReportHeaderString) > 0 Then
Me.[txtCustomer] = gstrReportHeaderString
gstrReportHeaderString = vbNullString
End If
End Sub


After all of the above, I get nothing in the report page header. Am I doing
something wrong here?
 
1. Where did you put the declaration (the "Public ..." line)?

2. Do you have "Option Explicit" at the top of all modules? If not, add it.

3. In the ReportHeader_Format() procedure, add the line:
Debug.Print "gstrReportHeaderString = " & gstrReportHeaderString
Then run the report, and open the Immediate Window (Ctrl+G) to see if the
string had a value at that time.

There may be a really simple way to do this though. Does the report's
RecordSource query contain the Class field? If not can you add it to the
query? Once it is in the query, you could just put this in the Control
Source of the txtCustomer text box on your report:
="Client Class " & [Class]

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Sky Warren said:
Guys,

This is not working for me. The text box on report page just stays blank.
What I'm trying to do is create a custom report page header that will
display
a custom message. Here's what I have setup so far:

Declared the public string variable:

Public gstrReportHeaderString As String

Assigned values to string in form named "Control Panel" in module "Class":

Private Sub Class_AfterUpdate()

Select Case Me.Class.Value

Case "A"
gstrReportHeaderString = "Client Class A"

Case "B"
gstrReportHeaderString = "Client Class B"

Case "C"
gstrReportHeaderString = "Client Class C"

End Select

DoCmd.OpenReport "Client Class", acViewPreview

End Sub

Now, in the report I have the unbound text box "txtCustomer" to which I
assigned the value of "gstrReportHeaderString" in the header format
section:

Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)
If Len(gstrReportHeaderString) > 0 Then
Me.[txtCustomer] = gstrReportHeaderString
gstrReportHeaderString = vbNullString
End If
End Sub


After all of the above, I get nothing in the report page header. Am I
doing
something wrong here?

Sky Warren said:
Hello to all,

Is it possible to change Report Headers from a form using a global
variable.
I would like to use the same report for A, B, and C clients instead of
having
three different reports.

Can a report header be manipulated with a variable passed from a form?
If so, how would I code this?

My form is named "Control", and the report is named "Client Class".
 
Hello to all who responded,

I feel very bad about having all of you spend your time trying to help me
solve this. The reason is I found a very simple solution that works perfectly
without passing variables. Here's what I did:

1. In my "Client Class" report's Report Header section I created a unbound
text box named "txtCustomer" and formatted it.

2. In the Report Headers "On Format" section I created the following module
that acts on the value passed by the "Client Class" query. That value is
evaluated in my Select Case and a custom header can now be assigned to the
"txtCustomer" text box:

Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)
Dim Agt As String
Agt = "Agent's "
Select Case Class
Case "A"
Me.txtCustomer = Agt + "Class A Clients"
Case "B"
Me.txtCustomer = Agt + "Class B Clients"
Case "C"
Me.txtCustomer = Agt + "Class C Clients"
Case "Attorney"
Me.txtCustomer = Agt + "Class Attorney Clients"
Case Else
Me.txtCustomer = "No match found in Class field"
End Select
End Sub

I must thank all of you for your input, for without it I would still be
trying to pass variables. This eliminates what would otherwise be several
reports having only a different header.

-Sky
 
Back
Top