"ARC" <PC*****@PCESoft.invalidwrote in
news:ZX***************@newssvr19.news.prodigy.net:
I know this should be simple, but in a sub-routine that's printing a
large batch of reports, how do you code the routine to look for an
escape key to allow the user to break out?
Thanks!
Andy
Private Declare Function GetKeyboardState Lib "user32" _
(pbKeyState As Byte) As Long
Private Declare Function SetKeyboardState Lib "user32" _
(pbKeyState As Byte) As Long
Private Const VK_ESCAPE = &H1B
Sub test()
Dim c As Long
Dim s As String
Dim aKeys(0 To 255) As Byte
Do
' check to see if escape key is pressed
DoEvents
GetKeyboardState aKeys(0)
If aKeys(VK_ESCAPE) And 1 Then
aKeys(VK_ESCAPE) = aKeys(VK_ESCAPE) And Not 1
SetKeyboardState aKeys(0)
MsgBox "Loop Terminated With Escape Key"
Exit Do
End If
' do work here here
' the next lines are just to give something to see
' and an example
Select Case c Mod 3
Case 0
s = "Back"
Case 1
s = "and"
Case 2
s = "Forth"
End Select
MsgBox s
c = c + 1
Loop
End Sub