Public Variables (1 Viewer)

hully333

Registered User.
Local time
Today, 15:21
Joined
Feb 7, 2008
Messages
18
Need a little help as i am a novice.

Using 1 form to select an option, depending on that option a string variable is populated with a path. (this bit works fine) as follows.
I have declared as....
public reportpath as string

Button click code;

Private Sub cmdrunrep_Click()
'On Error GoTo errortrap

If Frame15.Value = 1 Then
reportpath = "S:\reports\ITPR_Summary_PLC"
Else
If Frame15.Value = 2 Then
reportpath = "S:\reports\ITPR Lookup PLC"
End If
End If

Text26.SetFocus
Text26.Text = reportpath

'run the report viewer macro
DoCmd.RunMacro "runrep"


The runrep macro loads a form with crystal reports control on it.
and the load form code is ;

Private Sub form_Load()
On Error GoTo errortrap

Dim crReport As CRAXDRT.Report
Dim crApplication As New CRAXDRT.Application

Set crReport = crApplication.OpenReport(reportpath)

Text3.SetFocus
Text3.Text = reportpath

crv.ReportSource = crReport
crv.ViewReport

errortrap:
MsgBox Err.Description
Exit Sub

End Sub


Using the public string variable named reportpath at this point is empty and loses the actual path. As you can see i have added some temporary text boxes to see what the variable contains. It is empty on form load.

Please help the rest works fine. I feel i have done all the hard work but now i want it to run 1 of several reports i have missed something simple.
PS. just hard coding the report path into the form load event works fine and runs the Crystal ActiveX no problem. Just need to be able to pass the changing report path over to the load event from the button click event.

Regards

Simon
 
Last edited:

KenHigg

Registered User
Local time
Today, 10:21
Joined
Jun 9, 2004
Messages
13,327
Try declaring the var's in a stand alone module.
 

WayneRyan

AWF VIP
Local time
Today, 15:21
Joined
Nov 19, 2002
Messages
7,122
Simon,

Do as Ken says and put your variable in a Public Module, then
the Macro can see it.

Also:

Code:
Private Sub form_Load()
On Error GoTo errortrap

Dim crReport As CRAXDRT.Report
Dim crApplication As New CRAXDRT.Application

Set crReport = crApplication.OpenReport(reportpath)

Text3.SetFocus
Text3.Text = reportpath <-- The .Text property is ONLY available in the OnChange event
                            of Text3.  You should use .Value, or nothing, which is the
                            default.

crv.ReportSource = crReport
crv.ViewReport          <-- Once you get it working, you'll always "fall" into the
                            error routine below.

Exit Sub                <-- You need to add this line.

errortrap:
MsgBox Err.Description
Exit Sub

End Sub

hth,
Wayne
 

Users who are viewing this thread

Top Bottom