Disabling a Button?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a sheet with two buttons. I want only one to be active at a time based on some data. The buttons were created by simply clicking on the Button button on the Forms toolbar and drawing it in

I have a script that runs and checks some data and if one cell has a certain value, that will mean one of the buttons needs to be disabled (greyed out). How can I do this? I can't seem to find any properties or anything allowing me to access the button by name or anything like that that would allow me to do this. Can it be done

I would basically want to have something like

If Range("I8").Value = "x" The
button1.enabled=fals
button2.enabled=tru

Or something along those lines...

Thank
 
I don't know how to do that with the buttons from the forms menu, bu
the button available from the Control Toolbox has exactly that propert
and should work nicely for what you have in mind. Go t
View->Toolbars->Control Toolbox on the main menu and you can't miss it
- Piku
 
With ActiveSheet
If Range("I8").Value = "x" Then
.Buttons("Button 1").enabled=false
.Buttons("Button 2").enabled=true


I don't believe disabling them changes the appearance, however.

--
Regards,
Tom Ogilvy


Mr B said:
I have a sheet with two buttons. I want only one to be active at a time
based on some data. The buttons were created by simply clicking on the
Button button on the Forms toolbar and drawing it in.
I have a script that runs and checks some data and if one cell has a
certain value, that will mean one of the buttons needs to be disabled
(greyed out). How can I do this? I can't seem to find any properties or
anything allowing me to access the button by name or anything like that that
would allow me to do this. Can it be done?
 
How about visible = false for the button you don't want to
use and visible = true for the one you do?

-----Original Message-----
I have a sheet with two buttons. I want only one to be
active at a time based on some data. The buttons were
created by simply clicking on the Button button on the
Forms toolbar and drawing it in.
I have a script that runs and checks some data and if one
cell has a certain value, that will mean one of the
buttons needs to be disabled (greyed out). How can I do
this? I can't seem to find any properties or anything
allowing me to access the button by name or anything like
that that would allow me to do this. Can it be done?
 
I setup a Command button but when I try to access it via .Buttons("cmdCheckOut")... it gives me an "Invalid or Unqualified Reference" error

Is there a longhand way to access the button proerties or something that I'm doing wrong?
 
Originally you said:
Forms toolbar
now you are saying Commandbutton.

These are two different things handled in different ways. I won't try to
guess what you are actually doing.

--
Regards,
Tom Ogilvy

Mr B said:
I setup a Command button but when I try to access it via
..Buttons("cmdCheckOut")... it gives me an "Invalid or Unqualified
Reference" error.
Is there a longhand way to access the button proerties or something that
I'm doing wrong?
 
If I create a command button, how do I access it form within a macro to be able to set the properties?
 
If you select the forms button, and you have the the name box visible, you
will see the name of the button in the name box.

or

Sub ShowName()
For Each btn In ActiveSheet.Buttons
If InStr(1, btn.Caption, "check", vbTextCompare) Then
btn.Select
s = "Button's name is " & btn.Name & vbNewLine
s1 = "and can be addressed as Activesheet.Buttons("""
s2 = btn.Name & """)"
MsgBox s & s1 & s2
End If
Next
End Sub


--
Regards,
Tom Ogilvy


Mr B said:
I can do it either way as long as I end up with a button. I have both
buttons currently on the page. One drawn from the Forms bar and one from the
COmmand bar. However it gives me the error either way.
Here's the code I have:

If Range("I8").Value = "Checked Out" Then
Sheets("Front_End").Select
.Buttons("Check - Out").Enabled = False <--- This is where it crashes.

What do I put in the quotes? Just whatever text is in the button or is
there a Name property somewhere I can set?
 

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

Back
Top