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

    AfterUpdate event won't refresh subform!

    This is a follow-up to this solved thread (sorry, Rural Guy).



    I have a form ('Mainform') that contains a subform ('Subform') that contains combo boxes populated with values from a lookup table ('Lookuptable'). I have a further form ('Lookupform') that's used for inputting data to the lookuptable.

    I have a refresh button on Mainform that successfully refreshes the data in the combo boxes in Subform whenever an update is made to Lookupform. I've tried to do away with the refresh button by adding AfterUpdate events to Mainform and Subform. But it doesn't work!

    Here's my code:
    Private Sub Lookupform_AfterUpdate()
    On Error GoTo Err_Lookupform_AfterUpdate
    Me.Refresh
    Me![Subform].Form.Refresh
    Exit_Lookupform_AfterUpdate:
    Exit Sub
    Err_Lookupform_AfterUpdate:
    MsgBox Err.Description
    Resume Exit_Lookupform_AfterUpdate
    End Sub
    What am I doing wrong?

    (For info, I've tried 'requery' as well as 'refresh'.)

  2. #2
    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
    Nothing for which to be sorry! Any chance you can post a sample of your db so we can both be looking at the same thing?

  3. #3
    ConneXionLost's Avatar
    ConneXionLost is offline Simulacrum
    Windows XP Access 2003
    Join Date
    Jan 2010
    Location
    Victoria, Canada
    Posts
    291
    Just a shot in the dark here, but it looks like you want to refresh the Mainform & Subform while the Lookupform still has the focus. If so, then you'll need to name the main & subform in your code instead of using "Me" since Access will assume you're referring to the Lookupform.

    Cheers,

  4. #4
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    I think it's probably in the wrong event. Instead of AfterUpdate, I would suggest putting the code in the OnChange event. AfterUpdate would only trigger when the parent form's record source is updated (assuming it's bound to a record source) so it doesn't always fire when expected.

  5. #5
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317
    Neither of those suggestions works, assuming I've tried them properly, so I've cobbled something together to demonstrate my problem (see attached).

    The first subform (headed 'Friend of') contains dropdowns populated with data from the table corresponding to the main form. The second subform (headed 'Hobbies') contains dropdowns populated with data from a lookup table. The refresh button works, but the OnChange event doesn't.

    (Note that the very first record you enter after opening the form appears in the appropriate dropdown, but I've tested this and it has nothing to do with the OnChange event.)

  6. #6
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    I guess I don't understand what exactly is supposed to happen but Refresh doesn't seem to do anything either. What do you expect it do, ideally?

  7. #7
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317
    Quote Originally Posted by slave138 View Post
    I guess I don't understand what exactly is supposed to happen but Refresh doesn't seem to do anything either. What do you expect it do, ideally?
    As soon as a new record is added in the main form, the relevant name should appear as an option in the dropdown list in the first subform. As I said, this happens for the first new record I add after opening the main form but not for any subsequent records. But clicking on Refresh remedies this.

    So, for example, try adding 'Mike Green' as record 5. This will appear immediately in the dropdown list in the first subform. But then try adding 'Wendy Taylor' as record 6. This won't appear in the dropdown list until you click on Refresh. I want it to appear automatically.

    Mutatis mutandis, the same goes for the second subform.

  8. #8
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    Now that I understand better, you should put the following in the LostFocus event for each text field:

    Code:
    Me.sfmFriendship.Form.FriendOf.Requery

  9. #9
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317
    Quote Originally Posted by slave138 View Post
    Now that I understand better, you should put the following in the LostFocus event for each text field:

    Code:
    Me.sfmFriendship.Form.FriendOf.Requery
    Thank you. I couldn't get that to work (could you?) but I have found success with something I've based on it:
    Private Sub FirstName_LostFocus()
    On Error GoTo Err_FirstName_LostFocus

    Me!sfmFriendship.Form.Refresh

    Exit_FirstName_LostFocus:
    Exit Sub
    Err_FirstName_LostFocus:
    MsgBox Err.Description
    Resume Exit_FirstName_LostFocus
    End Sub
    Setting aside the fact that this seems to work, can you see any problem with it?

    One final question. I've put this in the LostFocus event of the Hobby field in frmHobby, which links to the sfmPersonHobby (the second subform) within frmPerson:
    Private Sub Hobby_LostFocus()
    On Error GoTo Err_Hobby_LostFocus

    Forms!frmPerson.sfmPersonHobby.Form.Refresh

    Exit_Hobby_LostFocus:
    Exit Sub
    Err_Hobby_LostFocus:
    MsgBox Err.Description
    Resume Exit_Hobby_LostFocus
    End Sub
    It works fine when frmPerson is open but generates a 'can't find form' error message when frmPerson is closed. How would I add a condition to say 'Refresh sfmPersonHobby if frmPerson is open; otherwise forget about it'?

  10. #10
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    It worked fine for me. Here's your DB with only that command added to the LostFocus events of the two text boxes.

  11. #11
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    To answer your later question, use something like:
    Code:
    If CurrentProject.AllForms(formname).IsLoaded = True Then...

  12. #12
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317
    Quote Originally Posted by slave138 View Post
    It worked fine for me. Here's your DB with only that command added to the LostFocus events of the two text boxes.
    And for me now. I'm blowed if I can work out what I was doing wrong this morning. Thank you.

  13. #13
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317
    Quote Originally Posted by slave138 View Post
    To answer your later question, use something like:
    Code:
    If CurrentProject.AllForms(formname).IsLoaded = True Then...
    I couldn't get this to work at first either, but now it works perfectly. It seems to make a difference if instead of editing your old code you cut it out and start again. I wouldn't have a clue why.

    Thank you again. That's it from me at least until next week!

  14. #14
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317
    Man, I'm having this problem again! What can prevent lists from requerying?

  15. #15
    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
    Have you already imported the db into a fresh, empty db and see if the problem follows? You can cause corruption if the debugger is runnig and you edit code. The import leaves the corruption behind. You can also try a /decompile.

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

Similar Threads

  1. refresh subform
    By asmith in forum Forms
    Replies: 5
    Last Post: 09-27-2010, 10:58 AM
  2. AfterUpdate not updating
    By P5C768 in forum Programming
    Replies: 6
    Last Post: 06-10-2010, 02:31 PM
  3. Trigger subform event
    By tuna in forum Forms
    Replies: 0
    Last Post: 05-09-2010, 06:29 AM
  4. Problems with subform refresh
    By Viggen66 in forum Queries
    Replies: 2
    Last Post: 02-23-2010, 04:07 AM
  5. My subform doesnt refresh????? HELP!
    By LiamMurphy in forum Forms
    Replies: 1
    Last Post: 03-09-2006, 09:08 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