Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disabling a custom menu-button 2

Status
Not open for further replies.

jgoodman00

Programmer
Jan 23, 2001
1,510
I have a custom menu-bar, which contains a print button. This button has a function written under it, which carries out a series of procedures before printing the result.

However, I need to be able to grey-out this print button until the user has clicked another button (a print preview button, which displays the data in another form & then displays the print preview).

So, does anyone know how I disable this (or any other) button until certain criteria are met, at which point the button will cease to be greyed out????



James Goodman
j.goodman00@btinternet.com
 
First you need to set a Reference to the Microsoft Access 8.0 Object Library (0r 9.0). Then add code to change the enable property of the CommandBar Control. One method would be to add two new functions, one to set the Enable property to False and the second to set it to True. Based on when you use this Menu Bar, you can call the Function to set the property to False when the database opens, or when you open a particular Form. You call the Function to set the Enable property to True as the last step in the Print Preview Macro, and you'd call the Function to set it back to False as the last step in the Print Macro. You need to know the name of the Menu Bar and the Name or Caption of the Print item. For this example we'll use a Menu Bar name of mnuTest and a Caption of "Print..." for the print button.

Public Function CmdBarPrintDisable()
Dim cbr As CommandBar
Dim cbrCtl As CommandBarControl
' Set a reference to the Access menu bar
Set cbr = CommandBars("mnuTest")
' Set a reference to the Print Control on the Menu Bar
Set cbrCtl = cbr.Controls("Print...")
' Set the Enabled Property to False
cbrCtl.Enabled = False
End Sub

Public Function CmdBarPrintEnable()
Dim cbr As CommandBar
Dim cbrCtl As CommandBarControl
' Set a reference to the Access menu bar
Set cbr = CommandBars("mnuTest")
' Set a reference to the Print Control on the Menu Bar
Set cbrCtl = cbr.Controls("Print...")
' Set the Enabled Property to False
cbrCtl.Enabled = True
End Function

HTH
PaulF
 

cbrCtl.Text = "Something Else"

doesn't work can someone tell me why? and how i can change the .text property of a msoControledit without reloading the whole commandbarmenu.

much appreciated
MMFL-
Mavericks Fan For Life
 
cbrCtl is declared as a CommandBarControl. CommandBarControl objects don't have a Text property, and that's why you get an error.

If you change the Dim statement to
Dim cbrCtl As CommandBarButton
it should work.

BTW, if anybody else finds this code in a forum search, you should know that PaulF had a typo in the first sentence. You need to set a reference to Microsoft Office 8.0 Library (or 9.0). Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top