allowing the <escape> key to break out of a routine
allowing the <escape> key to break out of a routine
am 07.04.2008 20:44:29 von Arc
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
Re: allowing the <escape> key to break out of a routine
am 07.04.2008 21:53:33 von Rich P
Hi Andy,
Access does not support that kind of functionality. This would require
multithreading -- which belongs to the Object Oriented Programming (OOP)
environment. The thing with Access is this: it is a High Level
Programming Platform -- meaning that it is significantly removed from
the operating system -- where lower level environments like VS.Net,
Java, are much closer to the operating system - thus giving you much
more control over what you can do (C++/MFC being even closer to the OS
-- just above Assembly Language which is just above machine language).
So VBA does not support multithreading (neither does VB6). VB.Net will
support multithreading since it is part of the OOP environment.
Once you click the print button in Access, the only way to break out of
the print job is to hit the stop/off button on the printer and then
cancel the print job on the workstation.
Rich
*** Sent via Developersdex http://www.developersdex.com ***
Re: allowing the <escape> key to break out of a routine
am 07.04.2008 22:22:18 von Lyle Fairfield
"ARC" wrote in
news:ZXtKj.1173$GO4.78@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
Re: allowing the <escape> key to break out of a routine
am 07.04.2008 22:22:28 von Arc
Hi Rich,
I'm printing a number of separate reports in a subroutine. It's actually a
"reprint invoices" function, which could print many many invoices, each one
a separate report. So I'm not meaning to break out while it's actually
printing, but between print jobs. Seems like I remember a visual basic
command from years ago that would allow you to break out of a routine if a
key was pressed.
Andy
P.S. Here's a sample of the code:
Do Until exitout = -1
Set db = CurrentDb()
Set rs = db.OpenRecordset("tReprintInvoices", DB_OPEN_DYNASET)
If rs.BOF Then
MsgBox "No invoices were found where the Invoice Printed box
was unchecked.", vbInformation
rs.Close
Set db = Nothing
Exit Function
End If
rs.FindFirst "PrintedYN = 0"
If rs.NoMatch Then
rs.Close
Set db = Nothing
exitout = -1
Else
Forms!frmOpt.Form!InvoiceNo = rs!InvoiceNo
rs.Edit
rs!PrintedYN = -1
rs.Update
'If Command() = "t" Then
' MsgBox "Printing Invoice #" & rs!InvoiceNo
'End If
rs.Close
Set db = Nothing
If Command() = "t" Then
'don't print
Else
DoCmd.OpenReport Forms!frmOpt.Form!RunName.Caption,
acViewPreview, , , acWindowNormal
DoCmd.PrintOut
DoCmd.Close acReport, Forms!frmOpt.Form!RunName.Caption,
acSaveNo
If Err = 2501 Then 'report cancelled
'Exit Function
End If
End If
End If
Loop
Re: allowing the <escape> key to break out of a routine
am 07.04.2008 22:48:45 von Arc
Thanks, Lyle. Seems like back in the VB 3.0 days, there was an even easier
way via code without declaring functions.
"lyle fairfield" wrote in message
news:Xns9A79A67D25326666646261@216.221.81.119...
> "ARC" wrote in
> news:ZXtKj.1173$GO4.78@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
Re: allowing the <escape> key to break out of a routine
am 07.04.2008 23:00:47 von Rich P
Hi Andy,
You can always press Ctrl-break to break out of a loop. But to do it
programmatically in Access, the only way to break out of a loop would be
to add a routine within the loop which would read - say a text file -
that you would modify from a separate app. If the text file says "keep
going" then the loop continues. But if the text file says something
like "stop" then the loop breaks out. If you try this - make sure you
add DoEvents before the textfile read line
Do While something = true
DoEvents
Open "C:\yourdir\BreakOut.txt" for input as #1
Input #1, s1
Close #1
If s1 = "Stop" then
Something = False
Exit Do
End If
...
Loop
The only catch with this is that you would need to have another app
running concurrently where you could modify the text file. This would
simulate multithreading because each app would be running on a different
thread. But true multithreading implies that you are running multiple
threads from the same app.
Rich
*** Sent via Developersdex http://www.developersdex.com ***
Re: allowing the <escape> key to break out of a routine
am 07.04.2008 23:08:41 von lyle
On Apr 7, 5:00=A0pm, Rich P wrote:
> Hi Andy,
> But to do it
> programmatically in Access, the only way to break out of a loop would be
> to add a routine within the loop which would read
It's a wise man indeed who knows the only way.
Re: allowing the <escape> key to break out of a routine
am 07.04.2008 23:43:25 von DFS
lyle wrote:
> On Apr 7, 5:00 pm, Rich P wrote:
>
>> Hi Andy,
>
>> But to do it
>> programmatically in Access, the only way to break out of a loop
>> would be to add a routine within the loop which would read
>
> It's a wise man indeed who knows the only way.
Does that apply to wise men as well?
"Anytime, my friend, that Lyle and I agree, you should take heed, because we
differ on a great many matters of opinion, so our areas of agreement are
more often than not, matters of fact."
Larry Linson
Microsoft Access MVP"
Re: allowing the <escape> key to break out of a routine
am 08.04.2008 00:46:32 von Rich P
Disclaimer:
"the only way" implies "The only way that I know how to do it". "the
only way" is the abbreviated form.
Rich
*** Sent via Developersdex http://www.developersdex.com ***