PDA

View Full Version : Solved: hide or show command button...



lazyuser
02-18-2009, 12:58 PM
i have a form that has two option/radio buttons, four text fields, one list box and two command buttons.

i need to show cmdButton1 if opt1 is chosen. in this option, the four text fields are activated/enabled and the listbox is disabled.

i need to show cmdButton2 if opt2 is chosen. in this option the list box is activated/enabled and the text boxes are disabled.

i need to display these buttons at the same place. just disable one show the other depending on the chosen option.

is this possible? thankzzz in advance

fumei
02-18-2009, 01:20 PM
"is this possible?"




Yes. Although perhaps you could explain WHY you need two commandbuttons? You could simply change the Caption of the one commandbutton to reflect the option button selected. Then build the different logic requirements into the ONE button.

You could all this with the values of your option buttons (if they are indeed in a frame).

IF opt1.Value = True Then
Listbox1.Enabled = True
Textbox1.Enabled = False
Textbox2.Enabled = False
Textbox3.Enabled = False
' etc. etc.
CommandButton1.Caption = "Yadda"
Else ' opt1 is False
Listbox1.Enabled = False
Textbox1.Enabled = True
Textbox2.Enabled = True
Textbox3.Enabled = True
' etc. etc.
CommandButton1.Caption = "Alternative"
End If


For the commandbutton...

Sub CommandButton1_Click()
Select Case CommandButton1.Caption
Case "Yadda"
' do what ever you were using for commandbutton1
Case "Alternative"
' do what ever you were using for commandbutton2
End Select
End Sub

fumei
02-18-2009, 01:23 PM
Oh, and yes, you can show or hide controls on a userform. It is called the .Visible property.

lazyuser
02-18-2009, 01:35 PM
"is this possible?"




Yes. Although perhaps you could explain WHY you need two commandbuttons? You could simply change the Caption of the one commandbutton to reflect the option button selected. Then build the different logic requirements into the ONE button.

You could all this with the values of your option buttons (if they are indeed in a frame).

IF opt1.Value = True Then
Listbox1.Enabled = True
Textbox1.Enabled = False
Textbox2.Enabled = False
Textbox3.Enabled = False
' etc. etc.
CommandButton1.Caption = "Yadda"
Else ' opt1 is False
Listbox1.Enabled = False
Textbox1.Enabled = True
Textbox2.Enabled = True
Textbox3.Enabled = True
' etc. etc.
CommandButton1.Caption = "Alternative"
End If

For the commandbutton...

Sub CommandButton1_Click()
Select Case CommandButton1.Caption
Case "Yadda"
' do what ever you were using for commandbutton1
Case "Alternative"
' do what ever you were using for commandbutton2
End Select
End Sub


awesome. thanks! it worked.

fumei
02-18-2009, 01:48 PM
Please be a bit more judicious with the Quote message in reply checkbox. It puts the whole thing in. As you can see in the post above, quoting my whole post does not really serve much purpose.

If you wish to quote a part of someone message, use the quote tags.

thanks! i'll try this out.

lazyuser
02-18-2009, 02:23 PM
Please be a bit more judicious with the Quote message in reply checkbox.

sorry! will do

fumei
02-19-2009, 09:07 AM
Thanks. I know you have just joined here, so not a problem. BTW: welcome to VBAX!

lucas
02-19-2009, 12:42 PM
lazyuser, since you are new here you should know that you can and should mark your own threads solved using the thread tools at the top of the page.

It's courteous to people trying to help when they don't have to read through an entire thread just to find it's been solved...

lazyuser
02-24-2009, 01:57 PM
just figured out how to close a thread as solved. here goes. i had no idea how to do this. now i do. sorry