Returning public variable as a formname?

Sprocket

Registered User.
Local time
Today, 20:48
Joined
Mar 15, 2002
Messages
70
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
 
Last edited:
You'll need to use early binding.

ie.

Code:
Forms(myvariable).Visible = True
 
Thanks for the quick response Mile-O-Phile but where do I put your little snippet of code?

Code:
Forms(myvariable).Visible = True


I should perhaps point out that it is a report that calls the dialogue box (which is a form) and it is the report that I am trying to refer back to, so perhaps it needs to be:

Code:
Reports(myvariable).Visible = True

Also in the Northwind Traders example database they use square brackets for the report name - should I use square or rounded brackets for a variable pretending to be a report name?

Still confussed.... :confused:

SPROCKET
 
Last edited:
You don't use what I gave you; it was just an example of how to refer to a form with a variable.

Why would you want to do something like this on a report? They are, essentially, static displays of data.
 
OK,

The report's on-open event tests to see if the parameter gathering form (dialogue) is open or or not. If it is already open by another report then it passes back a message saying process in use and quits. The dialogue form then collects the user input and hides itself until the report has finished with the data and closes. When the report closes - the on close event then closes the dialogue form. As the dialogue can be called by more than one report I need to prevent the other reports calling on the parameter form whilst it is still in use hence it needs to know which report called it.

It would obviously be easy to stay with multiple dialogue forms but I believe this is considered inelegant.
 
Personally, I'd gather the appropriate paramters and then open the report - you appear to be working backwards.
 
Hi Sprocket,

i think it's appropriate to use the arrangement you're talking about -- i.e., when the report is open, use the open event to check if the dialog form is in use and if not, open it up. i use this setup a lot when making reports that require a little bit of user input before they run. when you open the form, open it as a dialog box so that execution of the report's open event proc is paused until the dialog form is hidden or closed.

i think you'd do better to use the form's OpenArgs property to pass information from the report to the form, rather than a public variable in some other module. in the report's open event proc, do this:

Code:
DoCmd.OpenForm "myform", , , , , acDialog, Me.Name

The last parameter you pass to OpenForm is a string which is used to set the form's OpenArgs property (a property meant for just this kind of thing). From the form's code module (in whichever event proc is appropriate for your application), you can use this code to "retrieve" the information you passed:

Code:
someVariable = Me.OpenArgs

OpenArgs can only ever hold a single string. If you ever need to pass more than just a single string, you can make an array of whatever type of values you have (use variants if you have heterogeneous types) and then make a delimited string from the array using Join. Then in the form's module, you'd use Split (if my memory serves) to break it back up.
 
Ah!! Magic.

Thanks SCOTTN that is a really simple (elegant) solution.

There always is an easy way, it is just finding it that's difficult.

Many thanks....Sprocket
 

Users who are viewing this thread

Back
Top Bottom