Changing Ribbon visiblity with click of FORM button

C

CP

Hi, all. I have a custom application written in Access 2003 that I am
converting to Access 2007. I have developed a number of customized
ribbons that display correctly when their corresponding forms
display. However, I also have other ribbons not associated with
particular forms that need to display after a button is pressed, i.e.
when the On_Click event occurs. (These ribbons are customizations of
the built-in buttons that appear when building and running queries in
regular uncustomized Access applications which is when I need them to
appear. But they also show at other times that aren't appropriate for
my customized app and that's why I need to make them visible and
invisible.)

The On_Click even has this code:
----------------
Private Sub btnPress_Click()
Call ToggleVisibility("btnPress")
End Sub
----------------

and my Code Module has this:
------------------
Option Compare Database
Public myRibbon As IRibbonUI
Public VisibleTableTools As Boolean
Dim returnedVal As Boolean

Sub GetOnLoad(ribbon As IRibbonUI)
Set myRibbon = ribbon
VisibleTableTools = True
End Sub
Sub RefreshRibbon()
myRibbon.Invalidate 'either get syntax error or if I
change it to InvalidateControl, error 91 (object or block
vriable not set
End Sub
Sub GetVisibleTableTools(control As IRibbonControl, ByRef returnedVal)
returnedVal = VisibleTableTools
End Sub
Sub GetPressed(control As IRibbonControl, ByRef returnedVal)
Select Case control.Id
Case "VisibleTableTools"
returnedVal = VisibleTableTools
End Select
End Sub
Sub ToggleVisibility(ByVal btnName)
' Sub ToggleVisibility(control As IRibbonControl, pressed As
Boolean) ' I think this is the root of my problem.
Select Case btnName
Case "btnPress" 'name of the button
VisibleTableTools = True
Call RefreshRibbon
Case Else
VisibleTableTools = False
Call RefreshRibbon
End Select
End Sub
------------------------

As you can see, in the ToggleVisibility() function, I have substituted
"Sub ToggleVisibility(ByVal btnName)" for "Sub
ToggleVisibility(control as IRibbonControl, pressed as Boolean)"
because I can't figure out how to pass in/get out the name of the
Ribbon I'm trying to make visible (since the On_Click Action doesn't
come from a ribbon).

But if I change and use the ToggleVisibility(control as
IRibbonControl, pressed as Boolean), I get a syntax error in the
RefreshRibbon() sub. If I comment out the RefreshRibbon() using
either function then I don't get any errors but nothing happens, i.e.
my Ribbon doesn't appear.

(My code was originally taken from here: http://ribbon.anirdesh.com/Callbacks5.html
but I modified it mainly because it used an action done on the Ribbon
rather than on a form so I've probably messed things up in more than
one place.)

I will be extremely grateful to anyone who can help me solve this
problem. Thanks in advance. Carol.
 

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