473,395 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

allowing the <escape> key to break out of a routine

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
Apr 7 '08 #1
6 3355
"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
Apr 7 '08 #2
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

Apr 7 '08 #3
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" <ly******@yah00.cawrote in message
news:Xn***********************@216.221.81.119...
"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
Apr 7 '08 #4
On Apr 7, 5:00*pm, Rich P <rpng...@aol.comwrote:
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.
Apr 7 '08 #5
DFS
lyle wrote:
On Apr 7, 5:00 pm, Rich P <rpng...@aol.comwrote:
>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"
Apr 7 '08 #6
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 ***
Apr 7 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Luis P. Mendes | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I only know a little bit of xml and I'm trying to parse a xml document in order to save its elements in a file (dictionaries inside a list)....
1
by: Christian Schmidbauer | last post by:
Hello! I prepare my XML document like this way: ------------------------------------------------------- PrintWriter writer; Document domDocument; Element domElement; // Root tag
2
by: Francesco Moi | last post by:
Hello. I designed a form to edit some DataBase's fields. But some of these fields contain '&lt;' and '&gt;' characters. And these characters are '<' and '>' in HTML. So if want to edit these...
11
by: Les Paul | last post by:
I'm trying to design an HTML page that can edit itself. In essence, it's just like a Wiki page, but my own very simple version. It's a page full of plain old HTML content, and then at the bottom,...
7
by: Tony | last post by:
I'm using XmlTextWriter to write XML to a string and XmlDocument to read it back. Every thing works OK except if my data contains a < or >. If this is the case they get saved as < > repectively....
1
by: chuck | last post by:
Hi, I have a php function creating links from a products mysql database. some of the descriptions have characters that I need to escape but whatever i do, javascript doesn't like them. for...
9
by: Eric Lindsay | last post by:
I can't figure how to best display little snippets of shell script using <pre>. I just got around to organising to bulk validate some of my web pages, and one of the problems occurs with Bash...
131
by: Lawrence D'Oliveiro | last post by:
The "escape" function in the "cgi" module escapes characters with special meanings in HTML. The ones that need escaping are '<', '&' and '"'. However, cgi.escape only escapes the quote character if...
5
by: Jeff | last post by:
One thing I admire about php is that there is usually a function that does exactly what you want. I'm building an RSS feed (something I had in perl). There's a lot about escaping rss data I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.