views:

25

answers:

1

I hope this is a relatively easy problem although I have spent hours websearching and using T&E to no avail. Hopefully someone can help ;o)

I have an excel module that shows a UserForm to get some input data before doing a lot of processing. At the bottom of the userform are a couple of command buttons labeled "OK" and Cancel". I need to be able to have the user change option buttons then click on OK or Cancel to exit, where my module will continue the process based on whether or not "Cancel" was pressed. I just can't seem to find a way to read a Boolean result from pressing the Cancel button on the form. I'm 99% sure it's some kind of Public / Private referencing error, but I haven't earned enough experience to figure it out yet. Here is the code snippets:


(From Module1)

Sub ModuleName()

Dim State as Boolean
' Display Parameter box
UserForm2.Show
If UserForm2.ButtonCancel Then
    State = True
Else
    State = False
End If

End Sub

Based on the True or False from the Cancel, I can drive the rest of the procedure.


(UserForm2 Code)

Private Sub ButtonCancel_Click()

 BtnCancel = True

Unload Me

End Sub

Private Sub ButtonOK_Click()

 BtnCancel = False

Unload Me

End Sub


Private Sub ButtonReset_Click()

'Set the Default Settings

NEAlias.Value = "True"

NoteIgnore.Value = "True"

ABIgnore.Value = "True"

LinkIgnore.Value = "True"

End Sub

Private Sub UserForm_Initialize()

Dim BtnCancel As Boolean

'Add the Text to the options

NEIgnore.Caption = "Ignore"

NoteIgnore.Caption = "Ignore"

ABIgnore.Caption = "Ignore"

LinkIgnore.Caption = "Ignore"

NEAlias.Caption = "Alias Only"

NoteAlias.Caption = "Alias Only"

ABAlias.Caption = "Alias Only"

LinkAlias.Caption = "Alias Only"

NEMove.Caption = "Move and Alias"

NoteMove.Caption = "Move and Alias"

ABMove.Caption = "Move and Alias"

LinkMove.Caption = "Move and Alias"

'Set the Default Settings

NEAlias.Value = "True"

NoteIgnore.Value = "True"

ABIgnore.Value = "True"

LinkIgnore.Value = "True"

End Sub

That's it. It looks like it should be simple but I'm stumped. TIA for any help!

+1  A: 

[SOLVED] I finally figured ti out. I just needed this statement in the Declarations Section of Module1:

Public BtnCancel As Boolean

Craig
welcome to SO! You can go ahead and accept your answer so that others know how it was solved.
guitarthrower