Returning public variable as a Report name?
I have 3 reports that all require start-date and end-date parameters entered when the report is run. So far I have a seperate (identical) dialogue box for each report that provides these details. All works well.
To slim things down a bit I am trying to use a single dialogue box that can be called from each of the forms but I am having trouble getting the dialogue box to recognise which form has called it.
I have created a public variable in a utility module and called it strCallingForm.
In the on open event for each report I have entered a line of code: strCallingForm = Me.Name
If I go to the utility module and check, the variable it has correctly identified the calling form.
My problem appears to be in passing it back. Below is the code I am trying to use.
If I replace the value [strCallingForm] with the actual form name all works well. There must be some syntax I am missing or some rule about passing variables I do not understand.
Any help/ideas will be much appreciated......SPROCKET
Private Sub Form_Open(Cancel As Integer)
Dim strMsg As String, strTitle As String
Dim intStyle As Integer
' If Invoice LEA report is not being opened for previewing or printing,
' cause an error. (blnOpening variable is true only when report's Open event
' is being executed.)
If Not Reports![StrCallingForm].blnOpening Then Err.Raise 0
Exit_Form_Open:
Exit Sub
Err_Form_Open:
strMsg = "To use this form, you must preview or print the report Invoice LEA from the Main Menu."
intStyle = vbOKOnly
strTitle = "Open from Memu"
MsgBox strMsg, intStyle, strTitle
Resume Exit_Form_Open
End Sub
I have 3 reports that all require start-date and end-date parameters entered when the report is run. So far I have a seperate (identical) dialogue box for each report that provides these details. All works well.
To slim things down a bit I am trying to use a single dialogue box that can be called from each of the forms but I am having trouble getting the dialogue box to recognise which form has called it.
I have created a public variable in a utility module and called it strCallingForm.
In the on open event for each report I have entered a line of code: strCallingForm = Me.Name
If I go to the utility module and check, the variable it has correctly identified the calling form.
My problem appears to be in passing it back. Below is the code I am trying to use.
If I replace the value [strCallingForm] with the actual form name all works well. There must be some syntax I am missing or some rule about passing variables I do not understand.
Any help/ideas will be much appreciated......SPROCKET
Private Sub Form_Open(Cancel As Integer)
Dim strMsg As String, strTitle As String
Dim intStyle As Integer
' If Invoice LEA report is not being opened for previewing or printing,
' cause an error. (blnOpening variable is true only when report's Open event
' is being executed.)
If Not Reports![StrCallingForm].blnOpening Then Err.Raise 0
Exit_Form_Open:
Exit Sub
Err_Form_Open:
strMsg = "To use this form, you must preview or print the report Invoice LEA from the Main Menu."
intStyle = vbOKOnly
strTitle = "Open from Memu"
MsgBox strMsg, intStyle, strTitle
Resume Exit_Form_Open
End Sub
Last edited: