Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Sydney, New South Wales, Australia
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Control+Break (AccessXP)

    I have some code which picks related data from several tables and appends it to another table. All up it takes about 10 minutes on the network. To interrupt the procedure, I've been testing the use of Control+Break and of course, a system message appears. To me, this doesn't seem very user friendly for the masses.

    Is there a better way to go about user intervention? How would I code this?

    Another thing that has been happening as I test things with Control+Break, I don't get back full control of screen and keyboard. That is, I've hidden background forms, foreground forms are modal, and echo is set to off. All these settings remain after the code is interupted.

    So again, if there is a better way to control user intervention, i would really appreciate some help.
    Thanks
    Nick

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Control+Break (AccessXP)

    Unless these are very large tables (hundreds of thousands of records), I would suspect that your code could be made a lot more efficient, but that wasn't the question you asked. Control + Break is not normally used by the "masses", since it can take the user into the code behind the application. It does not change the modal properties of an object or set the screen echo back on and selecting the "End" option if presented stops your code abruptly without any cleanup, which is why you find yourself in that situation. What is it that you are trying to accomplish with this method?

    To clarify, what do you mean by "intervention"? Do you want to pause the process, abort it, or what? And what should the consequences of that action be? When you mention the network, are you talking about a front end that is on the network or merely a linked back end, with a local front end? Are you using DAO or ADO code to moving records around?
    Charlotte

  3. #3
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Sydney, New South Wales, Australia
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Control+Break (AccessXP)

    I suppose there is a possibility the code could be made more efficient. It loops through each of 3000 students, then finds the very first subject they were ever enrolled in. I could have used a DLookup to display the information but I decided to go for populating a separate table with the data because I will need to use it later for other purposes. This procedure takes up to 10 minutes to cycle through the student recordset, filtering related records then add those to the new table. It could be left to run its course and I could tell users that it could take up to 10 minutes and not to touch it, but, if they have to intervene and abort the process, then I want it to be user friendly. I don't need pausing as an option.

    If a user does need to abort, then the modal and echo properties need to be cancelled. I am using DAO. The back-end is on the network and the front-end is local. I presume Control+Break is the best keystroke for any user to abort a procedure, or is there a better one? Either way, I need help please with the coding.

    Thanks
    Nick

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Control+Break (AccessXP)

    Assuming that you start the code from (a command button on) a form, you can monitor the keyboard and react. Set the Key Preview property of the form to True, and use a boolean variable to signal if a specific key has been pressed. The following code behind a form example performs a loop, and gives the user the chance to exit gracefully if the Esc key is pressed.

    <img src=/w3timages/blueline.gif width=33% height=2>

    ' Module-level variable
    Private blnBreak As Boolean

    ' On Click handler for command button
    Private Sub cmdSomething_Click()
    Dim i As Long

    On Error GoTo ErrHandler

    blnBreak = False
    Echo False
    DoCmd.Hourglass True

    ' This is a dummy loop - replace with useful code
    For i = 1 To 10000
    ' Give events a chance
    DoEvents
    If blnBreak = True Then
    If MsgBox("End it all now?", vbQuestion + vbYesNo + vbDefaultButton2) = vbYes Then
    GoTo ExitHandler
    Else
    blnBreak = False
    End If
    End If
    Next i

    ExitHandler:
    ' Clean up and restore things to normal
    Echo True
    DoCmd.Hourglass False
    Exit Sub

    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub

    ' On Key Down handler for form
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    ' React to Esc key
    If KeyCode = vbKeyEscape Then
    blnBreak = True
    End If
    End Sub

    <img src=/w3timages/blueline.gif width=33% height=2>

  5. #5
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Sydney, New South Wales, Australia
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Control+Break (AccessXP)

    Thank you, Hans. That's exactly what I need. You're a life saver!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •