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

    OnPage event doesn't seem to fire

    I have a report going directly to a pdf file:
    Code:
    DoCmd.OutputTo acOutputReport, rptName, acFormatPDF, PDFName
    The report in fact renders and is written to the pdf file "PDFName". The OnPage event code is as follows:
    Code:
    Option Compare Database
    Dim PgNo As Variant
    Dim strTemp As String
    Dim HdrPgAdj As Integer
    Dim I As Integer
    Dim intShift As Integer
    Dim intShiftAMt As Integer
    
    
    <snip>
    
    
    Private Sub Report_Open(Cancel As Integer)
    Dim strCoverName As String
    intShiftAMt = 780       '0.5417 (design position) x 1440
    
    
    PgNo = 0
    intShift = 0            '1st 3 pages there's no shifting
    
    
    <snip>
    
    
    End Sub
    
    Private Sub Report_Page()
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '  Starting with the 4th page and alternately thereafter, we shift the page controls
    '  left;restore;left;restore;............ etc.  Given page binding on the left edge
    '  of the book, the duplex (both sides") printing will better position the back side.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    
    
    If pgn < 3 Then
        pgn = pgn + 1
        Exit Sub
    End If
    
    
    For I = 1 To 10
        Me.Controls("lblLn" & I).left = Me.Controls("lblLn" & I).left + intShift
    Next I
    
    
    Me.Image0.left = Me.Image0.left + intShift
    Me.ImageBox.left = Me.ImageBox.left + intShift
    
    
    If intShift = 0 Then         '1st nominal design position?
        intShift = -intShiftAMt  'Next page we shift to the left
    Else
        If intShift < 0 Then
            intShift = intShiftAMt
        Else
            intShift = -intShiftAMt
        End If
    End If
    
    
    End Sub
    The report is 2 columns. Below is a design view screenshot of the Detail section.


    Click image for larger version. 

Name:	000.jpg 
Views:	19 
Size:	69.0 KB 
ID:	48692

    EDIT: pgn is a typo, should be "Pgno". code proceeds to where shift code should run but nothing seems to happen and none of the error traps fire.

    EDIT2: I can't even get a debug a Breakpoint to fire, though simple Msgbox statements to fire announcing I'm in the code are working.
    Click image for larger version. 

Name:	001.jpg 
Views:	19 
Size:	138.2 KB 
ID:	48694

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    You could copy the report, switch to open normal (i.e. just print out) or try print preview and in the event just put a message box.
    I suspect the event doesn't fire for report "output as". Not all report events fire for all views. This one I don't know, but the documentation says
    The Page event occurs after Microsoft Access formats a page of a report for printing, but before the page is printed.
    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
    Been away most of the day and just now took a fresh look.
    Click image for larger version. 

Name:	002.jpg 
Views:	17 
Size:	30.7 KB 
ID:	48695
    With the way in which the controls are referenced, the Compiler had no way of telling my I'm a dummy. Those are text box controls, NOT labels. Should be Me.Controls("tbLn" & I).Left.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    You continue to surprise me with things I've never seen before and I often don't understand how it is that you don't raise errors. Or is it that you're just not reporting them?
    By that I mean Left is a function (thus a reserved word) and the way I see that used I can only imagine it is your own function/variable/constant - something - especially since the "L" is lower case. I don't know how you get away with such things, unless maybe sometimes you've disabled error handling.
    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
    Why runtime didn't raise an error when it failed to find a control entitled "lblLn1" is anyone's guess. Why the editor didn't capitalize the control's positional property "left" is also anyone's guess. It sure would have gotten my attention. If you look at my EDITs to #1, you'll see where the screenshot included more of the code that was previously <snipped> which included the On Error GoTO. Given all of what I coded that included referencing a non-existing label control without raising any errors surprised me more than it did you.

    Below is the entire sub without anything snipped. (Only change is the correction to the name(s) of the controls in the 1 to 10 loop, and notice the editor still hasn't capitalized "left".)
    Code:
    Private Sub Report_Page()
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '  Starting with the 4th page and alternately thereafter, we shift the page controls
    '  left;restore;left;restore;............ etc.  Given page binding on the left edge
    '  of the book, the duplex (both sides") printing will better position the back side.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    On Error GoTo Err_Handler
    
    
    If PgNo < 2 Then
        PgNo = PgNo + 1
        Exit Sub
    End If
    
    
    Me.Image0.left = Me.Image0.left + intShift
    Me.ImageBox.left = Me.ImageBox.left + intShift
    Me.ReportTitle.left = Me.ReportTitle.left + intShift
    
    
    For I = 1 To 10
        Me.Controls("tbLn" & I).left = Me.Controls("tbLn" & I).left + intShift
    Next I
    
    
    If intShift = 0 Then         '1st nominal design position?
        intShift = -intShiftAMt  'Next page we shift to the left
    Else
        If intShift < 0 Then
            intShift = intShiftAMt
        Else
            intShift = -intShiftAMt
        End If
    End If
       
    Exit_Handler:
        Exit Sub
    
    
    Err_Handler:
        MsgBox "Error " & Err.Number & " - " & Err.Description & vbNewLine & _
               "OnPage attempting to shift controls."
        Resume Exit_Handler
    
    
    
    
    
    
     
    
    
    End Sub

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    Quote Originally Posted by Micron View Post
    You continue to surprise me with things I've never seen before and I often don't understand how it is that you don't raise errors. Or is it that you're just not reporting them?
    By that I mean Left is a function (thus a reserved word) and the way I see that used I can only imagine it is your own function/variable/constant - something - especially since the "L" is lower case. I don't know how you get away with such things, unless maybe sometimes you've disabled error handling.
    Left is a function as well as a property of controls. It's on the Property Sheet Format tab.

    I have encountered instances where VBA will not capitalize and never solved the mystery. And today the mystery was compounded because VBA capitalized when it should be lower case as shown in the Intellisense popup!
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    I use it all, "Left", "Right" and "Mid" to isolate sub-strings, as well as reference to a control's positional properties. I don't get particularly excited when the editor doesn't capitalize, as it's not very smart to begin with. However, like Micron, I am bothered as to why runtime didn't raise an error when it encountered a non-existing control. I have to admit that these days that age has taken its toll on awareness, but not an error of the current magnitude.

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I've got to stop having these brain farts. Of course, left is a property too.
    OK, I'll say this for the other 2 points: I don't think intellisense works after you've invoked the controls collection, as in Me.Controls("txtCustomer"). The only times I can remember that a property wasn't capitalized when using .Controls syntax is
    a) when it didn't exist (e.g. spelled wrong) or
    b) it was written in a sub event that was started from the vbe rather than the property sheet.

    In the latter case I have done so and the result was a disconnect between the control event and the sub so I'd say you cannot expect capitalization to occur. Not sure about intellisense in that case. If you misspell control name in that reference, compile will not catch it either, so perhaps the lack of capital is due to the control (the label in this case) not existing. Just guessing there because I don't know if there are labels by those names.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    There are no labels named ("lblLn" & I) as you see in the loop 1 to 10. Runtime should have barfed when it encountered the name of an non-existing control.

    EDIT: BTW, I do have more faith in Runtime than perhaps this post suggests, so I have to assume the bottom line is that I somehow managed to miss a raised error. And, you've all been too kind to point out something to the effect that the "Old Geezer" is really loosing it

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    Micron, I have initiated event code for a control from the VBE. As long as I get the procedure declaration line correct, it will connect to the event property - [Event Procedure] appears in the property. Intellisense works as normal. True, no intellisense tips after invoking controls collection reference regardless.

    Bill, if you ran code and did not get "could not find" error, then there must be controls on that form with the lblLn prefix or you have an error handler trapping the error.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    So have I, but I mentioned it because in testing the .Controls() syntax it failed exactly as I described. Only when I went to the property sheet and "connected" it did the event code run. Doesn't happen often but when it does, that is the first thing I go to.
    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
    there must be controls on that form with the lblLn prefix or you have an error handler trapping the error.
    Neither is the case.

  13. #13
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    So Micron, when you wrote the event code it did not automatically insert [Event Procedure] in the property? That would be odd.

    And Bill, the mystery deepens because I get error.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    And Bill, the mystery deepens because I get error.
    Well, June7, it's like I alluded to earlier, sometimes "Old Geezers" don't always see things as they are, so I don't think there's any further need to dwell

  15. #15
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    So Micron, when you wrote the event code it did not automatically insert [Event Procedure] in the property?
    Sorry, I cannot recall if it was showing "Event Procedure" or not. FWIW, this is not the first time it's ever happened to me and I have no idea why. Perhaps if one does something in the vbe e.g. change code which is not then compiled, or perhaps I raised an error then simply stopped and selected an object then an event for it and either of those things causes it. I've been aware of it for years; it just doesn't happen often. As noted, if I create from the vbe and the event doesn't fire (I know because of break point) then first thing I do is select the event from the ps. When I do that, it takes me to the code I've already written. Then it works.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Combo, "NotInList" event doesn't fire
    By GraeagleBill in forum Programming
    Replies: 11
    Last Post: 06-14-2020, 05:50 PM
  2. Form_Current Doesn't Fire on First Record
    By RMittelman in forum Programming
    Replies: 6
    Last Post: 09-24-2019, 02:23 PM
  3. Form_Current doesn't fire when moving to first record.
    By MatthewGrace in forum Programming
    Replies: 14
    Last Post: 01-09-2019, 04:09 PM
  4. Replies: 2
    Last Post: 04-17-2017, 11:26 PM
  5. Replies: 5
    Last Post: 12-03-2013, 01:25 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