View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
shellshock[_4_] shellshock[_4_] is offline
external usenet poster
 
Posts: 1
Default Aborting a Sub procedure from a UserForm


Thanks to both of you for your suggestions. :) In the end, I used an
integer testflag very much like the boolean variable as suggested by
hanjohn, and I also used the Exit Sub command as suggested by
dominicb.

I inserted the testflag (designated X) in my userform code, which feeds
back to the main procedure as an indicator of whether or not the main
procedure should continue. Here's the userform code:

Option Explicit
Public RCType As Worksheet
Public ws As Worksheet 'this is a placeholder
Public X As Integer 'this is the testflag

Private Sub OptionButton1_Click() 'sample radio button code
Set ws = Worksheets("Sheet1")
X = 1
End Sub

Private Sub OK_Click()
Set RCType = ws
Hide
End Sub

Private Sub CANCEL_Click()
Unload Me
End Sub

The procedure that calls the code:

Sub main_procedure()
UserForm1.Show

If UserForm1.X = 1 Then
UserForm1.RCType.Activate
etc.etc.etc.
Else
Exit Sub
End If

End Sub

So, when the user selects a radio button, ws is defined, and X=1. Then,
when the user presses OK, RCType is equated to ws and the rest of
main_procedure runs.

If the user presses the OK button without first selecting a radio
button, X is still equal to 0, so we Exit Sub. If the user presses
CANCEL, the userform is unloaded, which I guess means that X=0, so that
again we Exit Sub.


--
shellshock
------------------------------------------------------------------------
shellshock's Profile: http://www.excelforum.com/member.php...o&userid=24935
View this thread: http://www.excelforum.com/showthread...hreadid=391599