Results 1 to 11 of 11
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post
    I have a button (wow I hear you say). behind this button I call a procedure in a module.

    It can run for many minutes during which time Access cannot receive any user input.

    I want to be able to cancel the process by allowing the user to click on the button whose caption I changed from 'Process' to 'Cancel' before I called the procedure

    so clicking on the button changes the caption to "Cancelling" and i have some code in the process like

    Code:
                    DoEvents
                    If ctlCancel.Caption = "Cancelling" Then
                        MsgBox "User Cancelled", vbOKOnly, "Seesion Output"
                        ctlCancel.Caption = "Session Output"
                        GoTo Exit_Procedure
                    End If
    So how do I allow the button to be clicked while the process is running?

  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    Having just looked at this thread (but not tried anything) ....

    Does puttting some Do Events into the procedure mean that Access periodically would respond to form events such as clicking the button?

    Does your procedure involve a loop? You could try a DoEvents at the end of each loop.
    Regards
    John



  3. #3
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post
    Thanks John but I think the problem is that the click event gives over control to the procedure it calls and waits for the procedure to finish before the control returns to the calling procedure and therefore form. so you can't click the button whle the procedure is running.

    It's kinda like when you open a form in code

    docmd.openform "myform"
    ' do more stuff ...

    the ' do more stufff runs and you can return to the form

    but if you open "myform' modally then code stops until you close "myform"
    and you can't do anything to the first form until you close "MyForm"

    So I guess I want to call the procedure in such a way that the calling procedure doesn't wait for it to finish before continuing.

  4. #4
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    Did you look at the thread i pointed to? I thought that, in that thead, Hans said it worked for him.
    Regards
    John



  5. #5
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post
    Just shutdown, reopended the app and it now works fine.
    Thanks

  6. #6
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post
    So if I call a sub then the calling code continues, but if i call a funtion it must wait to get the return value before it can continue.

    Does that sound right?

  7. #7
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    I agree with John.

    I am a bit late on this thread but....

    You cannot call the same procedure to stop it.
    Best way is to have 2 buttons.
    One calls the procedure the other stops it.
    You can place them over each other and have code to hide and unhide.

    I have attached a demo.
    It has just ONE form in it with a loop stopper demo.
    If stop is not pressed it runs for 1 minute.

    On my forms the buttons are apart for clarity of demo, but you could place them on top of each other and then the button caption would appear to change even through a different button.

    It is in Access 2003 format but works fine with 2007 and 2010

    [attachment=89855:LoopStopDemo.zip]

    Please Ignore spelling error in Stoped instead of Stopped on finish message
    Attached Files Attached Files
    Andrew

  8. #8
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post
    Sure Andrew, you can't call the same procedure to stop it but you can use the same button.
    The original code I posted does work.
    Setting the caption when clicking on the button like this

    Code:
        Set ctl = Screen.ActiveControl
        Select Case ctl.Caption
            Case "Session Output"
                ctl.Caption = "Cancel"
                DoEvents
                ExportSeminarBooking
            Case "Cancel"
                ctl.Caption = "Cancelling"
            Case Else
        End Select
    just seems that I had some sort of lockup that prevented me clicking on the button until I restarted.

  9. #9
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Maybe I misunderstood issue.
    I can see you code changes the Button Caption, while ExportSeminarBooking is running,
    but it doesn't actually terminate whatever is running in ExportSeminarBooking or does it?
    Andrew

  10. #10
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    Andrew

    Here is a one button version of your demo. I think that clicking the button when it says "stop" does actually stop the first loop, because when I still had the message in, I got two of them.

    [attachment=89864:LoopStopDemoOneButton.zip]
    Attached Files Attached Files
    Regards
    John



  11. #11
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Andrew W View Post
    Maybe I misunderstood issue.
    I can see you code changes the Button Caption, while ExportSeminarBooking is running,
    but it doesn't actually terminate whatever is running in ExportSeminarBooking or does it?
    Code:
      DoEvents
                    If ctlCancel.Caption = "Cancelling" Then
                        MsgBox "User Cancelled", vbOKOnly, "Seesion Output"
                        ctlCancel.Caption = "Session Output"
                        GoTo Exit_Procedure
                    End If
    you can see in the above code that when it sees the user cancelled if sets the caption back to where it was in the start and exits the procedure

Posting Permissions

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