judgehopkins
Registered User.
- Local time
- Today, 10:50
- Joined
- May 29, 2003
- Messages
- 13
This is a global variable question. When the user clicks exit, I do not want to exit unless a valid order number has been entered. I have used a global variable (gintFlag) to try to branch the Sub Form_Unload.
E.g., if the user clicks exit, the unload procedure calls the check order number procedure. If the user in the check order number procedure clicks cancel to go back to the last order entered, gintFlag is set to 1 and the execution goes back to the unload procedure.
The debugger shows the gintFlag set to 1 but the execution completely skips the If gintFlag = (gintFlag + 1) Then
gintFlag = 0
DoCmd.CancelEvent
Exit Sub
part of the code and goes to the “Do you want to exit?” messagebox, etc.
If the user clicks cancel in the check order number procedure, I want the unload procedure to stop.
Is this possible?
E.g., if the user clicks exit, the unload procedure calls the check order number procedure. If the user in the check order number procedure clicks cancel to go back to the last order entered, gintFlag is set to 1 and the execution goes back to the unload procedure.
The debugger shows the gintFlag set to 1 but the execution completely skips the If gintFlag = (gintFlag + 1) Then
gintFlag = 0
DoCmd.CancelEvent
Exit Sub
part of the code and goes to the “Do you want to exit?” messagebox, etc.
If the user clicks cancel in the check order number procedure, I want the unload procedure to stop.
Is this possible?
Code:
Option Compare Database
Option Explicit
Dim gintFlag As Integer
Private Sub Form_Unload(Cancel As Integer)
gintFlag = 0
CheckOrderNumberTest
If gintFlag = (gintFlag + 1) Then
gintFlag = 0
DoCmd.CancelEvent
Exit Sub
'When user clicks close, this confirmation box pops up;
'if user selects no, then Access returns user to the form
ElseIf MsgBox("Are you sure you want to exit?", _
vbYesNo, "Do you want to close?") = vbNo Then
Cancel = True
End If
End Sub
Private Sub CheckOrderNumberTest()
gintFlag = (gintFlag + 1)
'This procedure requires the user to enter
'a correct order number but also gives the option to cancel
'and go back to the last order entered.
If IsNull(Me!OrderNumber) Or Len(Me!OrderNumber) < 6 _
Or Not Me!OrderNumber Like "##-####" Then
If (MsgBox("Click OK to enter an order number in the format 03-1234" _
& vbCrLf & "or click CANCEL to return to the last order entered.", _
vbOKCancel, "Every order must have a correct order number!") _
= vbOK) Then
Me!OrderNumber.SetFocus
Else
DoCmd.GoToRecord , , acLast
Me!OrderNumber.SetFocus
gintFlag = (gintFlag + 1)
End If
End If
End Sub