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!

Update Subfrom based on Listbox selection

Status
Not open for further replies.

fb63

Technical User
Jun 8, 2010
18
US
I have a subform that shows a pivot graph of the records tied to the main form. That form has two listbox's used to filter those records. I have that tied to a button to pull new form to review individual records that were filtered. I would like to update the subform to show the pivot graph of the filtered results. They would like it to update as selections made, but would settle for a button to click to update the graph. The code below is in the EventClick of the button but error that the for isn't named.

Code:
  Dim stdocname As String
    Dim strwhere As String
    stdocname = "[form]![frm_main]![sfrm_chart]"
    strwhere = "1=1 "
    strwhere = strwhere & ListSelections(Me.WorkByCommodity, "[category]", "'")
    strwhere = strwhere & ListSelections(Me.workbyLocation, "[Location]", "'")
    DoCmd.OpenForm stdocname, , , strwhere, acEdit, acNormal

Here is the function
Code:
Function ListSelections(lboListBox As ListBox, _
    strFieldName As String, _
    strDelim As String) As String
    ' Used to grab the selected items form the listbox selections to use in the where statement
    '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
 
To begn with, is this a typo:

stdocname = "[form]![frm_main]![sfrm_chart]"

Usually the syntax for this construct is:

stdocname = "[forms]![frm_main]![sfrm_chart]"

[forms], small change but a needed one. You would use the 'form' keyword as:

form_frm_main!sfrm_chart

What happens when you make this change?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top