Results 1 to 7 of 7
  1. #1
    faythe1215 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jul 2014
    Posts
    52

    Refreshing Form and Subform


    Okay, I have a form, a subform which gets its information from a table. I have a button that adds information to the table then should refresh or requery the form and subform to display that information - but it doesn't. It doesn't seem to see the new information at all.

    Any tips?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    If you add info the the main form, you don't have to refresh.
    that could change your place.

    if you are on record 2, then add record 33, and you want to see rec 33, then you must navigate to it.(filter)
    IF you know the record ID.

    Code:
    me.filter= "[id]=" & txtFind
    me.filterOn=true
    if you add data to the subForm,then you can refresh.

  3. #3
    faythe1215 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jul 2014
    Posts
    52
    Hmm, not quite. I realize now my original post isn't terribly clear.

    I have a main form. [ID]
    I have a subform - this subform will have many records on it all of which will relate back to the main form. So multiple records will share the same value for [MainForm_ID] which is how the form pulls the records. My form allows me to look at everything on a table (see below) and determine which ones will get assigned the MainForm_ID to match the current MainForm record.
    I have a table - this table has a list of items. I can, form my current form, add a new item to this table.

    When I have added a new item to my table, I need to be able to see the item listed in a combo box on my subfrm - this is where my refresh/requery I would think would need to happen. But I can't seem to get it to work.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Hmm??

    Form and subform are usually used to deal with tables that are related in a 1 to Many relationship.
    eg: 1 Building may have many Rooms. 1 Person may have Many Hobbies

    tblBldg-->BldgContainsRoom<--tblRooms

    In the form/subform construct: Building is the data shown on the (main) Form and the Rooms in that Building(BldgContainsRoom) are shown in the subform. On the form you have a subform control to which you assign a form (your subform). The subform control has properties which allow you to identify the field in the main form's data source (recordsource) that relates to data in (recordsource of) the subform. These are Link Master Fields, and Link Child Fields.

    If you want to add a new Bldg, you would have some mechanism (form) to add a newBldg.
    If you want to add a new Room, you have to identify the Bldg before you can add the Room (to that Bldg).

    In the example of Person and Hobbies, you could have a form with a list of Persons. And an unbound combo with a list of Hobbies, and a subform with PersonHasHobby as the recordsource. You select a Person, then select a Hobby, then click a button, or, in the afterUpdate event of the combo, you have code to add a record to the PersonHasHobby with the PersonID and the RoomId. When you do a subform Requery, this latest record should now be visible in the subform.

  5. #5
    faythe1215 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jul 2014
    Posts
    52
    Quote Originally Posted by orange View Post
    Hmm??

    In the example of Person and Hobbies, you could have a form with a list of Persons. And an unbound combo with a list of Hobbies, and a subform with PersonHasHobby as the recordsource. You select a Person, then select a Hobby, then click a button, or, in the afterUpdate event of the combo, you have code to add a record to the PersonHasHobby with the PersonID and the RoomId. When you do a subform Requery, this latest record should now be visible in the subform.
    Yes! That's what I have going on. So in your example, my main form has me entering a person's name and address, then my subform will have me adding one or more hobbies to each person (using a combo box with a preset list of hobbies). If I click on a combo box and I don't find the hobby listed there, I have a button that opens the Hobby form and allows me to enter a new hobby. My code has me closing the Hobby form and refreshing or requerying the subform to reflect the new hobby added. But it doesn't. I thought that having a button that refreshes or requeries would be a workaround, but that doesn't work either.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Where exactly is the combobox with Hobbies ( I think I'd have it on the main form and a combo that gets its data (rowsource) from table Hobby)

    If you consider the Person on the mainform and you select a hobby for that person, I'd think some sql to create a record in PersonHasHobbies using the PersonId and the HobbyID would work, then requery the subform (based on PersonHasHobby).

    If you need to add a new Hobby to the tblHobby, then use your form to do so. Then requery the combo box to get the latest Hobbies, then select the Hobby, then use the sql that creates the PersonHasHobby records, then requery the subform.

    Seems to be the order of things.

  7. #7
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    As orange says, you need to requery the combo box for it to pick up any new entries in the Hobby table.

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

Similar Threads

  1. Replies: 1
    Last Post: 01-31-2015, 09:03 PM
  2. Refreshing a subform
    By RobRoy in forum Forms
    Replies: 8
    Last Post: 07-22-2013, 04:19 PM
  3. Refreshing a subform?
    By Shag84 in forum Forms
    Replies: 4
    Last Post: 08-07-2011, 10:07 AM
  4. Replies: 4
    Last Post: 05-17-2011, 06:56 AM
  5. Refreshing subform when form refreshed
    By Remster in forum Forms
    Replies: 27
    Last Post: 10-15-2010, 09:39 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