Filtering Subforms

King Kreglo

Registered User.
Local time
Yesterday, 16:00
Joined
Aug 31, 2013
Messages
32
Hi there!

I'm having some trouble with this code and can't seem to find the solution online.

I have a combo box (cboCurrentCustomer) on my main form that I wish to filter 3 subforms. The combo box serves as a search box, filtering the subforms as you type. The first subfrom I'm testing this on is called "subfrmOrder Central - Access.

The error that keeps coming up is reads "Compile error: Method or data member not found"

Here's the Code I've been trying to use:

Code:
Private Sub cboCurrentCustomer_Change()

 ' If the combo box is cleared, clear the form filter.
  If Nz(Me.cboCurrentCustomer.Text) = "" Then
    subfrmOrder Central - Access.Form.Filter = ""
    subfrmOrder Central - Access.FilterOn = False
    
  ' If a combo box item is selected, filter for an exact match.
  ' Use the ListIndex property to check if the value is an item in the list.
  ElseIf Me.cboCurrentCustomer.ListIndex <> -1 Then
    subfrmOrder Central - Access.Form.Filter = "[Customer] = '" & _
                     Replace(Me.cboCurrentCustomer.Text, "'", "''") & "'"
    subfrmOrder Central - Access.FilterOn = True
    
  ' If a partial value is typed, filter for a partial company name match.
  Else
    subfrmOrder Central - Access.Form.Filter = "[Customer] Like '*" & _
                     Replace(Me.cboCurrentCustomer.Text, "'", "''") & "*'"
    subfrmOrder Central - Access.FilterOn = True

  End If
  
  ' Move the cursor to the end of the combo box.
  Me.cboCurrentCustomer.SetFocus
  Me.cboCurrentCustomer.SelStart = Len(Me.cboCurrentCustomer.Text)

End Sub


This only filters one of the subforms. I figured it'd be best to start with one then whip out the other two!

Any help is appreciated :)
 
While the Access GIU lets you name objects with spaces, you cannot refer to them in VBA with spaces. (A good reason never to use spaces in names.)

Enclose the reference in square brackets, viz
[subfrmOrder Central - Access]

and, even if this works, it's better to include the object holding the control, viz
me.[subfrmOrder Central - Access]

and if you need to refer to any of the form properties in the sub form object, you need to use the form properties of the control, viz
me.[subfrmOrder Central - Access].Form....
 
Thanks for the response!
I tried that actually!
It still was coming up with the same error so I found a way around the need for the filter, so I should probably delete this thread! I could use a pointer on how to do that as well :)
 
It worked for me in the database you supplied.
 

Users who are viewing this thread

Back
Top Bottom