Results 1 to 5 of 5
  1. #1
    wtucker is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Jun 2017
    Posts
    50

    BeforeInsert Event Not Working

    Hey everyone,



    For aesthetic purposes I have custom navigation buttons on a form. The record count should update BeforeInsert, On Current, and On Load. The code is simple, but I can't seem to get the record count to update until after an update. I'll go to my form, enter a new record (it will say 6 of 5), and only once I go to a previous record does it count the sixth record (5 of 6). Am I missing something?

    Code:
    Private Sub Form_BeforeInsert(Cancel As Integer)
    Set rs = Me.RecordsetClone
    
    rs.MoveLast
        Me.txtRecCount = Me.CurrentRecord & " of " & rs.RecordCount
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,515
    From MS:

    The BeforeInsert event occurs when the user types the first character in a new record, but before the record is actually created.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    wtucker is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Jun 2017
    Posts
    50
    Quote Originally Posted by pbaldy View Post
    From MS:

    The BeforeInsert event occurs when the user types the first character in a new record, but before the record is actually created.
    I see what you're saying. It does kick in, but the record still doesn't exist, so the count is the same. Hmmmm...

    What function can I use to make it work the way the normal navigation bar works, to update the "# of #" to reflect the "new" record, even if it hasn't been created yet?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,515
    Completely untested, but in the before insert event couldn't you add 1 to whatever your test returned? And then in an update event set it to actual?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Code:
    Private Sub Form_Load()
      DoCmd.GoToRecord , , acLast
      DoCmd.GoToRecord , , acFirst
    End Sub
    
    Private Sub Form_Current()
     If Not Me.NewRecord Then
      Me.txtRecCount = "Record  " & CurrentRecord & "  Of  " & RecordsetClone.RecordCount & "  Records"
     Else
      Me.txtRecCount = "Record  " & CurrentRecord & "  Of  " & RecordsetClone.RecordCount + 1 & "  Records"
     End If
    End Sub

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. On Delete Event Not Working
    By pdowg881 in forum Access
    Replies: 2
    Last Post: 05-21-2015, 11:18 AM
  2. PLEASE HELP! Dlookup event not working....
    By emailloni in forum Forms
    Replies: 11
    Last Post: 01-10-2013, 12:43 PM
  3. NotInlist Event not working properly
    By thanosgr in forum Programming
    Replies: 2
    Last Post: 06-14-2012, 01:46 PM
  4. Beforeinsert syntax
    By ramindya in forum Access
    Replies: 1
    Last Post: 02-12-2012, 06:58 PM
  5. Not In List event not working
    By Bruce in forum Forms
    Replies: 1
    Last Post: 03-12-2010, 02:24 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