How to reference subform from a popup form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • munkee
    Contributor
    • Feb 2010
    • 374

    How to reference subform from a popup form

    Hi all,

    I am having some trouble, I am trying to create an advanced search form which will open up as a popup from my main search from.

    I am using the Allen Browne method of creating the where string however I am setting the recordsource of the subform with a constructed sql string, not filtering.

    My main form contains a subform which my basic search selects perfectly. However I cant seem to be able to get my advanced search to point down to the sub form correctly. I usually get the error "This object does not support this property or method" which keeps poping up everytime I close resulting in having to close access through task manager.

    Below is the code I use to point to the record source of the main forms sub form:

    Code:
        'Finally, apply the string as a query of the recordsource
        
        Dim topinsert2 As String
        
        
        If comboNrecords2 = "All" Then
        
        topinsert2 = "All "
        
        Else
        
        topinsert2 = "TOP " & comboNrecords2 & " "
        
        End If
        
       Forms!frmlogforfiltering!subfrmlogforfiltering.RecordSource = "Select " & topinsert2 & " * FROM logforfiltering WHERE " & strwhere2
    my main form: frmlogforfilter ing

    my sub form: subfrmlogforfil tering

    my advanced search form: frmAdvancedSear ch


    Thanks for any help,

    Chris
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Originally posted by munkee
    Hi all,

    I am having some trouble, I am trying to create an advanced search form which will open up as a popup from my main search from.

    I am using the Allen Browne method of creating the where string however I am setting the recordsource of the subform with a constructed sql string, not filtering.

    My main form contains a subform which my basic search selects perfectly. However I cant seem to be able to get my advanced search to point down to the sub form correctly. I usually get the error "This object does not support this property or method" which keeps poping up everytime I close resulting in having to close access through task manager.

    Below is the code I use to point to the record source of the main forms sub form:

    Code:
        'Finally, apply the string as a query of the recordsource
        
        Dim topinsert2 As String
        
        
        If comboNrecords2 = "All" Then
        
        topinsert2 = "All "
        
        Else
        
        topinsert2 = "TOP " & comboNrecords2 & " "
        
        End If
        
       Forms!frmlogforfiltering!subfrmlogforfiltering.RecordSource = "Select " & topinsert2 & " * FROM logforfiltering WHERE " & strwhere2
    my main form: frmlogforfilter ing

    my sub form: subfrmlogforfil tering

    my advanced search form: frmAdvancedSear ch


    Thanks for any help,

    Chris
    Hi

    I think this may do it
    Code:
    Forms!frmlogforfiltering!subfrmlogforfiltering.Form.RecordSource = "Select " & topinsert2 & " * FROM logforfiltering WHERE " & strwhere
    I believe (assume) that 'subfrmlogforfi ltering' is the form's subform CONTROL, and not the subform itself. To access the subform's controls and properties you must refer to the Form object CONTAINED in the subform control.

    It is confusing because Access gives the sub form control the same name as the sub form it contains by default (but you are given the opertunity to change it).

    In later versions of Access 2003+ I prefer to use this form, not sure why, but probably because I never took thr trouble to understand Bangs(!)
    Code:
    Form_frmlogforfiltering.subfrmlogforfiltering.Form.RecordSource = "Select " & topinsert2 & " * FROM logforfiltering WHERE " & strwhere
    Of course, this may not be the problem!

    HTH


    MTB

    Comment

    Working...