Page 1 of 2 12 LastLast
Results 1 to 15 of 28
  1. #1
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317

    Refreshing subform when form refreshed

    Folks



    I have a "Refresh" button on my main form that doesn't refresh the subform when it's clicked on. What do I need to add to my VBA code so that both the main form and the subform are refeshed when I click on "Refresh"?

    Thanks

    Remster

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You do understand that Refresh does *not* drop any deleted records or pick up any new records, right?

  3. #3
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317
    In the main form in question it seems to do what I want it to do.

    Let's call that form "DocumentsForm" and another one of my main forms "PeopleForm". DocumentsForm contains a combo box called "PeopleList", which is populated with data from PeopleTable. If, while I have DocumentsForm open, I open PeopleForm and add a new record, that new record produces a new value in PeopleList after (and only after) I click on my Refresh button. Are you telling me that shouldn't work?

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    A *Requery* will update the recordset with any new records. I have no idea what is behind your Refresh button.

  5. #5
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317
    Quote Originally Posted by RuralGuy View Post
    A *Requery* will update the recordset with any new records.
    Can you give me some tips on how to do that please?

    Quote Originally Posted by RuralGuy View Post
    I have no idea what is behind your Refresh button.
    Here you go:

    Private Sub Refresh_Click()
    On Error GoTo Err_Refresh_Click


    DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

    Exit_Refresh_Click:
    Exit Sub

    Err_Refresh_Click:
    MsgBox Err.Description
    Resume Exit_Refresh_Click

    End Sub


    Access wrote this itself: it's one of the pre-programmed options when you add a button.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Even though it was written by Access, the DoMenuItem syntax has been replaced with the RunCommand syntax. Here's a site to make the conversion easier: http://www.accessruncommand.com/domenuitem.htm
    Having said that, I don't use either. I prefer simply using code, in this case what you have would be replaced with:
    Code:
    Private Sub Refresh_Click()
       On Error GoTo Err_Refresh_Click
     
       Me.Refresh     '-- Which simply refreshes the form and its underlying RecordSet.
     
    Exit_Refresh_Click:
       Exit Sub
    Err_Refresh_Click:
       MsgBox Err.Description
       Resume Exit_Refresh_Click
    End Sub
    Adding the additional code to either Refresh or Requery the SubForm is trivial.

  7. #7
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317
    Hmm, the new data still doesn't appear in my drop-downs. I wonder what I'm missing.

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Are you talking about a SubForm or ComboBoxes (dropdowns) on a MainForm? If it is ComboBoxes then there are other things that need to be done.

  9. #9
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317
    I'm talking about combo boxes within a subform. They're the sort of combo boxes where you're not restricted to the values already in the list. So suppose a new value is added within the subform of Record 1. I want that value to appear in the list when completing the subform of Record 2. At the moment it's not appearing until I close and reopen the (main) form.

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Are you using the NotInList event to add to the RowSource of the ComboBox in the SubForm? Is the SubForm in Continuous Form view?

  11. #11
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317
    I'm not sure what you mean by 'Continuous Form view', so I've added a screenshot. I suspect this is what you mean.

    What's the NotInList event and what do I need to do to include it?

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    The Hyperlink area of that form is a SubForm in either Datasheet or Continuous Form view. Is that the area of this form that you are trying to get to update?

  13. #13
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317
    Yep, that's the one! All the other combo boxes refresh when I click my 'refresh' button, but not the ones in the subform.

  14. #14
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    This link should shed some light on the subject: http://www.mvps.org/access/forms/frm0031.htm
    BTW, I'll bet you could make everything happen automatically without the need for a Refresh button.

  15. #15
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317
    This seems to work:

    Private Sub Refresh_Click()
    On Error GoTo Err_Refresh_Click

    Me.Refresh
    Me![Miscellaneous Hyperlinks subform].Form.Refresh

    Exit_Refresh_Click:
    Exit Sub
    Err_Refresh_Click:
    MsgBox Err.Description
    Resume Exit_Refresh_Click
    End Sub

    Whether the whole thing looks sufficiently streamlined to an experienced eye, I've no idea. But it seems to work. (I tried replacing 'Refresh' with 'Requery', which doesn't.)

    As for dispensing with the 'refresh' button, are you talking about adding an AfterUpdate event or something like that?

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

Similar Threads

  1. Refreshing Make table queries within a form?
    By umass02 in forum Queries
    Replies: 2
    Last Post: 09-03-2010, 09:14 AM
  2. refreshing form after running query
    By ninachopper in forum Queries
    Replies: 1
    Last Post: 07-12-2010, 04:30 AM
  3. Refreshing queries without opening them
    By trialpayjinn in forum Access
    Replies: 3
    Last Post: 07-01-2010, 05:04 PM
  4. Outlook Table not Refreshing (2007)
    By rglasunow in forum Programming
    Replies: 0
    Last Post: 09-23-2009, 11:50 AM
  5. Refreshing comboboxes in a subform
    By KB_Dev in forum Programming
    Replies: 1
    Last Post: 04-07-2009, 12:12 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