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 sizbut 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 Recognized 1

Status
Not open for further replies.

0212

Technical User
Apr 2, 2003
115
US
Hi, all! I'm using a public variable (declared in a standard module)to pass a value from a form to a report using Print Preview Command Button. The variable is not recognized in my private subroutine. How do I pass a value from a form textbox to a report textbox? Thanks for any help!
 

Can you provide some code?
How are you declaring the variable?
How are you referencing it?
What (incorrect) results do you get?

Randy
 
Randy, thanks for helping me! I've included the declaration of the Public Variables the standard module and the usage in the Private sub.

'Module 1'


Option Compare Database

Public GFReport As String
Public GFDueDate As String

'Private Sub'

Private Sub PrintRpt2_Click()

GFReport = Me!Text110.Value
GFDueDate = Me!Text118.Value
DoCmd.OpenReport stDocName, acPreview
GFReport = Reports!stDocName.Text110.Value
GFDueDate = Reports!stDocName.Text118.Value
End Sub
 
pass a value from a form to a report
Perhaps this ?
DoCmd.OpenReport stDocName, acViewPreview
DoEvents
Reports(stDocName)!Text110.Value = Me!Text110.Value
Reports(stDocName)!Text118.Value = Me!Text118.Value

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for helping me, PHV! The values still are not passed through the report. The textboxes are blank. Here's the code behind the command button on the form. Any ideas? Thanks!

Private Sub PrintRpt2_Click()
On Error GoTo Err_PrintRpt2_Click

Dim stDocName As String
Dim stDocNameF As String
stDocName = "RptFrmTrackRptDatesODR"
stDocNameF = "FrmTrackRptDatesODR"

DoCmd.OpenReport stDocName, acPreview

Me.Filter = Reports!RptFrmTrackRptDatesODR.Filter

DoEvents
Reports(stDocName)!Text110.Value = Me!Text110.Value
Reports(stDocName)!Text118.Value = Me!Text110.Value

Exit_PrintRpt2_Click:
Exit Sub
 
Perhaps try it from the other end. On the OnFormat event of the appropriate report section:

Me.Text118 = Forms!frmFormName!Text110.Value


This will display the form control values.
Cheers,
Bill
 
It looks to me like you're assigning values to your variables twice, the second set of which are blank at this point!
Code:
Private Sub PrintRpt2_Click()

[b]GFReport = Me!Text110.Value
GFDueDate = Me!Text118.Value[/b]
DoCmd.OpenReport stDocName, acPreview
[b]GFReport = Reports!stDocName.Text110.Value
GFDueDate = Reports!stDocName.Text118.Value[/b]
End Sub

Shouldn't this be:

Code:
Private Sub PrintRpt2_Click()

GFReport = Me!Text110.Value
GFDueDate = Me!Text118.Value
DoCmd.OpenReport stDocName, acPreview
[b]Reports!stDocName.Text110.Value = GFReport  
Reports!stDocName.Text118.Value = GFDueDate[/b]
End Sub

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Thanks, missingling! The simple fix did the trick! Formertexan, could you be more specific on your approach? I went to my report, but don't know where the onFormat event is. I tried the textbox and tried the form itself. Thanks all!

 
Look for the OnFormat event at the report sections (header, footer, detail).

Cheers, Bill
 
You need to make the variable Global.

Global myvariable as <datatype>
 
Thank you, foxwiz2661! However, I am not clear on the difference of Public and Global Variables. Can you help? Thanks again!
 
Using Public in the stand alone module makes the variable global for throughout the project. I think the Global foxwiz2661 mentions is recognized by VBA in order to be backwards compatible, but Access Help doesn't even have a listing for it. If you enter Global in the Help box, Public variables pop up.

Glad you got it working!

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Thank you, Missingling, for the clarification. You have been very helpful!

Jim.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top