Page 2 of 2 FirstFirst 12
Results 16 to 27 of 27
  1. #16
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Am I missing something here, but isn't that code simply going to print the same pdf 4 times with a different file name?

    strCurFloor = 100 + I

    I'm guessing this should be a criteria used somewhere to reopen the form with different data, but that isn't happening.
    I would have thought you needed (air code obviously)

    docmd.openform .... , Criteria
    docmd.outputTo ...
    docmd.close ac form ...



    This is how you would loop through a report on the same basis, and I don't think a form being printed would be any different.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  2. #17
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,818
    I wouldn't do that yet (I mean use that as a solution) but out of curiosity is OK. GB, have you stepped through that code to
    a) see which pass it is that is raising the error as you have a loop there.
    b) see if it still fails when stepping through

    Why would you declare an integer and pass its value to a string? You're asking for trouble doing that sort of thing. That's what type conversion functions are for.
    Last edited by Micron; 12-29-2021 at 10:14 AM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #18
    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,742
    @Minty

    I don't think so.

    The loop has 4 iterations. GB has North and South towers, and each has 4 floors. Output has Floor & I - so I think the logic seems ok. We'll have to see what resolves the error condition.

  4. #19
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,008
    Quote Originally Posted by orange View Post
    @Minty

    I don't think so.

    The loop has 4 iterations. GB has North and South towers, and each has 4 floors. Output has Floor & I - so I think the logic seems ok. We'll have to see what resolves the error condition.
    But the form remains the same? even for north and south?
    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

  5. #20
    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,742

  6. #21
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    With your suggestion, the first OutputTo executed normally as it has been. In the error handler, I recorded error activity in the IW noting the error and "current strErrMsg". The error occurred once again and then Access just seemed to "park".

    A couple of months ago, I had problems with OutputTo being "unavailable", only the issue pertained to reports. The solution turned out to be moving the code to a class module, open acHidden, OutputTo and then close. It might be a "shotgun approach", but I'll try that in the next hour or so.

    To Orange's comment, from another point in the UI the user can selectively create the pdf files one at a time without any errors, so it is only when I attempt to "rapid fire" all 8 floors that I hit the current OP.

  7. #22
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,818
    @Minty - the variable is probably global. I think GB likes to keep us in the dark a bit, just to see how sharp we can be.
    I would open it filtered or use OpenArgs from that code as you say. I can't decide which would be most scary - passing numbers to string variables or using a global this way. If they're not string variables, then the naming convention is misleading.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #23
    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,742
    I agree that we may not be aware of some details. Micron may be onto things with a filter or openargs...
    I'm not sure how he is getting the floor values for his individual pdf's.
    My simple mockup alters the where clause. Each output is quite small (32Kb). I get 4 north and 4 south, but I'm changing the input for the form.

    Code:
    Sub chkiter()
        Dim i As Integer
        For i = 0 To 3
            DoCmd.OpenForm "animal", acNormal, , "animalid =" & i
            DoCmd.OutputTo acOutputForm, "animal", acFormatPDF, "c:\users\jp\documents\North" & i & ".pdf"
            DoCmd.OpenForm "animal", acNormal, , "animalid =" & i + 4
            DoCmd.OutputTo acOutputForm, "animal", acFormatPDF, "c:\users\jp\documents\South" & i & ".pdf"
        Next i
        DoCmd.Close acForm, "animal"
    End Sub

  9. #24
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Wow! Talk about obscure!
    First, to Micron's comment. Yes, it would have removed question had I commented that strCurFloor was global. It was necessary because the normal use of the two forms have the floor numbers passed in OpenArgs. When the forms open only for purposes of pdf creation, I add 100 to the floor number and the Open code segment (below) takes care of distinguishing the two modes of operation.

    As for the data type, old habits die hard. I'm so used to other languages where conversions are automatic given the context of the statements. As you'll see in the final code, I'm trying to correct the error of my ways
    Code:
    If IsNull(Me.OpenArgs) Then
        strfloor = strCurFloor
    Else
        strfloor = Me.OpenArgs
    End If
    
    
    If strfloor > 100 Then
        strfloor = strfloor - 100
        bolPDF = True
        Me.Form.Visible = False
    End If
    So, what turned out to be thought as everything else, it was the "frmSouthTower" that needed the same code segment that had been included in the Open event of the "frmNorthTower", this discovery of course, makes me the dummy with this OP. (See code above)

    The successful code is as follows. (Note no need for the Pause)
    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
    
    
    On Error GoTo Err_Handler
    
    
    For I = 1 To 4
        strCurFloor = CStr(100 + I)
        strfloor = CStr(I)
        
        strErrMsg = "create pdf North floor layouts: "
        DoCmd.OutputTo acOutputForm, "frmNorthTower", acFormatPDF, "c:\Revel\RDS\FloorPDFs\North" & strfloor & ".pdf"
        DoCmd.Close acForm, "frmNorthTower"
        
        strErrMsg = "create pdf South floor layouts: "
        DoCmd.OutputTo acOutputForm, "frmSouthTower", acFormatPDF, "c:\Revel\RDS\FloorPDFs\South" & strfloor & ".pdf"
        DoCmd.Close acForm, "frmSouthTower"
    Next I
    
    
    strShell = "c:\Windows\Explorer.exe " & "c:\Revel\RDS\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

  10. #25
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,008
    Now the question might be, why not just FormTower and a method of selecting n,s,e or w ?
    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

  11. #26
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Fair question. For your viewing pleasure, I've included below reduced images of the two towers. Every distinct element you see in the image, other than the room border lines, is a detectable control. The difference between the two towers would make a single form an absolute nightmare to create plus tons of code to position and toggle visibility of the elements as one goes from one tower to the other, so I took the easy way out.
    Click image for larger version. 

Name:	000.jpg 
Views:	11 
Size:	86.4 KB 
ID:	46957 Click image for larger version. 

Name:	001.jpg 
Views:	11 
Size:	69.4 KB 
ID:	46958

  12. #27
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,008
    Very nice
    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 2 of 2 FirstFirst 12
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