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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ARC

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

    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


  • lyle fairfield

    #2
    Re: allowing the &lt;escape&g t; key to break out of a routine

    "ARC" <PCESoft@PCESof t.invalidwrote in
    news:ZXtKj.1173 $GO4.78@newssvr 19.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 GetKeyboardStat e Lib "user32" _
    (pbKeyState As Byte) As Long
    Private Declare Function SetKeyboardStat e 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
    GetKeyboardStat e aKeys(0)
    If aKeys(VK_ESCAPE ) And 1 Then
    aKeys(VK_ESCAPE ) = aKeys(VK_ESCAPE ) And Not 1
    SetKeyboardStat e 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

    Comment

    • ARC

      #3
      Re: allowing the &lt;escape&g t; key to break out of a routine

      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.OpenRecordse t("tReprintInvo ices", 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.Fo rm!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.OpenRepor t Forms!frmOpt.Fo rm!RunName.Capt ion,
      acViewPreview, , , acWindowNormal
      DoCmd.PrintOut
      DoCmd.Close acReport, Forms!frmOpt.Fo rm!RunName.Capt ion,
      acSaveNo
      If Err = 2501 Then 'report cancelled
      'Exit Function
      End If
      End If
      End If
      Loop

      Comment

      • ARC

        #4
        Re: allowing the &lt;escape&g t; key to break out of a routine

        Thanks, Lyle. Seems like back in the VB 3.0 days, there was an even easier
        way via code without declaring functions.

        "lyle fairfield" <lylefa1r@yah00 .cawrote in message
        news:Xns9A79A67 D25326666646261 @216.221.81.119 ...
        "ARC" <PCESoft@PCESof t.invalidwrote in
        news:ZXtKj.1173 $GO4.78@newssvr 19.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 GetKeyboardStat e Lib "user32" _
        (pbKeyState As Byte) As Long
        Private Declare Function SetKeyboardStat e 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
        GetKeyboardStat e aKeys(0)
        If aKeys(VK_ESCAPE ) And 1 Then
        aKeys(VK_ESCAPE ) = aKeys(VK_ESCAPE ) And Not 1
        SetKeyboardStat e 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

        Comment

        • lyle

          #5
          Re: allowing the &lt;escape&g t; key to break out of a routine

          On Apr 7, 5:00 pm, Rich P <rpng...@aol.co mwrote:
          Hi Andy,
          But to do it
          programmaticall y 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.

          Comment

          • DFS

            #6
            Re: allowing the &lt;escape&g t; key to break out of a routine

            lyle wrote:
            On Apr 7, 5:00 pm, Rich P <rpng...@aol.co mwrote:
            >
            >Hi Andy,
            >
            >But to do it
            >programmatical ly 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"


            Comment

            • Rich P

              #7
              Re: allowing the &lt;escape&g t; key to break out of a routine

              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 ***

              Comment

              Working...