Displaying variable on report (1 Viewer)

Ksan

Flailling in the dark
Local time
Today, 19:21
Joined
Oct 26, 2005
Messages
36
This is probably going to be an easy answer for one of the many well informed posters out there...

I have user specified variable which is concatenated into some text to make another variable.

Blah Blah Blah USER DEFINED BIT Blah Blah etc

These variables are just strings to hold text.

I don't need to do anything with this variable except display it on a report. I'm missing something here because its just not happening.

Can some one point me in the direction that obvious went please?
 

RuralGuy

AWF VIP
Local time
Today, 12:21
Joined
Jul 2, 2005
Messages
13,826
Just add a TextBox to your report with the ControlSource set to =YourVariable
 

Ksan

Flailling in the dark
Local time
Today, 19:21
Joined
Oct 26, 2005
Messages
36
Y'know I could swear I tried that at some stage but I must have been copying and overtyping a label or summat (that'll teach me!).

Thanks for your help RG, I knew it wouldn't take the peeps of this forum long to sort me out!

:)
 

Ksan

Flailling in the dark
Local time
Today, 19:21
Joined
Oct 26, 2005
Messages
36
To further muddy the waters, I'm having trouble passing the variable to the report.

The Report when triggered opens a dialog box to specify a value for the variable. Whatever I type is displayed so the text box on the Report is working fine now but the variable from my vba code is not being shown.

The Variable is there because I can display it to a text box on a Form, but its not making the journey to the Report.

Do I have to make a specific reference to the variable such as =[xxxxxxx]![variable]? Which might be a bit tricky because it comes from a module...

Any thoughts on how to carry it across?
 

RuralGuy

AWF VIP
Local time
Today, 12:21
Joined
Jul 2, 2005
Messages
13,826
Are you talking about a global public variable in a standard module?
 

Ksan

Flailling in the dark
Local time
Today, 19:21
Joined
Oct 26, 2005
Messages
36
I've swapped the Dim statements on the variable to Public to no avail.

The relevant bits of the module now read:

Option Explicit

Public VariREPORT as string

And the Report text box (named ReportProse) reads in design mode:

=[VariREPORT]

Additionally - In the post above it reads =YourVariable but everytime I leave editting the text box the [] brackets get added to my variable name.
 
Last edited:

Ksan

Flailling in the dark
Local time
Today, 19:21
Joined
Oct 26, 2005
Messages
36
Its a global, I try not to embed anything in a form's module if I can help it.
 

RuralGuy

AWF VIP
Local time
Today, 12:21
Joined
Jul 2, 2005
Messages
13,826
Move the Global variable into a local report variable in the Open event of the report and then use the local variable as the ControlSource of your control. Why not pass the value to the report in the OpenArgs argument of the OpenRepost command?
 

Ksan

Flailling in the dark
Local time
Today, 19:21
Joined
Oct 26, 2005
Messages
36
I'm struggling with this, so this is basically what I have so far (I've trimmed the non-essentials like the error handling)

This is the global function called by a form.
Option Explicit

Public VariLIST as String
Public VariREPORT as String


Function PrintButton_PayMode()

Let VariREPORT = "BlahBlahBlah" + VariDATE
DoCmd.OpenReport VariLIST, acNormal, , , , VariREPORT

End Function

My attempts to read the VariREPORT sent by OpenArgs to the report are failing miserably at the moment, can I get a really really obvious pointer?
 

Ksan

Flailling in the dark
Local time
Today, 19:21
Joined
Oct 26, 2005
Messages
36
wOOt, I have it sussed out at long last! My problem was not with 'sending' the variable to the report but the syntax needed to get at the variable from the report.

Now added to the OnFormat property of the report header (where the text box resides) is something similar to the following snippet of code...


Function FunctionName()

Reports![ReportName]![TextboxName] = VariableName

End Function


Thanks for the help earlier RG, it may not have sunk in straight away but it helped me haul my ignorance across the finish line! :)
 

RuralGuy

AWF VIP
Local time
Today, 12:21
Joined
Jul 2, 2005
Messages
13,826
Move the OpenArgs to a printer variable in the Open event of the report.
Code:
Option Compare Database
Option Explicit
Dim MyVariable As String

Private Sub Report_Open(Cancel As Integer)

If Not IsNull(Me.OpenArgs) Then
    '-- Report is being opened from a form passing a string
    MyVariable = Me.OpenArgs
End If

End Sub
Then bind your report control to the MyVariable. Change the names to better suit your report and be more descriptive.
 

RuralGuy

AWF VIP
Local time
Today, 12:21
Joined
Jul 2, 2005
Messages
13,826
As you discovered, there are many ways to skin this cat. Thanks for posting back with your success.
 

Users who are viewing this thread

Top Bottom