How to call private sub proc XXXX

kostas

New member
Local time
Today, 14:36
Joined
Jun 26, 2009
Messages
3
Hi,
I need some guide.
Have Public sub ResetAll() within [form_frmMenu] module. In same module there is many subs and they are all private subs.
When user use some cmd.bttn on form [frmMenu] i save bttnName in global variable gActive as string.
How to make work this:
Public Sub ResetAll()
gActive=gActive &"_Click()"
Call gActive
End sub
There allway error mesage:
"Compile error:
Expected Sub,Function, or Property"
Tnx in front for your time and effort in front
 
You should be able to change the "Private" declaration to "Public". This will make the procedure visible to the rest of the code.
 
gActive is a variable and you can call it simply by name (gActive).

'Call gActive' is a call to an "Expected Sub, Function, or Property", not a variable.

some info missing in the question i think.
 
Last edited:
gActive is a variable and you can call it simply by name (gActive).

'Call gActive' is a call to an "Expected Sub, Function, or Property", not a variable.

some info missing in the question i think.

Waz,
Take look of this:
Global gActive as string
' this variable is deffined in separate module

'code from Form_frmForm1 module:
Private Sub cmdOpenForm1_Click()
Docmd.OpenForm "frmForm1"
' calls to some other subs and functions
gActive=me.cmdOpenForm1.Name
End sub

'In the same module i have Public Sub:

Public Sub ResetAll()
' Can i make this construction???????????
Call gActive&"_Click()"
' so gActive="cmdOpenForm1_Click()". Can I combine Call with string variable and get same result as when i write: Call cmdOpenForm1_Click
End Sub
I know that this example looks strange, but real question is: Can I combine Call function with variable.
 
i understand. played with it a bit but can't make it work. Call does not seem to like strings (or variables). i tried Eval but that didn't help. sry.
 
try this:
i needed this to make a combobx scroll with the form_mousewheel function
Code:
Private Sub Form_MouseWheel(ByVal Page As Boolean, ByVal count As Long)
'Some personal code...
    If Me.ActiveControl.OnChange = "[Event Procedure]" Then
        txt = Me.ActiveControl.EventProcPrefix & "_Change"
        CallByName Me, txt, VbMethod
    End If
end sub

Public Sub NrVerg_Change()
"some personal code...
End Sub
In this example i've got a combobox called nrVerg with a change event as PUBLIC sub. It has to be public! when i scroll in the combobox the activecontrol is set to this control and evenproprefix has the first string to call an avent, add the event action string after it and execute with callbyname.

greetz
 
Last edited:
Personally, I'd just avoid arbitrary code execution although. While it could be done by invoking Eval() function or Application.Run method, I'd sooner look for a different way that doesn't requires arbitrary code execution.

You may want to take a look at ChrisO's excellent technique of handling events.

Alternatively, you would just move all code out of the cmdOpenForm1_OnClick and put it into a public function or sub.. name it "OpenForm1" or whatever, then both your cmdOpenForm1_OnClick and ResetAll sub can call the same function/sub, passing in any parameter where you need to determine which form to act upon or such.
 
kostas

maybe you can do it this way

in the button click event, instead of having an event procedure, just put

=myfunction(anyparameter)

this will call a named global function (or form function) called myfunction, with an argument anyparamater. (has to be a function, but doesnt return anything)

look at how the inbuilt switchboard manager handles button clicks - exactly the same procedure.

eg One of my clients like a big CLOSE button on each form.

I have the buttton click event =GenericClose()

and a function

function GenericClose()
with screen.activeform
docmd.close
end with
exit function


I just copy the client's standard close button from form to form (and it doesnt need any more coding)
 

Users who are viewing this thread

Back
Top Bottom