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

    Subform Not Navigating Properly (First Time Only)

    I have a strange issue.



    My main form is bound to a single table. I wanted to be able to navigate records on the main form by picking a record from an unbound ListBox on the form. I've done this many times, and use the ListBox wizard to setup that ListBox.

    This time a ListBox doesn't suit my needs, because I want more control over the list records, such as different fonts for different columns, and some conditional formatting in the list fields. Therefore I created a subform bound to the same table. In the subform's On_Current event, I run a public Subroutine on the Parent form, sending it the record ID from the subform. This subroutine tells the Parent form to find that record.

    This is working perfectly, except for a strange quirk:

    When the forms all load, the first record of the subform is selected by default. The On_Current event fires properly (I have the following code in the On_Current event to verify):
    Code:
    Debug.Print "form_current, order=" & Me.OrderID
    The very first time I click on another subform record, nothing happens. The first record is still current, and no On_Current event fires (of course).
    The next time I click on another subform record (and every time after that), that record gets focus and the On_Current event fires properly.

    Maybe pertinent: If I close the main form and open the subform by itself, this doesn't happen. It only happens if the form is actually being used as a subform.

    Any idea what's not working here? Thanks...

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    First click is giving the focus to the subform?
    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

  3. #3
    Minty is online now VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    If you make the record selectors visible you will probably "See" which record is selected.
    I suspect it's not that the current event isn't firing, but that the main form isn't loaded fully, as sub form's load first.

    You may need to load the subform object in the main forms load event.
    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 ↓↓

  4. #4
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Quote Originally Posted by Minty View Post
    If you make the record selectors visible you will probably "See" which record is selected.
    I suspect it's not that the current event isn't firing, but that the main form isn't loaded fully, as sub form's load first.

    You may need to load the subform object in the main forms load event.
    Thanks Minty. Even without record selectors, I can see which subform record is selected, because I have conditional formatting so the current record is bold. And you are right, it's not that the event is not firing, but that the subform didn't have focus.

    Rather than loading the subform in the main form's load event, I tried setting focus to the subform record from the main form's load event. This seemed to solve the issue.

  5. #5
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Quote Originally Posted by Welshgasman View Post
    First click is giving the focus to the subform?
    Thanks, Welshgasman. You hit the nail on the head. In the main form's Load event (which occurs after the subform is loaded), I put a statement to set focus to the subform record and it started working properly. Thanks!

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

Similar Threads

  1. Replies: 2
    Last Post: 01-09-2019, 09:31 AM
  2. Replies: 18
    Last Post: 01-08-2019, 09:33 PM
  3. Replies: 18
    Last Post: 07-16-2017, 04:52 AM
  4. Replies: 1
    Last Post: 07-06-2017, 05:55 AM
  5. Navigating from Form to SubForm
    By Gryphen957 in forum Forms
    Replies: 1
    Last Post: 11-19-2010, 10:08 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