+ Reply to Thread
Results 1 to 5 of 5

Option button click with if else statment

Hybrid View

peedarp1985 Option button click with if... 06-02-2010, 11:11 PM
Paul Re: Option button click with... 06-02-2010, 11:26 PM
peedarp1985 Re: Option button click with... 06-02-2010, 11:55 PM
shg Re: Option button click with... 06-03-2010, 12:07 AM
peedarp1985 Re: Option button click with... 06-03-2010, 12:11 AM
  1. #1
    Registered User
    Join Date
    05-11-2010
    Location
    Portland oregon
    MS-Off Ver
    Excel 2007
    Posts
    10

    Option button click with if else statment

    I am trying to execute a program using if else statement on an option button to open a userform on a command button click. The following userforms are named as drilling, milling and so on. The trouble I am having is, the vba tell me my if else statements are wrong could some one show me the right way if i am doing something wrong

    Private Sub Ok_Click()
    
    
     If Drilling.Value = True Then Drilling.Show
     ElseIf Milling.Value = True Then Milling.Show
     ElseIf Turning.Value = True Then Turning.Show
     ElseIf Reaming.Value = True Then Reaming.Show
     ElseIf Boring.Value = True Then Boring.Show
    
    End If
    
    End Sub
    Last edited by peedarp1985; 06-03-2010 at 12:12 AM.

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Option button click with if else statment

    Because you put the first IF/THEN on one line, that ends the entire IF statement. You must put the action after the THEN on another line in order to use ELSEIF. For example:
    Private Sub Ok_Click()
    If Drilling.Value Then
        Drilling.Show
    ElseIf Milling.Value Then
        Milling.Show
    ElseIf Turning.Value Then
        Turning.Show
    ElseIf Reaming.Value Then
        Reaming.Show
    ElseIf Boring.Value Then
        Boring.Show
    End If
    End Sub
    You don't need the "= TRUE" part in each test, since an option button should be either True or False by nature.

  3. #3
    Registered User
    Join Date
    05-11-2010
    Location
    Portland oregon
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Option button click with if else statment

    I tried the code but I am still having issues. It shows me an error and when I debug it it points to the process I selected. How can I have it link to the userform i have created and open it.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Option button click with if else statment

    You have a name conflict if you have ActiveX option buttons with the same names as forms. If that's the case, name the buttons as optDrilling, optMilling, etc.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Registered User
    Join Date
    05-11-2010
    Location
    Portland oregon
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Option button click with if else statment

    Thanks that worked.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1