Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160

    How to link main form with Sub Form


    Hi,
    I want to add a subform after the main form has been created - not create it together with the main form.
    I need help linking the form to the subform so that the subform is updated when the main form moves to another record, at the moment all fields on the main form are updated when a new record is selected, but the subform continues to display the results of the initial query.
    How can I get the subform to be updated together with the main form?
    Thanks for any help.
    David

  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,521
    The subform control on the main form has master/child link properties. Those would refer to the field(s) that join them. If you add a subform with the wizard, it will ask about them.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Hi pbaldy, thanks for your reply.
    I've filled those Data Property fields, but there's no change on the subform - still displays only initial query results.
    Any other ideas?

    Thanks
    David

  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,521
    Can you attach the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Hi Paul, When I clicked the 3 horizontal dots for Link Child Fields I get the message "can't link unbound forms" even though the main form has a record source and the subform has a source object - are these bound forms?
    On the subform in "Link Master Fields" I entered the textbox name that contains the main form's link field and now the subform is updated together with the main form.
    The link master field name in the table is "Species ID", is the space a problem?

  6. #6
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Excuse my ignorance - how do I "attach the db"?

    My accdb file is 10 Mg

  7. #7
    Join Date
    Apr 2017
    Posts
    1,679
    Where you did place your subform? Into Main form, or into some other form both your "main" and subform are inserted into? When the last, and you want to keep this design, then you must have unbound control(s) in this 3rd form, which is/are updated by OnCurrent event of your "main" form, and you have to link your subform to this/those unbound control(s) manually (Access will protest, that it is not possible, but don't trust him about this).

  8. #8
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    My form and subform are now in sync - when I select a record on the main form the subform is updated. Problem now is clicking anywhere on the subform or trying any form action (save, close ect.) on the main form I get "Index or primary key cannot contain a null value".

    Here's the Main Form Property Sheet:


    Attachment 30875Attachment 30876Attachment 30877Attachment 30878


    Here's the subform data properties:

    Attachment 30879

  9. #9
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Main Form Property Sheet:


    Click image for larger version. 

Name:	ComplaintsFrm-properties1.JPG 
Views:	18 
Size:	91.0 KB 
ID:	30880Click image for larger version. 

Name:	ComplaintsFrm-properties2.JPG 
Views:	18 
Size:	85.4 KB 
ID:	30881Click image for larger version. 

Name:	ComplaintsFrm-properties3.JPG 
Views:	18 
Size:	77.9 KB 
ID:	30882Click image for larger version. 

Name:	ComplaintsFrm-properties4.JPG 
Views:	19 
Size:	86.3 KB 
ID:	30883




    And here's the subform Data Property sheet:


    Click image for larger version. 

Name:	SubFormDataProperties.JPG 
Views:	19 
Size:	36.6 KB 
ID:	30884


    At this point I don't want to change any data it should all be read only.

    Thanks
    David
    Last edited by mdavid; 10-20-2017 at 02:58 AM. Reason: added more info

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    If you compact/repair the db and then zip, it may be small enough to attach. If not you can email it to me.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Hi, I emailed my db as requested, and now received a reply saying "Please post your reply on the forum, thanks" pointing me back here .
    Did you receive my db? What do I need to do? Where can I see Paul's reply?

  12. #12
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    For anyone that's interested, I solved the error message: "Index or primary key cannot contain a Null value" with the following code:

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    Me.Undo
    End Sub
    This form is read only.

    Now the other major problem is that scrollbars and record navigation doesn't work on the subforms.

    Really like to hear from anyone that knows how to fix this.

    Thanks
    David

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No, I didn't get it. Sounds like you sent it to the forum. Try

    pbaldy
    gmail
    com

    That code will prevent you from making any changes to the data.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    OK I've sent it to you.
    Also scrollbars, and navigation buttons (next, last etc) on the subforms are not working - but I can scroll vertically with the mouse wheel.

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Got it, but I'm away from a computer for a day or two.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. subform will not link to main form
    By wolfm in forum Forms
    Replies: 2
    Last Post: 09-28-2017, 09:49 AM
  2. Link main form to subform
    By OllieCat in forum Forms
    Replies: 3
    Last Post: 05-12-2017, 06:01 AM
  3. Replies: 3
    Last Post: 01-05-2012, 07:15 PM
  4. Link main form with subform
    By lizzywu in forum Forms
    Replies: 1
    Last Post: 11-18-2011, 03:22 PM
  5. Replies: 3
    Last Post: 11-16-2011, 01:56 PM

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