+ Reply to Thread
Results 1 to 8 of 8

Goto statment or IF Then End Sub

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-01-2009
    Location
    Cincinatti,Ohio
    MS-Off Ver
    Excel 2003
    Posts
    122

    Goto statment or IF Then End Sub

    I need a macro that will show a userform if the value of any of three possible chekbox's is true. However if more than 1 checkbox is true I still only need the userform to be shown once. I have tried a few things and am stuck. I think a goto command would work, or if I could simply say If-then-End Sub, but I guess you cant do that. So here is what I have so far, please help if you can, I need to use this for a few different userforms so it is a big stumbling block for me right now. and any help would be greatly appreciated.
    Public Sub roundprocessuserformcall()
    Dim roughround As Integer
    Dim finishround As Integer
    finishround = 0
    roughround = 0
    
    If R_Router_Setup.Blanking.Value = True Then
    Blanking.Show
    R_Router_Setup.Blanking.Value = False
    End If
    
    If R_Router_Setup.RoughMachiningDiameter.Value = True Then
    
    Call RoundRoughDiminsions(roughround)
    End If
    
    If R_Router_Setup.RoughMachineLength.Value = True Then
    
    Call RoundRoughDiminsions(roughround)
    
    End If
    
    If R_Router_Setup.Dead_Center.Value = True Then
    
    End If
    
    If R_Router_Setup.Finishmachinglength.Value = True Then
    
    Call RoundFinishDiminsions(finishround)
    End If
    
    If R_Router_Setup.Finish_machine_Diameter.Value = True Then
    'RoundFinishMachine.Show
    Call RoundFinishDiminsions(finishround)
    
    End If
    
    If R_Router_Setup.RoughButtonHead.Value = True Then
    
    End If
    If R_Router_Setup.Finishbuttonhead.Value = True Then
    
    End If
    If R_Router_Setup.threading.Value = True Then
    
    End If
    If R_Router_Setup.RoughGage.Value = True Then
    'RoundRoughMachine.Show
    Call RoundRoughDiminsions(roughround)
    End If
    If R_Router_Setup.Finishgage.Value = True Then
    'RoundFinishMachine.Show
    Call RoundFinishDiminsions(finishround)
    End If
    
    If R_Router_Setup.Machine_Notches.Value = True Then
    
    End If
    If R_Router_Setup.Polishing.Value = True Then
    
    End If
    If R_Router_Setup.InertiaWeld.Value = True Then
    
    End If
    If R_Router_Setup.Tumble.Value = True Then
    
    End If
    If R_Router_Setup.ShotPeen.Value = True Then
    
    End If
    
    End Sub
    Public Sub RoundRoughDiminsions(roughround)
    If roughround >= 1 Then End Sub
    End If
    If R_Router_Setup.RoughMachiningDiameter.Value = True Then
    RoundRoughMachine.Show
    End If
    If R_Router_Setup.RoughMachineLength.Value = True Then
    RoundRoughMachine.Show
    End If
    If R_Router_Setup.RoughGage.Value = True Then
    RoundRoughMachine.Show
    End If
    roughround = roughround + 1
    End Sub
    Public Sub RoundFinishDiminsions(finishround)
    If finishround >= 1 Then GoTo 10
    End If
    
    If R_Router_Setup.Finishmachinglength.Value = True Then
    RoundFinishMachine.Show
    End If
    If R_Router_Setup.Finish_machine_Diameter.Value = True Then
    RoundFinishMachine.Show
    End If
    If R_Router_Setup.Finishgage.Value = True Then
    RoundFinishMachine.Show
    End If
    finishround = finishround + 1
    
    10 End Sub
    If you need any more info let me know, but the first sub checks the vaue of a previous userform,and if true calls 1 of 2 subs that determine if the other userform has been called yet, if so the ends the sub, or if not it shows the second userform, ....

    Also if you know of a better way to do this please let me know,

    Thanks for your time,
    Last edited by TheNewGuy; 07-09-2009 at 04:00 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Goto statment or IF Then End Sub

    How does it check the previous userform? Are the variables declared as Public or Global?

    Do you need multiple userforms? A multipage control on what userform is often a good substitute
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    06-01-2009
    Location
    Cincinatti,Ohio
    MS-Off Ver
    Excel 2003
    Posts
    122

    Re: Goto statment or IF Then End Sub

    How does it check the previous userform?
    It checks the previous userform by looking to see if the vaue of the checkbox is true.
    Are the variables declared as Public or Global?
    I am not sure, I know the variables are declared in a public sub, and they are listed in the arguments of the sub that uses them....
    Do you need multiple userforms?
    I am not sure what you mean, there are 3 userforms that I am dealing with now, 1 to check the values and then 2 different ones that check to see if the other userform has been called yet, and either call it or make sure it doesn't get called.
    A multipage control on what userform is often a good substitute
    If I use a multipage userform I will still need some code to make sure that the second and third userform only gets called one time each, even though there are three different checkbox's that can call them. Right? I have never used a multipage userform.



    How do I tell the macro to go to a certain line in the macro?(the END SUB line) I think that would be the easiest way to do this.
    Last edited by TheNewGuy; 07-09-2009 at 09:55 AM.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,009

    Re: Goto statment or IF Then End Sub

    Unless I have misunderstood, you just need an Or statement:
    Public Sub RoundRoughDiminsions(roughround)
    If roughround >= 1 Then End Sub
    End If
    If R_Router_Setup.RoughMachiningDiameter.Value Or _
       R_Router_Setup.RoughMachineLength.Value Or _
       R_Router_Setup.RoughGage.Value Then
    RoundRoughMachine.Show
    End If
    roughround = roughround + 1
    End Sub
    Everyone who confuses correlation and causation ends up dead.

  5. #5
    Forum Contributor
    Join Date
    06-01-2009
    Location
    Cincinatti,Ohio
    MS-Off Ver
    Excel 2003
    Posts
    122

    Re: Goto statment or IF Then End Sub

    Man, I though that was going to work perfect ROMPER, but it is calling the two userforms twice each. This is what I changed it, this way I am not even using the other two subs....

    Public Sub roundprocessuserformcall()
    'Dim roughround As Integer
    'Dim finishround As Integer
    'finishround = 0
    'roughround = 0
    
    If R_Router_Setup.Blanking.Value = True Then
    Blanking.Show
    R_Router_Setup.Blanking.Value = False
    End If
    
    If R_Router_Setup.RoughMachiningDiameter.Value = True Or _
    R_Router_Setup.RoughMachineLength.Value = True Or _
    R_Router_Setup.RoughGage.Value = True Then
    RoundRoughMachine.Show
    'Call RoundRoughDiminsions(roughround)
    End If
    
    'If R_Router_Setup.RoughMachineLength.Value = True Then
    
    'Call RoundRoughDiminsions(roughround)
    
    'End If
    
    If R_Router_Setup.Dead_Center.Value = True Then
    
    End If
    
    If R_Router_Setup.Finishmachinglength.Value = True Or _
    R_Router_Setup.Finish_machine_Diameter.Value = True Or _
    R_Router_Setup.Finishgage.Value = True Then
    RoundFinishMachine.Show
    'Call RoundFinishDiminsions(finishround)
    End If
    
    'If R_Router_Setup.Finish_machine_Diameter.Value = True Then
    'RoundFinishMachine.Show
    'Call RoundFinishDiminsions(finishround)
    
    'End If
    
    If R_Router_Setup.RoughButtonHead.Value = True Then
    
    End If
    If R_Router_Setup.Finishbuttonhead.Value = True Then
    
    End If
    If R_Router_Setup.threading.Value = True Then
    
    End If
    'If R_Router_Setup.RoughGage.Value = True Then
    'RoundRoughMachine.Show
    'Call RoundRoughDiminsions(roughround)
    'End If
    'If R_Router_Setup.Finishgage.Value = True Then
    'RoundFinishMachine.Show
    'Call RoundFinishDiminsions(finishround)
    'End If
    
    If R_Router_Setup.Machine_Notches.Value = True Then
    
    End If
    If R_Router_Setup.Polishing.Value = True Then
    
    End If
    If R_Router_Setup.InertiaWeld.Value = True Then
    
    End If
    If R_Router_Setup.Tumble.Value = True Then
    
    End If
    If R_Router_Setup.ShotPeen.Value = True Then
    
    End If
    
    End Sub
    Can you see why it is calling the userforms twice? And how do I make it stop? Just to clarify, I need it to call the userform if ANY of those three checkbox's are true, but if more than one checkbox is true, I still want the userform to be called only once. Thanks again for all your help!

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,009

    Re: Goto statment or IF Then End Sub

    Where are you calling that sub from?

  7. #7
    Forum Contributor
    Join Date
    06-01-2009
    Location
    Cincinatti,Ohio
    MS-Off Ver
    Excel 2003
    Posts
    122

    Re: Goto statment or IF Then End Sub

    Thank you for the reply, I was just about to edit my last post to tell you I figured it out. I had a second call to the sub that contains the IF-OR statements lurking in the workbook. That is why it was showing the userforms twice. Your suggestion worked perfectly! So again thank you! You have been a big help!

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,009

    Re: Goto statment or IF Then End Sub

    Glad to help!

+ 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