Report will not access public variables from form

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

Guest

On a form, I have declared public variables for current (old) values in the
controls and also edited (new) values. There are manipulated through code
behind the form correctly.
After a save record on the form, I send a report by email that tells the
client that revisions to the record on the form have changed.
In OnOpen event on the report I have some if statements to print the old and
new values on the report if they differ, e.g.(or i.e.)
If gstrPARTNoOld <> gstrPARTNoNew Then
Me.txtPartNoNew = gstrPARTNoNew
Me.txtPartNoOld = gstrPARTNoOld
End If
I have stepped through the code and the values for the public variables are
not shuffling from the form over to the report. The form is still open
although it has lost focus as the report is in preview mode. What am I
forgetting to do?
 
When you declare global variable in your form you can use them every where in
that form but not outside the form, if you want to use the variable every
where then declare them in a module and not in your form.
and dont forget to remove them from your form.
 
Sorry for being too brief.
The public variables are in the declarations section of the form's module so
they should be available outside the form.

Also, using Access 2000
 
Lee said:
Sorry for being too brief.
The public variables are in the declarations section of the form's module so
they should be available outside the form.

Also, using Access 2000


Well, they are, but it's different than public variables in
a standard module.

A form/report's module is a Class Module where module level
Public variables are properties of the class (and Public
Subs/Functions are methods). This means that the syntax to
refer to the variables is:

Forms!formname.variablename
 
Public Variables - Bad

Always avoid public varialbes. In your report, you can reference values in
your form. For example if you need to use the value of TextBox1 from your
form in the report, reference it as forms!MyForm!TextBox1
 
Back
Top