passing a variable from one module to another

ronnroz

Registered User.
Local time
Today, 02:58
Joined
Nov 30, 2004
Messages
15
I have to pass this value, declared as Variant, from one module (form) to another module (another form). But this variable is not one of the objects of any query, table or forms. It's a variable being calculated in a module. Now how can I pass this value to a different module? Here's the example:

Function glrQBF_DoHide(frm As Form)

Dim varSQL As Variant
Dim strParentForm As String

'Get the name of the Parent form
strParentForm = Left(CStr(frm.Name), Len(CStr(frm.Name)) - 4)
'Create the approprite Where clause based on the fields with data in them
varSQL = glrDoQBF(CStr(frm.Name), False)
'Open the Parent form filtered with the Where clause genereated above
DoCmd.OpenForm strParentForm, acNormal, , varSQL
'Make this *_QBF form invisible
frm.Visible = False
' DoCmd.Close
End Function


As you can see the variable varSQL is being created in the above module and I would like to pass the value of varSQL to another module which is a part of a different form.

Please help me. Thanks.
 
The problem has to do with limitations on class modules and scope rules. If I recall correctly, a class module (one associated with a form or report) can never become public. Therefore, you really cannot activate something that is visible across modules when limited to class modules.

The problem is in using a class module, but you cannot initiate an action from a general module (except with a RunCode macro).

The only way to do this (that I can recall offhand) has to do with the fact that if two forms are open, their controls are at least potentially visible to each other. Something like Forms!Form("formname")!Controlname, but you should look up this syntax in Help - having to do with working with controls on other forms.

I'm not even sure that you can activate an entry point in a class module from outside the context of the class module. I don't think the syntax supports it. So passing a parameter to a subroutine in a form is the wrong answer.

Try moving the subroutine or function to a general module, but with the understanding that if you are trying to alter something on form 1 from form 2, this isn't necessarily the way to do it.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom