Results 1 to 3 of 3
  1. #1
    MatthewR is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2015
    Posts
    118

    Not Displaying Record Count Correctly / On Current Event Firing Multiple Times

    Hi, folks. I made a label (named "RecordNumber") in a subform that's supposed to display the Current Record Number and the Record Count.

    To do that, I put the following VBA code into the subform's On Current event:


    Code:
    Me.RecordNumber.Caption = "Case #  " & CurrentRecord & "  of  " & RecordsetClone.RecordCount
    When I open the subform on its own, it works just fine.

    But when I open the main form with the subform in it, the label only displays "Case # 1 of 1", even though there are multiple cases. If I click on the next record button, though, the label correctly says "Case # 2 of 2". So, the problem is only happening when it loads.

    I stepped through the code, and I found that, for some reason, when I load the main form, it fires the subform's On Current event 3 times. After it fires the first time, the label displays the correct caption: "Case # 1 of 2". But, after it fires the 2nd time, it incorrectly says "Case # 1 of 1". And the when it fires the 3rd time, it incorrectly says "Case # 1 of 1" again.

    So, perhaps the solution is making sure the On Current event fires just once. The question is, how do I that? Or perhaps there's another solution? Please help! Many thanks.

    Matt

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Are you aware that the RecordCount is not guaranteed accurate until after the Recordset has done a MoveLast?

  3. #3
    MatthewR is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2015
    Posts
    118
    Yeah, I know. But now that you mention it, I realized that I had it in the On Load event. I moved it to the On Current event, and now it works fine. Thanks for your help.

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

Similar Threads

  1. Replies: 4
    Last Post: 04-06-2016, 05:37 AM
  2. Replies: 14
    Last Post: 03-19-2013, 12:16 AM
  3. tab control - firing a page on-click event
    By Chuck55 in forum Programming
    Replies: 7
    Last Post: 05-01-2012, 09:57 AM
  4. Replies: 14
    Last Post: 02-23-2012, 06:32 PM
  5. Replies: 1
    Last Post: 07-12-2010, 12:00 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