Control menu through function?

H

Henrootje

I tried to write a function that will allow me to control the menubar
of an access application that I am developing.

This is what I got but as you see it generates a string and I do not
know how to execute this...
Are there any suggestions as to how I could do this?


----------------------------------------------------------code-------------------------------------------------------

Function fMenu(vOnOff As Boolean, vLaag1 As Integer, Optional vLaag2 As
Integer, Optional vLaag3 As Integer)

'With this code the menuitems get enabled/visible
'fMenu(1, 2, 1)for example will enable the first command in the second
item of the topmenu

Dim vAction
Dim vState
Dim vOpdracht

If vOnOff = 1 Then 'translate 1 and 0 to true or false
vState = "True"
Else
vState = "False"
End If

If vLaag2 = 0 Then 'if it concerns second layer, anything gets
invisible instead of disabled
vAction = "Enabled"
vOpdracht = "CommandBars('OK Revisie').Controls(" & vLaag1 & ")." &
vAction & "=" & vState
GoTo Uitgang
Else
vAction = "Visible"
If vLaag3 = 0 Then
vOpdracht = "CommandBars('OK Revisie').Controls(" & vLaag1 &
").Controls(" & vLaag2 & ")." & vAction & "=" & vState
GoTo Uitgang
Else
vOpdracht = "CommandBars('OK Revisie').Controls(" & vLaag1 &
").Controls(" & vLaag2 & ").Controls(" & vLaag3 & ")." & vAction & "="
& vState
GoTo Uitgang
End If
End If

Uitgang:
Debug.Print Eval(vOpdracht)

End Function
 
A

Alessandro Baraldi

Henrootje ha scritto:
I tried to write a function that will allow me to control the menubar
of an access application that I am developing.

This is what I got but as you see it generates a string and I do not
know how to execute this...
Are there any suggestions as to how I could do this?


----------------------------------------------------------code-------------------------------------------------------

Function fMenu(vOnOff As Boolean, vLaag1 As Integer, Optional vLaag2 As
Integer, Optional vLaag3 As Integer)

'With this code the menuitems get enabled/visible
'fMenu(1, 2, 1)for example will enable the first command in the second
item of the topmenu

Dim vAction
Dim vState
Dim vOpdracht

If vOnOff = 1 Then 'translate 1 and 0 to true or false
vState = "True"
Else
vState = "False"
End If

If vLaag2 = 0 Then 'if it concerns second layer, anything gets
invisible instead of disabled
vAction = "Enabled"
vOpdracht = "CommandBars('OK Revisie').Controls(" & vLaag1 & ")." &
vAction & "=" & vState
GoTo Uitgang
Else
vAction = "Visible"
If vLaag3 = 0 Then
vOpdracht = "CommandBars('OK Revisie').Controls(" & vLaag1 &
").Controls(" & vLaag2 & ")." & vAction & "=" & vState
GoTo Uitgang
Else
vOpdracht = "CommandBars('OK Revisie').Controls(" & vLaag1 &
").Controls(" & vLaag2 & ").Controls(" & vLaag3 & ")." & vAction & "="
& vState
GoTo Uitgang
End If
End If

Uitgang:
Debug.Print Eval(vOpdracht)

End Function

As you Write the OnAction property can contain a function to Call....!
Why you use EVAL....?
On modify the property the commandbar(Control) will generate the
call...!

To call it you need a Function...!

Es:
CommandBars('OK Revisie').Controls(" & vLaag1
&").OnAction="=ExecFunc()"

Now you Need ExecFunc() so....

Public Function ExecFunc()
msgbox "I'm still Executing the menù"
End Function

@Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top