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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using multiple optionbuttons with IF statements 1

Status
Not open for further replies.

kalle82

Technical User
Apr 2, 2009
163
SE
Hi!

I have a userform in word. Im using multiple optionbuttons to print the desired text for the user based on the marked optionbuttons.

My question is when you run the IF statement, for the first three choices? How can in the code include 4 new statments that comes with the first choice. Let me give you and example.

Three choices

1.Blue
2.Green
3.Red

Green has the following choices:

1.Light
2.Medium
3.Dark

How do include that in an IF statment?

Here is a sample of my code:

If OptionButton2 = True Then

UpdateBookmark "bokmark2", "Påminnelse"
UpdateBookmark "bokmark1", TextBox13
UpdateBookmark "text1", "BESLUT" & _
vbCrLf & vbCrLf & _
"Skatteverket beslutar att inte medge undantag enligt 30 § lag (2007:592) om kassaregister." & _
vbCrLf & vbCrLf & vbCrLf & vbCrLf & _
"MOTIVERING." & vbCrLf & _
"Ni har ansökt om undantag med hänvisning till att:" & _

This i were it should again look at the choices thats available for green: Light, Medium, Dark

Is there any tutorial ive been looking around.

Cheers

Carl







 
OK! I made this a bit easier.

Inside this i need to make room for more choiches how do i do that?

CAN I USE IF INSIDE IF? Look at the text below in my code it shows where i need to make the choices again. If you read my first post, this choice should be between the light, medium and dark.

Sub skapabeslut()

If OptionButton4.Value = True Then

UpdateBookmark "bokmark2", "Påminnelse"
UpdateBookmark "bokmark1", TextBox13
UpdateBookmark "text1", "BESLUT" & _
vbCrLf & vbCrLf & _
"Skatteverket beslutar att INTE medge undantag enligt 30 § lag (2007:592) om kassaregister." & _
vbCrLf & vbCrLf & vbCrLf & vbCrLf & _
"MOTIVERING." & vbCrLf & _
"Ni har ansökt om undantag med hänvisning till att:"

HERE I WANT IT TO LOOK AT 3 NEW OPTIONS BUTTONS AND CHOOSE FROM THEM AS I DID BEFORE? CAN I USE IF INSIDE IF?

ElseIf OptionButton3.Value = True Then
UpdateBookmark "text1", "BESLUT" & _
vbCrLf & vbCrLf & _
"Skatteverket beslutar att MEDGE undantag enligt 30 § lag (2007:592) om kassaregister." & _
vbCrLf & vbCrLf & vbCrLf & vbCrLf & _
"MOTIVERING." & vbCrLf & _
"Ni har ansökt om undantag med hänvisning till att:"

ElseIf OptionButton5.Value = True Then

UpdateBookmark "text1", "BESLUT" & _
vbCrLf & vbCrLf & _
"Skatteverket beslutar att AVVISA undantag enligt 30 § lag (2007:592) om kassaregister." & _
vbCrLf & vbCrLf & vbCrLf & vbCrLf & _
"MOTIVERING." & vbCrLf & _
"Ni har ansökt om undantag med hänvisning till att:"

End If


End Sub
 
You can embed IF's:
Code:
If OptionButton2 = True Then
    ' common part of code
    If opbLight=True Then
        ' light option
    ElseIf opbMedium=True Then
        ' medium option
    Else
        ' other (dark) option
    End If
End If
If you have a set of options under each colour, you could rearrange the design and use two combo boxes instead, with the dynamic contents (list) of the second one. The logic will stay the same, You can use 'Select Case' statement instead of 'If' structure.

combo
 
Thanks combo!

It works like a charm!!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top