ToolButton Visibility

I have a couple of buttons on a toolbar that I want to be either not visible or visible depending on options available to the user.

They are the Commit/Rollback (Save/Undo) buttons. When a record is loaded they are not visible until the user changes a field at which point they become visible. These buttons were previously not on the toolbar but at the bottom of the window and I just used the visible property. There is no corresponding visibility property on a toolbutton… So I wrote the following method. It works fine except I would like to make it a global method in a global module so that it doesn’t have to be repeated in each window. The problem is, when I put it in the global module, the tbNavigate1 toolbar isn’t available. I don’t especially want to make it public because the toolbar is named the same in every window.

So does anyone have a solution? thanks so much.

[code]Private Sub HideShowToolbarButtons(sAction As String)
if sAction = “Show” then
tbNavigate1.tiSave.icon = save40
tbNavigate1.tiSave.Caption = “Save”
tbNavigate1.tiRollback.icon = Trash32
tbNavigate1.tiRollback.Caption = “Undo”
else
tbNavigate1.tiSave.icon = nil
tbNavigate1.tiSave.Caption = “”
tbNavigate1.tiRollback.icon = nil
tbNavigate1.tiRollback.Caption = “”
end if

Return
End Sub
[/code]

and that will leave a button that cant be seen but is still pushable

there is no “visible” or not for a tool bar item
the button either exists or doesn’t (its just the way they work)

i’d add and remove the items

in your global module make your method be something like

HideShowToolbarButtons(whichToolbar as Toolbar, sAction As String)
  if sAction = "Show" then 
    whichToolbar.tiSave.icon        = save40
    whichToolbar.tiSave.Caption     = "Save"
    whichToolbar.tiRollback.icon    = Trash32
    whichToolbar.tiRollback.Caption = "Undo"
  else
    whichToolbar.tiSave.icon        = nil
    whichToolbar.tiSave.Caption     = ""
    whichToolbar.tiRollback.icon    = nil
    whichToolbar.tiRollback.Caption = ""
  end if
  
End Sub

FWIW I would split this into 2 methods as this kind of “send in the right thing to do from outside” is known as “control coupling” which is generally a bad thing - https://en.wikipedia.org/wiki/Coupling_(computer_programming)

You could give the module a reference to the toolbar.

except that still doesn’t solve the problem of visibility. But that is an excellent change which I will make.

how do I do that?

For a better UX they should always be visible, just not enabled.
Magically appearing and disappearing buttons are hard to predict for new users.

how does removing the item not make it “invisible” ?

Tim, I first tried the enable/disable property, but there is VERY LITTLE difference in the way a disabled button looks from the way an enabled one does. Much less difference that in other controls.

No, I meant the visibility of the toolbar in the global module. The toolbar is local to a window and the global module can’t see it.

[quote=325836:@william plunkett]
how do I do that?[/quote]

reread my post as I edited it as beatrix posted

then your code on the window calls the method in the global module with

HideShowToolbarButtons(tbNavigate1, sAction) // whatever action is supposed to be done

Thanks Norman, I think that’s the answer…

Maybe I’m a bit slow but how is the solution different from the original code beyond being usable for any toolbar?

It still leaves a button that is invisible but pushable, doesn’t it?

it does
Thats why I said I would add and remove buttons not try & make them invisible

William needed it to be usable by any one of several windows which had a toolbar (even named them the same)

Thanks for clearing that up for me.