Results 1 to 5 of 5
  1. #1
    keviny04 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Apr 2015
    Posts
    128

    Form with two subforms = SLOW PERFORMANCE

    I made a test database to illustrate my problem:
    Views: 9 Size: 70.7 KB">subform tests.zip


    I have two tables, Table1 and Table2, that have a one-to-many relationship. I made a form named "Main Form 1" which sets up the two tables as main form and subform. Everything works as it should. Note that the child records on the subform show up almost instantaneously whenever I move to a different record on the main form.

    Click image for larger version. 

Name:	mainform1.jpg 
Views:	25 
Size:	43.9 KB 
ID:	20526


    But then I made a "Main Form 2" that sets up the two tables as two SUBFORMS:

    Click image for larger version. 

Name:	mainform2.jpg 
Views:	26 
Size:	72.4 KB 
ID:	20525

    The form is set up so that when I click on a record on Table1 subform, the child records of the Table2 subform appears. This is done by setting the link master & child fields in Table2 subform's property sheet.

    My problem is that the child records take HALF A SECOND (or more) to appear. I click on a record on Table1 subform, child records on Table2 subform appear half a second later. Click on another row on Table1 subform, another half second wait.

    Anyone know why there is such a delay and is there any way to eliminate or minimize it? Note that it doesn't matter how many child records there are to show. Even if there is only one child record to show, the delay still occurs.

    ---------

    My workaround currently is NOT to use the link master & child fields in Table2 subform's properties. I set the link fields to blanks. Then I go to Table1 subform's OnCurrent event and CHANGE Table2 subform's RecordSource directly:

    Code:
    Private Sub Form_Current()
        
        ' Ignore error caused by "Table2 subform" not being loaded
        On Error Resume Next
        
        ' Change record source of "Table2 subform" directly
        Forms![Main Form 3]![Table2 subform].Form.RecordSource = "SELECT * FROM Table2 WHERE ID=" & Me!ID
    
    End Sub
    And the result is in "Main Form 3" of my database. The child records appear INSTANTLY every time I select a record in Table1 subform.

    I'm beginning to implement this workaround in several of my projects, whenever performance becomes an important issue.

    But I still would like to know why such a performance hit occurs only in a subform-subform setup, but NOT in a mainform-subform setup. Don't the two setups use the same kind of link master & child fields?

  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,841
    your workaround is a fairly standard solution - but you might be even quicker if you used

    Code:
    Parent.[Table2 subform].Form.RecordSource = "SELECT * FROM Table2 WHERE ID=" & Me!ID
    Why is the linkchild/master slower? probably because you are bringing through the entire dataset and effectively filtering, plus having to have the ID field in the main form react to the oncurrent event - so more steps to go through. Suggest try this as an alternative (in table1 current event) and compare with the linkchild/master times

    Code:
    with Parent.[Table2 subform].Form
     .Filter="ID=" & Me!ID
     .filteron=true
    end with

  3. #3
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    link master & child fields in Table2 sub form is not correct; it must be unbound in your design

    if table 1 was a single form (sub form) and table 2 was inset into it - then the master/child linking would be correct

    your record source approach is correct; or you could source table 2 on a query that refers to criteria of table 1 - and requery table2 upon select of table 1

  4. #4
    keviny04 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Apr 2015
    Posts
    128
    Quote Originally Posted by Ajax View Post
    Why is the linkchild/master slower? probably because you are bringing through the entire dataset and effectively filtering,
    But then why does the slowdown NOT occur in a mainform-subform setup (See my "Main Form 1")? The subform there also brings through the entire dataset with filtering, just like in the subform-subform setup.

    Quote Originally Posted by Ajax View Post
    plus having to have the ID field in the main form react to the oncurrent event - so more steps to go through. Suggest try this as an alternative (in table1 current event) and compare with the linkchild/master times

    Code:
    with Parent.[Table2 subform].Form
     .Filter="ID=" & Me!ID
     .filteron=true
    end with
    Your code also yields pretty fast result, but that is not really in question. What is in question is that when there is NO OnCurrent event, no code, just the subform's built-in properties for the link master & child fields being used, then there is a slowdown. And it only occurrs in subform-subform, not mainform-subform. THAT is the mystery to me.

  5. #5
    keviny04 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Apr 2015
    Posts
    128
    Quote Originally Posted by NTC View Post
    link master & child fields in Table2 sub form is not correct; it must be unbound in your design

    if table 1 was a single form (sub form) and table 2 was inset into it - then the master/child linking would be correct
    The link master field for Table2 subform is the invisible textbox named "ID" near the top of "Main Form 2", with control source =[Table1 subform].[Form]![ID] . It carries over the "ID" field from Table1 subform, so it can be used for the link master field for Table2 subform. This is how it is usually done when you need to link multiple subforms on a form.

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

Similar Threads

  1. Replies: 11
    Last Post: 10-22-2014, 07:56 AM
  2. Replies: 0
    Last Post: 08-18-2014, 09:11 AM
  3. Slow Form
    By imorgan22 in forum Forms
    Replies: 5
    Last Post: 09-04-2013, 06:22 PM
  4. Replies: 3
    Last Post: 10-18-2011, 03:08 PM
  5. slow performance with multiple users
    By netgrim in forum Access
    Replies: 4
    Last Post: 05-16-2010, 05:41 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