Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    JonathanT is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2011
    Posts
    80

    Updating a form

    I have Form A which is based on a table and Form B which is based on a query. Currently I have code written so when I change a certain field value in Form A it updates the records in Form B. I would like to embed Form B in Form A rather than have two forms open. When I embed Form B in Form A the code to update Form B doesn't run. The error is Microsoft Access can't find the referenced form 'Form A'.



    Any ideas would be appreciated

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    2,290
    Well showing your code would be a start?

    If B is embeded in A, then A is the parent and you could just use
    Me.BControl = Me.Parent.AControl

    However more than one record, implies and Update query perhaps?
    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
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    10,029
    see this link about how to reference forms and controls on other forms
    http://access.mvps.org/Access/forms/frm0031.htm

  4. #4
    JonathanT is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2011
    Posts
    80
    The code I'm using to update Form B is "Forms!Form B.Requery" . The code is in the AfterUpdate property of a combobox field on Form A. It works as expected when Form A and B are open but not when Form B is embedded in Form A

  5. #5
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    10,029
    you shouldn't need any code, just set the subform control linkchild/master properties - linkmaster will be the name of your 'certain field' and linkchild the related field in formB.

    incidentally, when providing code, please make sure it is accurate as

    "Forms!Form B.Requery"

    won't work. Best to copy/paste

    And do read the link I provided in post #3.

  6. #6
    JonathanT is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2011
    Posts
    80
    Thanks all. I'll review the suggestions

  7. #7
    JonathanT is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2011
    Posts
    80
    I'm going to restate my question. I may have been too vague. I have FormA which is based on the table 'Spending'.
    FormB is based on a query 'Detailqry' and displays 3 fields from the query. FormA has code in the 'AfterUpdate' property of several combo boxes that requeries the 'Detailqry' for FormB when a combobox on FormA is updated.
    The code is:
    Private Sub MonthFilter_AfterUpdate()
    Forms!FormB.Requery
    End Sub
    (MonthFilter is the name of a combobox on FormA)

    The two forms work as intended when both are open. However when I embed FormB into FormA and update a combobox on FormA , I get the message "Microsoft Access can not find the referenced form "FormB".

    Any ideas?

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    10,750
    Error is because the syntax is wrong, which is based on the hierarchy of related objects. Use the syntax of one of the following:

    Code:
    Forms("MainFormName").Controls("subformControlName").Form 
    
    Forms("MainFormName").Controls("subformControlName").Form
    Either of those should get you to the subform level. After that, you either drill down further to form controls or just continue with form properties or methods. NOTE: subformControlName is the name of the control that contains the subform, which may or may not be the same name as the subform. Access has the tendency to name this the same, as well as name controls the same as the field they're bound to. Personally, I don't let that stand. Also, use your object names, not (e.g.) MainFormName.
    Last edited by Micron; 06-20-2022 at 07:29 PM. Reason: corrected references
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    2,290
    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

  10. #10
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    10,029
    That link already provided in post #3

  11. #11
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    2,290
    Perhaps the O/P might refer to it now as it has been repeated?
    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

  12. #12
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    10,029
    Donít think the OP is reading anything provided, or failing to understand the basics

  13. #13
    JonathanT is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2011
    Posts
    80
    I've read everything more than once. As suggested I'm missing something basic to this process. I'm going to try to create a form and subform from scratch and see if the subform will act as intended. My current forms may have some code or relationship configuration that is preventing the desired result.

  14. #14
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    10,750
    If you get stuck consider posting a copy of the db, or one that at least contains what's needed to replicate the issue. If your db is split, either post the back end (be) as well or just keep the form(s) and needed tables in a new version and post that. Usually you must zip your file in order to condense it enough to post here. If your data is confidential, consider https://www.accessforums.net/showthread.php?t=77482

    Soon I will be on the road (then on the ocean) so my time here will be limited for about 2 weeks, thus will have to bow out after today.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  15. #15
    JonathanT is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2011
    Posts
    80
    Thanks Micron, Your post on the 20th was the answer. When I embedded the form I needed to change the name under the Property Sheet 'Selection type:subform/subreport' to a different name than what Access had chosen. I also changed the .Form to .Requery and now all functions work in the embedded subform

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

Similar Threads

  1. Replies: 1
    Last Post: 08-25-2021, 11:18 AM
  2. Replies: 9
    Last Post: 05-24-2021, 06:29 AM
  3. Replies: 11
    Last Post: 05-16-2019, 12:53 PM
  4. Updating form after updating and closing a popup window
    By Historypaul in forum Programming
    Replies: 2
    Last Post: 04-21-2014, 02:13 AM
  5. Replies: 5
    Last Post: 06-03-2013, 09:34 AM

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