473,403 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

How to Use a Global Variable in a Report's Format Header Event

124 100+
I have a form that contains parameters for a report. After the user clicks Preview I have code that set's the Where clause for the report's record source. Once the report opens I close the parameter form. However, the user enters values on the parameter form that I want to display on the report (StartDate and EndDate, specifically). But because I close the parameter form (otherwise it'd be in the way of the report) I lose those values and they don't render on the report. So I thought I could store them in a global variable that I can then call in the report's header format event. This is what I have:

Parameter Form:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Public gstrStartDate As String
  3. Public gstrEndDate As String
  4. Option Explicit
  5.  
  6. Private Sub cmdPreviewReport_Click()
  7.  
  8.         gstrStartDate = Me.txtStartDate
  9.         gstrEndDate = Me.txtEndDate
  10.  
  11. ...more code...
  12.  
  13. DoCmd.OpenReport "r_FamStmt", acViewPreview, WhereCondition:=strWhere
  14. DoCmd.Close acForm, "f_ParamFamStmt"
  15.  
  16. End Sub
  17.  
My report's format header event:
Expand|Select|Wrap|Line Numbers
  1. Private Sub FamilyIdGroupHeader_Format(Cancel As Integer, FormatCount As Integer)
  2.  
  3. Me.txtReportingPeriod = "Reporting Period: " & gstrStartDate & " to " & gstrEndDate
  4.  
  5. End Sub
  6.  
The issue is that when I debug my code, it doesn't recognize the global variables gstrStartDate and gstrEndDate in my report's header format code above. Error is "Variable not defined". What I don't understand is that I did define it as global variable in my cmdPreviewReport sub at the top so why isn't it recognizing it?
May 4 '11 #1

✓ answered by dsatino

Yes, but you defined it within the forms module. Put the global variable declartion in your own module and you should be fine.

1 2600
dsatino
393 256MB
Yes, but you defined it within the forms module. Put the global variable declartion in your own module and you should be fine.
May 5 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Dan Elliott | last post by:
Hello, Converting from a working C program to C++, I run into the following error: I have a header: (header.h) namespace shared{ ... struct X{ ...
3
by: Eric Lilja | last post by:
Hello, I have a few global variables in my program. One of them holds the name of the application and it's defined in a header file globals.hpp (and the point of definition also happen to be the...
9
by: rosethorn | last post by:
I'm modifying a pre-existing programme with a defined project structure. I need to add a global variable that is visible in both an implementation file in a library, and visible inside the main of...
2
by: Lu | last post by:
Hello, I am wondering how to protect a global variable in a header file from external access. So I googled and found: "The keyword 'static' has two different uses, depending on whether it is...
5
by: luc wastiaux | last post by:
Hello, I need to share a global variable between functions, and for clarity reasons, my code is split in different .c files that each compile into a ..o (object) which in turn are compiled...
1
by: ravinder thakur | last post by:
hi all experts, i am porting a project from c to the c++ framework. during the porting i have encounterd a where i have a static and a global variable with the same name. now what rules c...
9
by: ruca | last post by:
How can I declare a global variable in my .js file, that I can preserve her value each time I need to call any function of .JS file in my ASP.NET application? Example: var aux=null; function...
2
by: mars | last post by:
In my application, global variable A, during its construction, depends on another global variable, say B. However, variable B may have not been initialized by then. How can I make sure that...
6
by: kevinold | last post by:
Hello everyone, I'm using the Prototype JS library, but think my problem might be just be with how I'm initializing and trying to set my javascript variables. Just a note, I have to pass my...
112
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.