gooniegirl180
Board Regular
- Joined
- Aug 13, 2003
- Messages
- 152
I'm a struggling and inexperienced VBA writer. I can't get me head around what I'm doing wrong here. I am attempting to effectively disable the "X" close button on a user form. I have the following code:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
Cancel = True
Unload ClaimHeader1
MsgBox "Invalid Action", vbOKOnly
ClaimHeader1.Show
End If
End Sub
If a user clicks on the "X" close button, the "Invalid Action" message comes up correctly, however, the userform doesn't unload and is still on the screen. When the user presses on the "OK" button of the messagebox, I get the error "Form already displayed: can't be shown modally", and the debugger highlights the "ClaimHeader1.Show" command as being the error.
I tried including the command "ClaimHeader1.Hide" after the Unload command, and that worked, but only for the first press of the "X" button - if the user presses the "X" close button a second time, nothing at all happens. I have a "Cancel & Exit" button on the form, and if that is pressed at this point then the ClaimHeader1 userform stays displayed despite the code continuing to execute.
What am I missing?
Thanks,
Goonie
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
Cancel = True
Unload ClaimHeader1
MsgBox "Invalid Action", vbOKOnly
ClaimHeader1.Show
End If
End Sub
If a user clicks on the "X" close button, the "Invalid Action" message comes up correctly, however, the userform doesn't unload and is still on the screen. When the user presses on the "OK" button of the messagebox, I get the error "Form already displayed: can't be shown modally", and the debugger highlights the "ClaimHeader1.Show" command as being the error.
I tried including the command "ClaimHeader1.Hide" after the Unload command, and that worked, but only for the first press of the "X" button - if the user presses the "X" close button a second time, nothing at all happens. I have a "Cancel & Exit" button on the form, and if that is pressed at this point then the ClaimHeader1 userform stays displayed despite the code continuing to execute.
What am I missing?
Thanks,
Goonie