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

    Another encounter with the OutputTo command

    I've had problems with the 2046 errors in the past, but not quite like this one. The code below works find for the 1st of 8 pdf files to be created, but bombs with the 2046 as soon as an attempt is made to proceed to the 2nd of the 8. Is there some other action that is required after each instance of the OutputTo? (I tried to find my old threads about these 2046 errors, but failed to find an answer there.)



    Code:
    Private Sub cmdPDFs_Click()
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '  Give UI ability to bulk refresh the floor layouts
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    Dim strShell As String
    Dim ShellRet As Variant
    Dim I As Integer
    Dim strErrMsg As String
    Dim strPDFName As String
    
    
    On Error GoTo Err_Handler
    
    
    For I = 1 To 4
        strCurFloor = CStr(100 + I)
        strfloor = CStr(I)
        
        strErrMsg = "create pdf North floor layouts: "
        strPDFName = strHostFldr & "\FloorPDFs\North" & strfloor & ".pdf"
        DoCmd.OutputTo acOutputForm, "frmNorthTower", acFormatPDF, strPDFName
        
        strErrMsg = "create pdf South floor layouts: "
        strPDFName = strHostFldr & "\FloorPDFs\South" & strfloor & ".pdf"
        DoCmd.OutputTo acOutputForm, "frmSouthTower", acFormatPDF, strPDFName
    Next I
    
    
    strShell = "c:\Windows\Explorer.exe " & strHostFldr & "\FloorPDFs\"
    ShellRet = Shell(strShell, 3)
    
    
    DoCmd.Close
    
    
    Exit_Handler:
       Exit Sub
    Err_Handler:
       MsgBox "Error " & Err.Number & " in attempting to " & strErrMsg & Err.Description
       Resume Exit_Handler
    End Sub

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Nothing obvious. You're using full version, not runtime?
    I'd try outputting the same one a second time (copy/paste the one that works, rem out the other). That way I'd know if it has anything to do with the file path being constructed.

    EDIT - both forms are open?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Using full version.

    Modified the loop to a single iteration but get a 2046 on the 2nd attempt.
    Code:
    For I = 1 To 1
        strCurFloor = CStr(100 + I)
        strfloor = CStr(I)
        
        strErrMsg = "create pdf North floor layouts: "
        strPDFName = strHostFldr & "\FloorPDFs\North" & strfloor & ".pdf"
        DoCmd.OutputTo acOutputForm, "frmNorthTower", acFormatPDF, strPDFName
    DoCmd.OutputTo acOutputForm, "frmNorthTower", acFormatPDF, strPDFName
    
    
        
        'strErrMsg = "create pdf South floor layouts: "
        'strPDFName = strHostFldr & "\FloorPDFs\South" & strfloor & ".pdf"
        'DoCmd.OutputTo acOutputForm, "frmSouthTower", acFormatPDF, strPDFName
    Next I
    Bombs on the 2nd attempt to

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Posts probably crossed. I guess my edit might not apply then. Try a pause or Do Events in between outputs. Or just a stop statement that you'll then have to F8 to get passed it (so single step in other words).
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    No luck with single step:
    Code:
    For I = 1 To 4
        strCurFloor = CStr(100 + I)
        strfloor = CStr(I)
        
        strErrMsg = "create pdf North floor layouts: "
        strPDFName = strHostFldr & "\FloorPDFs\North" & strfloor & ".pdf"
        DoCmd.OutputTo acOutputForm, "frmNorthTower", acFormatPDF, strPDFName
    Stop
        
        strErrMsg = "create pdf South floor layouts: "
        strPDFName = strHostFldr & "\FloorPDFs\South" & strfloor & ".pdf"
        DoCmd.OutputTo acOutputForm, "frmSouthTower", acFormatPDF, strPDFName
    Stop
    Next I
    Nor with a 2 second delay coupled with a DoEvents:
    Code:
    For I = 1 To 4
        strCurFloor = CStr(100 + I)
        strfloor = CStr(I)
        
        strErrMsg = "create pdf North floor layouts: "
        strPDFName = strHostFldr & "\FloorPDFs\North" & strfloor & ".pdf"
        DoCmd.OutputTo acOutputForm, "frmNorthTower", acFormatPDF, strPDFName
    Pause (2)
    DoEvents
        
        strErrMsg = "create pdf South floor layouts: "
        strPDFName = strHostFldr & "\FloorPDFs\South" & strfloor & ".pdf"
        DoCmd.OutputTo acOutputForm, "frmSouthTower", acFormatPDF, strPDFName
    Pause (2)
    DoEvents
    Next I

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,859
    Try swapping them around, South first, then North
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    DoCmd.OutputTo acOutputForm, "frmNorthTower", acFormatPDF, strPDFName
    DoCmd.OutputTo acOutputForm, "frmNorthTower", acFormatPDF, strPDFName

    If it works for the first line above but balks on that second line then I'm out of ideas.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    I thought you were "pulling my leg" with such a suggestion in that I couldn't imagine what difference it would make, but behold, when I run the single cycle loop below there's no error. If I run the 4 iteration loop it doesn't fail until the 2nd iteration.
    Code:
    For I = 1 To 1
        strCurFloor = CStr(100 + I)
        strfloor = CStr(I)
        
        strErrMsg = "create pdf South floor layouts: "
        strPDFName = strHostFldr & "\FloorPDFs\South" & strfloor & ".pdf"
        DoCmd.OutputTo acOutputForm, "frmSouthTower", acFormatPDF, strPDFName
        
        strErrMsg = "create pdf North floor layouts: "
        strPDFName = strHostFldr & "\FloorPDFs\North" & strfloor & ".pdf"
        DoCmd.OutputTo acOutputForm, "frmNorthTower", acFormatPDF, strPDFName
    Next I

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,859
    No, all I was thinking was there was a problem with the South part in some way?
    Put a Do Events at the bottom of the loop?

    No sure what strCurFloor is for, as it does not appear to get used?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Plenty of people with this issue report that it's on again, off again. So not sure you should jump to conclusions after one test of one loop iteration. One thing missing from the picture is showing how strHostFldr is declared. Possibly not relevant, but...
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #11
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Time to debug.print the paths before you try to output, and make sure the paths created by the string variable actually exist as printed?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  12. #12
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    strHostFldr is global and is Dim As String

  13. #13
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    With this code configured to reveal the string values:
    Code:
    Private Sub cmdPDFs_Click()
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '  Give UI ability to bulk refresh the floor layouts
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    Dim strErrMsg As String
    Dim strPDFName As String
    Dim strFloor As String
    
    
    On Error GoTo Err_Handler
    
    
    For I = 1 To 4
        strCurFloor = CStr(100 + I)
        strFloor = CStr(I)
        
        strErrMsg = "create pdf South floor layouts: "
        strPDFName = strHostFldr & "\FloorPDFs\South" & strFloor & ".pdf"
    Debug.Print strPDFName
        DoCmd.OutputTo acOutputForm, "frmSouthTower", acFormatPDF, strPDFName
        
        strErrMsg = "create pdf North floor layouts: "
        strPDFName = strHostFldr & "\FloorPDFs\North" & strFloor & ".pdf"
    Debug.Print strPDFName
        DoCmd.OutputTo acOutputForm, "frmNorthTower", acFormatPDF, strPDFName
    
    
    Next I
    
    
    strShell = "c:\Windows\Explorer.exe " & strHostFldr & "\FloorPDFs\"
    ShellRet = Shell(strShell, 3)
    
    
    DoCmd.Close
    
    
    Exit_Handler:
       Exit Sub
    Err_Handler:
       MsgBox "Error " & Err.Number & " in attempting to " & strErrMsg & Err.Description
       Stop
       Resume Exit_Handler
    End Sub
    The IW clearly indicates the strings are as expected:
    Click image for larger version. 

Name:	000.jpg 
Views:	13 
Size:	22.3 KB 
ID:	49248

    I need to step away for about an hour. Maybe the problem will fix itself while I'm gone

  14. #14
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    I figured out what the problem was with the 2046 errors.

    There are two towers (buildings) currently configured for the app, each with 4 floors. The two forms, frmNorthTower and frmSouthTower are a bit complex to say the least. They are more-or-less identical in how they are configured logically and populated from the underlying RecordSource, they are both "Single Form". As each instance of the form opens, the form's Load event SELECTs its floor occupant data based on either OpenArgs or in its absence the floor value found in the global variable "strCurFloor", you see that being set in each iteration of the loop. On somewhat of a hunch, I surmised that it might be a case where Access didn't detect that change as I stepped through each floor and deemed the form unavailable to process. So, as you see in the code, I opened the form hidden so it would go through its "normal" use, sent it to a pdf and then closed it. That's more or less how the UI works when the user goes from floor to floor in an interactive mode.

    Code:
    For I = 1 To 4
        strCurFloor = CStr(100 + I)
        strFloor = CStr(I)
        
        strErrMsg = "create pdf South floor layouts: "
        strPDFName = strHostFldr & "\FloorPDFs\South" & strFloor & ".pdf"
        DoCmd.OpenForm "frmSouthTower", , , , , acHidden
        DoCmd.OutputTo acOutputForm, "frmSouthTower", acFormatPDF, strPDFName
        DoCmd.Close acForm, "frmSouthTower"
        
        strErrMsg = "create pdf North floor layouts: "
        strPDFName = strHostFldr & "\FloorPDFs\North" & strFloor & ".pdf"
        DoCmd.OpenForm "frmNorthTower", , , , , acHidden
        DoCmd.OutputTo acOutputForm, "frmNorthTower", acFormatPDF, strPDFName
        DoCmd.Close acForm, "frmNorthTower"
    Next I

  15. #15
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,859
    So could you open the form once outside the loop, and then just OutputTo ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 7
    Last Post: 03-06-2020, 07:20 AM
  2. Outputto PDF cancelled
    By tinyb in forum Programming
    Replies: 12
    Last Post: 10-13-2015, 08:29 AM
  3. modify my outputto command button
    By cuddles in forum Forms
    Replies: 4
    Last Post: 05-14-2014, 05:18 AM
  4. OutputTo PDF???
    By jgelpi16 in forum Programming
    Replies: 1
    Last Post: 03-17-2011, 11:39 AM
  5. OutputTo Excel
    By smikkelsen in forum Access
    Replies: 0
    Last Post: 03-08-2011, 05:15 PM

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