Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subform updated by 2 or more listboxs

Status
Not open for further replies.

fb63

Technical User
Jun 8, 2010
18
US
I have an unbound form with two listboxs, one for category and one for location that are pulling from the main table. I also have an unbound subform pivot table showing total records form that table by age. After users select categories and locations they want the subform to show only the records for the selected options. The filters for the detail form pulls up the correct info, but I am at a loss as to how to force that subform to refresh. Pulling it up on a new window works, but doesn't give them what they want.

subform code
Code:
SELECT qry1.Category, qry1.Location, Sum(IIf([expr1]<15,1,0)) AS explt15,  Sum(IIf([expr1]>=15 And [expr1]<=20,1,0)) AS exp15to20, Sum(IIf([Expr1]>20,1,0)) AS expo20 FROM qry1 WHERE GROUP BY qry1.Category, qry1.Location;"

my code which pulls up detail record form
Code:
    Dim stDocName As String
    Dim StrWhere As String
    Dim ssql As String
    stDocName = "qry1"
    StrWhere = "1=1 "
    StrWhere = StrWhere & ListSelections(Me.WorkByCommodity, "[category]", "'")
    StrWhere = StrWhere & ListSelections(Me.workbyLocation, "[Location]", "'")
    Debug.Print StrWhere
    
    DoCmd.OpenForm stDocName, acNormal, , StrWhere, acEdit, acNormal

ListSelections function
Code:
Function ListSelections(lboListBox As ListBox, _
        strFieldName As String, strDelim As String) As String
    'send in a list box control object
    Dim strIn As String
    Dim varItem As Variant
        
    If lboListBox.ItemsSelected.Count > 0 Then
        strIn = " AND " & strFieldName & " In ("
        For Each varItem In lboListBox.ItemsSelected
            strIn = strIn & strDelim & lboListBox.ItemData(varItem) & strDelim & ", "
        Next
        'remove the last ", " and add the ")"
        strIn = Left(strIn, Len(strIn) - 2) & ") "
    End If
    ListSelections = strIn

End Function

I am assuming I need to modify the sqlcode for the subform but not sure what modifications I need to make. All my changes have either not compiled, returned errors, or brought up the subform as a new form.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top