Results 1 to 5 of 5
  1. #1
    GeorgeJ is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    67

    Want subform updated

    This question describes a kind of a complicated situation but it would be really helpful if I could do what I am trying to do. I have a form (call it BigForm) which has two subforms, call them Subf1 and Subf2. Subf1 is a tabular form with record selectors. I have a routine inside the
    sub Form_Current


    property of form Subf1. This routine executes every time the user changes the record which is selected in Subf1.

    The routine takes one of the fields of the selected record in subf1 and puts it into a global string variable. Then another routine which is called from sub Form_current uses this string to create records in a table. The info in this table depends on the info in the global string variable set with the value obtained from the selected record in subf1.

    The second subform (subf2) gets its data from this table. The thing is, the second subform is not ubpdated when this happens. If I close BigForm and open Subf2 directly I see that it now shows the appropriate data in the table, corresponding to which record was selected in Subf1 inside BigForm. But this isn’t really helpful. What I want is for the info shown in Subf2 to be updated when the user clicks on a different record in Subf1. In other words, when the table from which Subf2 gets its data is changed, I would like the information displayed in Subf2 on Bigform to reflect this fact. Is there some sort of a refresh command?

    Any suggestions.

  2. #2
    A S MANN is offline Advanced System Analyst
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    India
    Posts
    161
    In the after update event of SubF1 use

    DoCmd.Requery "table"
    DoCmd.RunCommand acCmdRefresh

  3. #3
    GeorgeJ is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    67
    Thank you for your response.

    The recordsource for Subf2 is the table "Table1". When I open BigForm, which has as subforms both Subf1 and Subf2, I see the correct info in Subf2.

    When I put the following code in the Form_Current subprogram in the code file of Subf1

    Docmd.Requery "Table1"

    DoCmd.RunCommand acCmdRefresh

    and then I select another record in subf1 I get the following error message


    "Runtime error 2046. The command or action Requery isn't available now"

    I get the same message if the code references subf2 rather than Table1, e. g. Docmd.Requery "Subf2"

    Any suggestions?

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I am having trouble understanding the form relationships.

    First though, you cannot "requery" a table. A table is just a container that holds (stores) data. You can requery forms/subforms, combo boxes and list boxes because they have a record source.

    So you have a main form, "BigForm", with two subforms - "Subf1" and "Subf2".
    Is "BigForm" unbound? Why are "Subf1" and "Subf2" in "BigForm"?


    It sounds like "Subf2" is a subform of "Subf1".
    Do they have a common linking field? (Link Master Field and Link Child Field/)

  5. #5
    GeorgeJ is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    67
    Well, I finally figure out the answer, which I am posting here in case anyone will find it helpful

    Condition:

    A form BigForm contains 2 subforms, Subf1 and Subf2. (Subf2 is directly on Bigform, it is not a subform of Subf1). Both of these subforms are tabular. Their record-sources are Table1 and Table2 respectively. One of the fields of Table1 is InfoField. There is a public routine MakeTable2 which puts data into Table2. The data which MakeTable2 puts into Table2 is dependent on a global variable Infostring$. It is desired that as the user selects different records in Subf1, the global InfoString$ is set to Subf1!Infofield and then Table2 is updated by running MakeTable2, and then the display in Subf2 reflects this update.

    Here is how to accomplish this:

    In the code file of Subf1, Put the following code

    Sub Form_Current()
    Infostring$ = me!InfoField
    MakeTable2
    me.parent.Subf2.Requery
    end sub


    (A problem that vexed me for a long time was that I tried to access Forms!Subf2 and kept getting an error message saying that it couldn't be found. I have discovered that sometimes you can access an open form this way and other times you can't. It may be that you can access a parent form this way but not a subform.)

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

Similar Threads

  1. Replies: 6
    Last Post: 07-24-2014, 08:18 AM
  2. Replies: 1
    Last Post: 12-11-2012, 02:57 PM
  3. SellRate should get updated
    By jalal in forum Access
    Replies: 6
    Last Post: 08-10-2012, 07:36 AM
  4. autofill box is always updated as 0.
    By mejia.j88 in forum Forms
    Replies: 7
    Last Post: 11-08-2011, 07:15 PM
  5. records with different updated report_date
    By lizzywu in forum Reports
    Replies: 3
    Last Post: 10-27-2011, 01:28 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