Flushing Esc / Cancel requests from input queue (1 Viewer)

mdlueck

Sr. Application Developer
Local time
Today, 13:56
Joined
Jun 23, 2011
Messages
2,631
Previously I had been running Access applications through paces "torture testing" and had come up with three DoEvents being required to completely flush the input queue of all Esc / Cancel requests. Abridged example:

Code:
Private Sub btnClose_Click()
  'Flush keystrokes out of the buffer so that close via Esc does not generate an error msg
  DoEvents
  DoEvents
  DoEvents

  'Close window "self"
  Call uiutils_CloseForm(Me)

End Sub
Well that is all fine and dandy unless... :cool: there happens to be a "Loose Changes Yes/No box" which pops up. Scenario of how to still crash Access:

  1. Press Esc on an Edit Record form
  2. Yes/No Loose Changes box comes up (VBA MsgBox style)
  3. Press Esc several more times
  4. Then press the "Yes" button to really abandon changes
  5. VBA then crashes having detected a Cancel in the input queue :banghead:
Example of my confirmation box code:

Code:
  'Confirm dialog here...
  intRC = MsgBox("Abandon any Fandango Part Edit changes?", vbYesNo + vbQuestion + vbDefaultButton2, "Confirm Close without Save?")
  If intRC = vbNo Then
    GoTo Exit_btnRollback_Click
  End If
So I have had to stoop to doubling up my DoEvents to flush the buffer, as follows:

Code:
Private Sub btnRollback_Click()

  Dim intRC As Integer

  'Flush keystrokes out of the buffer so that close via Esc does not generate an error msg
  DoEvents
  DoEvents
  DoEvents

  'Confirm dialog here...
  intRC = MsgBox("Abandon any Fandango Part Edit changes?", vbYesNo + vbQuestion + vbDefaultButton2, "Confirm Close without Save?")
  'Flush keystrokes out of the buffer so that close via Esc does not generate an error msg
  DoEvents
  DoEvents
  DoEvents
  If intRC = vbNo Then
    GoTo Exit_btnRollback_Click
  End If

  'Close window "self"
  Call uiutils_CloseForm(Me)

Exit_btnRollback_Click:
  Exit Sub

End Sub
 

Users who are viewing this thread

Top Bottom