|
-
July 22nd, 2012, 12:40 AM
#1
How to use Msgbox with Escapekey in VB6
I have tried to end my program with following procedure:-
1. When i press Escapekey in keyboard it should display messagebox stating 'Do you want to Quit?" with Yes or No Option
Remark: its work up to this.
2. But When i click on Yes button option, It wont work for me. i have used following and it display "compile error: Argument not optional"
Please correct me...
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyEscape Then
MsgBox ("Do you want to quit"), vbYesNo, "You are clossing your program"
If MsgBox = vbYes Then
End
Else
Me.Show
End If
End If
End Sub
Thank you in advance....
-
July 22nd, 2012, 12:58 AM
#2
Re: How to use Msgbox with Escapekey in VB6
Always call a separate Subroutine, and unload the TOP-MOST form, LAST:
Code:
Option Explicit
Private Sub cmdExit_Click()
Dim frm As Form
For Each frm In Forms
If frm.Name <> Me.Name Then ' Unload this form LAST
Unload frm
Set frm = Nothing
End If
Next
Unload Me
End Sub
-
July 23rd, 2012, 12:07 AM
#3
Re: How to use Msgbox with Escapekey in VB6
The error is due to improper use of MsgBox
Code:
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyEscape Then
Dim Result As Integer
Result=MsgBox ("Do you want to quit", vbYesNo, "You are clossing your program")
If Result = vbYes Then
End
Else
Me.Show
End If
End If
End Sub
That said you should not use End to stop your program but should unload all forms as shown in the post above as well as release any objects that may be active in your program. If you need to use End to stop your program then you have done something wrong.
Last edited by DataMiser; July 23rd, 2012 at 12:11 AM.
Always use [code][/code] tags when posting code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|