azizrasul
Well-known Member
- Joined
- Jul 7, 2003
- Messages
- 1,304
- Office Version
- 365
- 2019
- 2016
- Platform
- Windows
I have the following code in the Workbook Open event.
When UserForm opens, some code opens another userform called 'frmMessageBox2' which contains two buttons and a label. The two buttons have their captions called Yes and No respectively. The code that runs when these buttons are pressed is:-
The code on the Initialize event of UserForm is:-
When the Yes button is pressed then everything works fine and 'frmMessageBox2' closes. However when the No button is pressed, frmMessageBox2 appears again each time I presse the No button. What am I doing wrong?
Code:
Application.Visible = False
UserForm.show
When UserForm opens, some code opens another userform called 'frmMessageBox2' which contains two buttons and a label. The two buttons have their captions called Yes and No respectively. The code that runs when these buttons are pressed is:-
Code:
Private Sub cmdNo_Click()
strYN = "No"
Unload Me
End Sub
Private Sub cmdYes_Click()
strYN = "Yes"
Unload Me
End Sub
The code on the Initialize event of UserForm is:-
Code:
If DoesRegistryKeyExist("HKEY_CURRENT_USER\Software\Microsoft\Office\" & dblMSOfficeVersion & "\Excel\Security\Trusted Locations\Licence Key Generator\") = False Then
With frmMessageBox2
.lblMessage.Caption = strMessage
.show
End With
If strYN = "No" Then
Exit Sub
ElseIf strYN = "Yes" Then
'some code
End If
End If
When the Yes button is pressed then everything works fine and 'frmMessageBox2' closes. However when the No button is pressed, frmMessageBox2 appears again each time I presse the No button. What am I doing wrong?