Thanks, forgot that little tidbit.The_Doc_Man said:Implied but not stated explicitly in FoFa's answer is that the other form must be open at the time.
can I have more than one procedure in one module?FoFa said:Thanks, forgot that little tidbit.
I used DoCmd.OpenModule(), to open up the module and call my procedure, but it keeps returning an error.FoFa said:Thanks, forgot that little tidbit.
docmd.OpenModule("showHide", "ShowControl")
Call YourProcerhureName
Call YourFunctionName(Argument1, Argument2....)
When I call it my procedure using 'Call myprocedure', it returned this error.Banana said:You don't do that.
Instead, use this:
Code:Call YourProcerhureName
If it's a function that requires some parameters, then
Code:Call YourFunctionName(Argument1, Argument2....)
Of course, they have to be public.
HTH.
The reason I am wanting to call a procedure from a module to a form is because I want to call this procedure in many forms.Fear Naught said:Sorry Bee, maybe I am confused about what you are trying to do. Why would you want to open the Module. What you need to do is either run a function or call a sub procedure.
To run a function just type the function name into code on your form or if trying to get a value for a text box then the control source for the text box should be:
=functionname()
To call a sub procedure in a form use:
Call ProcedureName.
There is no reason to refer to the module name that the procedures/functions are in.
Hope this helps.
Thanks for your help guys.FoFa said:I think what Doc Man is trying to say, is there are some things "tied" in the event procedure to the form (so to say). Typically what you need to do when you setup a global procedure, is pass whatever it needs to work with from the event procedure in the form. Have it do it's work, and depending on what is required, return a value/s. So lets say you global module you want to call from many different forms is suppose to take a yes/no value from a checkbox, and update a record with current date (if yes), flag it as past due if No.
Your event procedure would "capture" the value of the check box and them pass this along with a primary key (it needs to know WHAT to update) to the procedure:
CALL MyProcedure(Me.MyCheckbox, Me.primaryKey)
SUB MyProcedure(CBvalue as binary, PK as long)
' Do work here
END SUB
SO what is happening is the main work is common and the same no matter what calls the global procedure. But each form isolates itself from the module.
That is rather simplistic explaination, but should give you an idea of what we are talking about.
Clear as MUD?