Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097

    Need a method to slow execution down

    Not at all surprising to get the error depicted below. I need a method inserted in my code below after each of the DoCmd.OutputTo commands to wait for the action to complete. What method might one suggest?


    Click image for larger version. 

Name:	000.jpg 
Views:	17 
Size:	72.7 KB 
ID:	46950
    Code:
    Private Sub cmdPDFs_Click()
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '  Give UI ability to bulk refresh the floor layouts
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    Dim I As Integer
    
    
    On Error GoTo Err_Handler
    
    
    For I = 1 To 4
        strCurFloor = 100 + I
        strfloor = I
        DoCmd.OutputTo acOutputForm, "frmNorthTower", acFormatPDF, "c:\Revel\RDS\FloorPDFs\North" & strfloor & ".pdf"
        DoCmd.OutputTo acOutputForm, "frmSouthTower", acFormatPDF, "c:\Revel\RDS\FloorPDFs\South" & strfloor & ".pdf"
    Next I
    
    
    DoCmd.Close
    
    
    Exit_Handler:
       Exit Sub
    Err_Handler:
       MsgBox "Error " & Err.Number & " in attempting to create pdf floor layouts : " & Err.description
       Resume Exit_Handler
    
    
    End Sub

  2. #2
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    DoEvents ...too short ...DoEvents
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Here's an older routine that may apply.
    Code:
             '---------------------------------------------------------------------------------------
    ' Procedure : Pause
    ' Author    : From ghudson Access World Forums
    ' Date      : 28/02/2011
    ' Purpose   : To cause Access to Pause for a specific amount of time(in seconds)
    '---------------------------------------------------------------------------------------
    '
    Public Function Pause(NumberOfSeconds As Variant)
    10    On Error GoTo Err_Pause
    
              Dim PauseTime As Variant, start As Variant
    
    20        PauseTime = NumberOfSeconds
    30        start = Timer
    40        Do While Timer < start + PauseTime
    50        DoEvents
    60        Loop
    
    Exit_Pause:
    70        Exit Function
    
    Err_Pause:
    80        MsgBox Err.Number & " - " & Err.Description, vbCritical, "Pause()"
    90        Resume Exit_Pause
    
    End Function
    Test routine:

    Code:
     Sub TESTTIMER()
    
    Debug.Print Now
    Pause (3)
    Debug.Print Now
    End Sub
    Result:

    Code:
    15/05/2015 8:10:15 AM 
    15/05/2015 8:10:18 AM

  4. #4
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097
    Hi Colin,
    I don't understand your post? First, I always thought the DoEvents was to force completion of DB update activity? Second, your post suggests that I insert multiple DoEvents in succession after each of the OutputTo statements?
    Bill

  5. #5
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Just me, but I don't see the point of passing a parameter to a procedure then creating a variable that is equal to that parameter as it's already declared. One could argue that an error handler is usually a good idea, but could also argue that the pause value will be provided by code in virtually all cases, so it should never be null or of the wrong data type. I modified a similar version of the above, but eventually went with Single so that I could pass a fractional portion of seconds. Even half a second can add up if you've got many routines to run through in some sort of update. FWIW, it looks like

    Code:
    Public Function Pause(sngSecs As Single)
    Dim Start As Variant
    Start = Timer
    Do While Timer < Start + sngSecs
        DoEvents
    Loop
    End Function
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Quote Originally Posted by GraeagleBill View Post
    Hi Colin,
    I don't understand your post? First, I always thought the DoEvents was to force completion of DB update activity? Second, your post suggests that I insert multiple DoEvents in succession after each of the OutputTo statements?
    Bill
    The forum has a minimum reply length.
    Writing DoEvents was too short so I had to repeat it in order to post

    DoEvents is one method of allowing time for code to complete before the next line of code is run.
    There are other alternatives but IMO that is usually the best method.
    Specifying a Pause time can add a degree of certainty to that but will often just add an unnecessary delay.

    Or you can use dbIdle.RefreshCache - shorter delay but may not allow code completion as a result.
    See my article Speed Comparison Tests 3 - Mendip Data Systems (isladogs.co.uk)
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097
    Same error even with the DoEvents following the OutputTo commands. Could it be that the form itself might still be open?

    Code:
    Private Sub cmdPDFs_Click()
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '  Give UI ability to bulk refresh the floor layouts
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    Dim I As Integer
    
    
    On Error GoTo Err_Handler
    
    
    For I = 1 To 4
        strCurFloor = 100 + I
        strfloor = I
        DoCmd.OutputTo acOutputForm, "frmNorthTower", acFormatPDF, "c:\Revel\RDS\FloorPDFs\North" & strfloor & ".pdf"
        DoEvents
        DoCmd.OutputTo acOutputForm, "frmSouthTower", acFormatPDF, "c:\Revel\RDS\FloorPDFs\South" & strfloor & ".pdf"
        DoEvents
    Next I
    
    
    DoCmd.Close
    
    
    Exit_Handler:
       Exit Sub
    Err_Handler:
       MsgBox "Error " & Err.Number & " in attempting to create pdf floor layouts : " & Err.description
       Resume Exit_Handler
    
    
    End Sub

  8. #8
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Same error even with the DoEvents following the OutputTo commands. Could it be that the form itself might still be open?
    Not sure its relevant but you can easily check that: Google for code to check if a form is loaded

    Or adapt code already suggested about to pause code. Start with say a 10s pause. If it works, reduce to 9s & repeat reducing by one second each time until it fails
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  9. #9
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097
    Will do. I have some code somewhere that scans the forms collection, so I can use that to check the state of the form.
    Also, I have a version of the Pause function laying around somewhere in an old app. Never been a big fan of such indeterminate methods, but they do work. I always have to test them on one of my old "slower" laptops so I don't release a piece of code that works on my high-end desktop but not on a user's machine. (BTW, not applicable here, but there's a ShellWait function out in the wild that works perfectly when one needs Shell processes to complete before proceeding.)
    Thanks,
    Bill

  10. #10
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    We're focused on what GB says is required. However, perhaps that is not the case. If this code is in a runtime version, the report has to be opened before it can be output? In other words, there might be other reasons why the error is being raised, one of which could be that the form has a timer event that's interfering. I guess a pause will prove whether or not that is what the issue is.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #11
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097
    If this code is in a runtime version
    It is not.
    form has a timer event that's interfering
    None.

    I'll post back later after I get a chance to insert a "Pause". (current time preempted by other forces )

  12. #12
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097
    Micron's version of "Pause" works just fine. However, after a 10 second pause the error occurs as before. Verified first form closed and 2nd of the two OutputTo commands failed with the 2046 error.

    I'm stumped!

  13. #13
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    As always, the current and relevant posted code will provide so much more insight.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  14. #14
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097
    Below is the modified code that reveals the point of failure. I'm concluding, right or wrong, that had the DoCmd.Close acform found the form NOT open I would have received the appropriate error message. As one can see from the screenshot at the point of failure, the 2nd of the two OutputTo commands raised the error.
    Code:
    Private Sub cmdPDFs_Click()
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '  Give UI ability to bulk refresh the floor layouts
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    Dim I As Integer
    Dim strErrMsg As String
    
    
    On Error GoTo Err_Handler
    
    
    For I = 1 To 4
        strCurFloor = 100 + I
        strfloor = I
        
        strErrMsg = "create pdf North floor layouts: "
        DoCmd.OutputTo acOutputForm, "frmNorthTower", acFormatPDF, "c:\Revel\RDS\FloorPDFs\North" & strfloor & ".pdf"
        Pause (5)
        strErrMsg = "close frmNorthTower: "
        DoCmd.Close acForm, "frmNorthTower"
        
        strErrMsg = "create pdf South floor layouts: "
        DoCmd.OutputTo acOutputForm, "frmSouthTower", acFormatPDF, "c:\Revel\RDS\FloorPDFs\South" & strfloor & ".pdf"
        Pause (5)
        strErrMsg = "close frmSouthTower: "
        DoCmd.Close acForm, "frmSouthTower"
    Next I
    
    
    DoCmd.Close
    
    
    Exit_Handler:
       Exit Sub
    Err_Handler:
       MsgBox "Error " & Err.Number & " in attempting to " & strErrMsg & Err.description
       Resume Exit_Handler
    
    
    End Sub
    Click image for larger version. 

Name:	001.jpg 
Views:	15 
Size:	37.7 KB 
ID:	46952

  15. #15
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Just out of interest, try escaping that error in the error handler...

    If err=2046 Then Resume Next

    Sometimes that is enough to 'fix' recalcitrant code
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Help with execution
    By kieranharrison in forum Access
    Replies: 24
    Last Post: 06-30-2019, 09:31 PM
  2. Replies: 3
    Last Post: 07-26-2017, 08:14 AM
  3. Replies: 6
    Last Post: 06-25-2016, 02:56 PM
  4. How to halt continued execution
    By GraeagleBill in forum Programming
    Replies: 3
    Last Post: 01-04-2016, 09:48 PM
  5. Pausing macro execution
    By lupis in forum Programming
    Replies: 3
    Last Post: 06-28-2010, 12:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums