PDA

View Full Version : Userform - is it possible?



blackie42
02-16-2008, 10:11 AM
Is it possible to have certain textboxes available dependent on which option button is selected? Any help with the code would be appreciated

e,g If optionbutton 1 is selected then textbox1 & 2 available (for input)
If optbut 2 selected then txtbox 1 & 3 available
If optbut 3 selected then txtbox 2 & 3 available

thanks

Jon

Bob Phillips
02-16-2008, 10:34 AM
Private Sub OptionButton1_Click()
With Me

.TextBox1.Visible = True
.TextBox2.Visible = True
.TextBox3.Visible = False
End With
End Sub

Private Sub OptionButton2_Click()
With Me

.TextBox1.Visible = True
.TextBox2.Visible = False
.TextBox3.Visible = True
End With
End Sub

Private Sub OptionButton3_Click()
With Me

.TextBox1.Visible = False
.TextBox2.Visible = True
.TextBox3.Visible = True
End With
End Sub

Private Sub Userform_Activate()

Me.OptionButton1.Value = True
End Sub

blackie42
02-16-2008, 11:41 AM
Thanks XLD - works like a charm.

Have another question on userforms - I think its possible - If I say had 3 optionbuttons on a user form - by hitting command button can I display a further userform dependent on which option button is active? Something like 'if optbut1 selected show userform2, if optbut2 selected show useform3 etc.

thanks

AmardeepD
02-16-2008, 12:08 PM
I would suggest that in the withme sections of each optionbox write an identifying integer or string to a variable ( i.e ident =1 or ident= opt1 where ident is the variable which is declared general in the userform) and then in the command button have a group of cascaded ifs so that depending on what options were selected it will change what form is being opened.

Bob Phillips
02-16-2008, 12:20 PM
Private Sub CommandButton1_Click()

If Me.OptionButton1 Then

Userform2.Show
ElseIf Me.OptionButton2 Then

Userform3.Show
Else

Userform4.Show
End If


BTW, you should use more meaningful names than OptionButton1, Userform2, etc.

blackie42
02-16-2008, 12:22 PM
mmmh I'll have to think about it a bit - a little confused

thanks anyway

Bob Phillips
02-16-2008, 01:59 PM
By what?

blackie42
02-16-2008, 04:00 PM
Thanks again XLD - it is pretty logical when you think about it - problem is I am a fairly infrequent user of vba - just need a bit of help to get started (and I was never much good a logic!)

thanks again