Results 1 to 10 of 10
  1. #1
    Perfac's Avatar
    Perfac is offline Expert
    Windows 7 64bit Access 2016
    Join Date
    May 2016
    Location
    Centurion Pretoria
    Posts
    618

    Requery Subform in Form.

    I have a form t02Payment and subform t02PaymentSub. On Mainform control T001 control T020 on the subform. What would be the exact VBA code to requery? Ive done some reading and trying, no success yet.

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    If referring to a control from the same form or subform, just use Me.ControlName notation e.g. Me.T001 ; Me.T020

    From outside the form its Forms!t02Payment.T001

    Slightly more complicated referencing a subform form the main form
    Use Me.SubformName.Form.SubformControl e.g. Me.t02PaymentSub.Form.T020
    From outside the form, use Forms!t02Payment.Form.T020

    You can also refer to a control in the main form from the subform using Parent notation

    See this link for more examples http://allenbrowne.com/casu-04.html

    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    "Me.SubformName.Form.SubformControl"

    Me.SubformControl.
    Form.ControlName ?

    where subform control is the name of the main form control containing the subform and ControName is the name of the control on the subform. Unless I'm misinterpreting your meaning, your syntax order is Me > [subformName] > Form (which isn't a property of the subform, rather of the subform control) > [name of control containing subform].

    Then again, your use of "subformname" might mean the subform control and subformcontrol is the control on the subform. In that case, ignore me.
    Last edited by Micron; 02-11-2018 at 08:03 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Sorry - I always name the subform control to be the same as the subform name.
    Micron is indeed perfectly correct in clarifying the points above
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Ahh, OK. It only took one time for me to regret naming a subform control the same as the subform, or for settling for the default form wizard control names (where they are named the same as their fields). The error was "Ambiguous name detected". In other words, Access couldn't distinguish between the two same-named things. Don't remember which of those 2 issues caused the error, but it has never happened since because I don't allow duplicate names. Probably it was control/field, but when it comes to subform controls/subforms, I figure why take a chance?

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    That's not what I meant.
    If you name a subform control the same as the subform itself, you will indeed get issues.

    When you place a subform in a main form, it becomes a control of the main form.
    As such it can be named using the actual subform name or any alias you like

    As I normally name subforms something like fsubSomeName, I just use the actual name for that purpose.
    For example:
    Code:
    strPupil = Forms!frmStudentAttendanceMarks.fsubStudentAttendanceMarks.Form.PupilID
    ....
    strDateString = Forms!frmCalendarMonth.fsubWeeklyCalendar.Form.txtWeekStartDate
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  7. #7
    Perfac's Avatar
    Perfac is offline Expert
    Windows 7 64bit Access 2016
    Join Date
    May 2016
    Location
    Centurion Pretoria
    Posts
    618
    Thanks. My full VBA following your advice looks like this. Gives error "Method or data member not found"

    Private Sub T001_AfterUpdate()
    Me.f02PaymentSub.Form.T020.Requery
    End Sub

  8. #8
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    In the main form, is the subform 'control' referred to as 'f02PaymentSub'? Check the form property sheet
    Check the zeroes aren't meant to be the letter O (or vice versa)

    If that doesn't fix it, please post screenshots of form & subform in both form view & design view 'labelling' the required items
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  9. #9
    Perfac's Avatar
    Perfac is offline Expert
    Windows 7 64bit Access 2016
    Join Date
    May 2016
    Location
    Centurion Pretoria
    Posts
    618
    Hi thanks. It is working now. I named the subform T010 in the mainform. Didn't understand when you guys actually meant that since the form in the Objects list name is f02PaymentSub. I'm happy and will probably not loose an hour again!

  10. #10
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Glad its working...
    That was exactly the point that Micron & I were discussing!
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. Replies: 2
    Last Post: 11-15-2017, 08:51 AM
  2. Requery subform from main form
    By nswhit in forum Forms
    Replies: 7
    Last Post: 05-13-2013, 02:22 PM
  3. Requery Main Form, Keep Focus on Subform
    By burrina in forum Forms
    Replies: 8
    Last Post: 11-21-2012, 03:50 AM
  4. Requery subform after update of main form
    By gemadan96 in forum Forms
    Replies: 3
    Last Post: 10-17-2012, 02:33 PM
  5. Replies: 3
    Last Post: 04-17-2012, 10:28 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