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!

Public variable not passing to report field 1

Status
Not open for further replies.

Diplodok

Technical User
May 27, 2011
3
UA
Hello.
I have MS Access report created with one unbound field which
Source data = [tts]
Then I create next VBA code in that Report module:

**************************************
Option Compare Database
Public tts

Private Sub Report_Open(Cancel As Integer)
tts = 20
End Sub

**************************************

It works well on Access2000
It doesn't work on Access 2003

What's wrong?

Thank you
 
So tts is a constant? It is always 20? Why not just put a label with 20 as the caption? Or a TextBox with "=20" as its recordsource?

The way to make the code as written work is to use a Function. Add something like:
Code:
Function Get_tts() as Integer
Get_tts = tts
end function

And the ControlSource should be =Get_tts()

But I don't se the point if it is a constant value.

You could pass a value through OpenArgs and change
Code:
tts = 20
to
Code:
tts = Me.OpenArgs
 
No, tts is not constant, naturally.
I give this example to describe problem only.
As a matter of fact, there are 5-7 unbound fields in my real report.
All those fields have to show some portion of statistic information.
All info calculated on Report_open
(I think, you do not needed full information about it.)
I only want to pass Global variable value to Report field

With Access 2000 my example worked well
But now I'm using Access 2003 and my report shows me #Name?

I have 5 different real reports with stat information.
So, I have to redesign its all?
 
Use a public function to retrieve the values of the public variables.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 

Unfortunately, you have to change all of the reports, but it should not be a huge change.

You can still do the calcs in the Report_Open Event and assign the variables, but to call them on the report you need a Function. However, since the Function can have all sorts of code in it, I recommend you do the calcs inside the function and assign the values to all of the unbound TextBoxes there.

You can do something like:
Code:
Function CalcFields() as [i]VarType[/i] ' pick appropriate type for first unbound control
'calc values here
CalcFields = ValueForFirstControl
txtSecondControl = ValueForSecondControl
txtThirdControl = ValueForThirdControl
...
End Function

Set the ControlSource of the first unbound control to "=CalcFields" and leave the other controls unbound.

If you use the same calculations in other parts of your code, you could code each calculation as its own Function and simply use "=FunctionName()" as the controlsource of each calculated control. (This is actually a 'cleaner' method and would be easier for someone else to interpret if you won the Lottery and quit.)

 
Thank You.
I finally use a function to get public variables value.
Thank you again? Gammachaser
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top