Results 1 to 7 of 7
  1. #1
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211

    Form_Current Doesn't Fire on First Record

    I have a ListBox which contains the ID and name of my members from the Members table. I used the wizard to build the macro which is executed after the list box is updated, to find the appropriate record in the form when I click a list box item.



    So when I open the form, I have code to go to the very first record, so everything works fine. The Form_Current event fires as expected.

    When I click on any item in the list box, the macro causes a search, which finds the record. Form_Current fires.
    But this only happens when I click on any item except the first item in the list box. If I click back on the first item, Form_Current does NOT fire.

    I tried removing the generated macro and replacing it with DoCmd.SearchForRecord in code, and the same thing happens.
    If I navigate the records using the record selector at the bottom of the form, everything works fine, including for the first record.
    Only when using the list box does the Form_Current not fire for the first record only. Strangely enough, the record does load on the form properly.

    I tried adding code in the list box AfterUpdate event to specifically fire form_current event and that works. But a Debug.Print statement in Form_Current shows me that it's getting fired only once when I specifically call it in ListBox_AfterUpdate (for the first record), but twice for any other record.

    So does anybody know why Form_Current doesn't fire when I search for the record?

    BTW, my code in ListBox_AfterUpdate is this:
    Code:
    Private Sub lstMembers_AfterUpdate()
    
        DoCmd.SearchForRecord , , acFirst, "NAID=" & Me.lstMembers
        Form_Current
    
    
    End Sub
    Thanks...

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I'm a bit confused. What kind of form is this? When it opens, there are no records showing?
    Only when using the list box does the Form_Current not fire for the first record only. Strangely enough, the record does load on the form properly.
    This sounds like the first listbox item is related to the first visible record, which means the Current event is not going to run again just because you click on the list item. You would have to requery the form just to reload the record that's already loaded to make the current event run.

    The current event has already run when the form is opened and a record is visible. If I'm understanding what you're saying, why would you want the form current event to run for a record that is already current? If I've misunderstood, then my other suggestion would be to use the GoToRecord method as opposed to SearchForRecord.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    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.

  4. #4
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    BTW - If you do get it to work, why call the current event? When it goes to the record, the current event would run automatically. Calling it in the next line will only make it run again

  5. #5
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Thanks June7! That totally worked.

  6. #6
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Hi Micron,

    To answer your questions:

    The form is working perfectly. When I open it, the first record properly displays. When I move to another record and back using the record selectors the Form_Current event fires properly on any record I move to.

    When I add a ListBox and let the wizard generate the macro to find the record based on the ID I chose in the list box that also works perfectly, but not when navigating back to first record. It works for every other record. On first record, Form_Current does NOT fire. This is regardless of whether I use the wizard-generated macro or the code shown above.

    I only put that Form_Current call in the ListBox_AfterUpdate as a test. You're correct, I don't want it to normally fire twice.

    Please see the reply from June7, which shows this is definitely a bug in Access. Using RecordsetClone and Bookmarks instead of SearchForRecord, it works as expected.

    As for why I need this at all? I'm wanting to log all changes made by the user. I have a Recordset object declared at Form-level. In Form_Current, I populate that with the current record. In Form_AfterUpdate I send that recordset and also the current record (after being updated) to my logging routine, which examines the fields and logs any changes to a log table.

    Thanks for the quick reply!

  7. #7
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    IIRC, in that link it was also suggested to use gotorecord rather than findrecord but can't recall if anyone reported that it worked. Would be simpler than rs and bookmarks if it did. I did play with a bound form and a listbox using your code and it seemed to work for me.

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

Similar Threads

  1. 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
  2. Replies: 11
    Last Post: 06-02-2018, 02:48 PM
  3. Replies: 2
    Last Post: 04-17-2017, 11:26 PM
  4. Replies: 5
    Last Post: 12-03-2013, 01:25 PM
  5. Trying to fire event on record change
    By danielhowden in forum Forms
    Replies: 3
    Last Post: 05-13-2011, 06:30 AM

Tags for this Thread

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