I have created a form which uses a combobox to filter date "on the fly" i.e. while typing in the combobox the filter is already selecting records. I used code found from a helpful source online, and am just above amateur level. The form works perfectly, however I wanted to do some sorting and subtotaling, so needed to use a report instead of the form. I saved the form as a report, and in the report the combobox does not work properly. I changed all the references from form to report in the code, and "believe" that it is set up properly. The only thing I noticed was this; in the form the code is in the "change" event, but there is no change event selection in the report. Following is the code from the form which works:
Private Sub cboFilter_Change()
On Error Resume Next
' If the combo box is cleared, clear the form filter.
If Nz(Me.cboFilter.Text) = "" Then
Me.Form.Filter = ""
Me.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.cboFilter.ListIndex <> -1 Then
Me.Form.Filter = "[SupplierID] = '" & _
Replace(Me.cboFilter.Text, "'", "''") & "'"
Me.FilterOn = True
' If a partial value is typed, filter for a partial SupplierID name match.
Else
Me.Form.Filter = "[SupplierID] Like '*" & _
Replace(Me.cboFilter.Text, "'", "''") & "*'"
Me.FilterOn = True
End If
' Move the cursor to the end of the combo box.
Me.cboFilter.SetFocus
Me.cboFilter.SelStart = Len(Me.cboFilter.Text)
End Sub
Any thoughts on how I must manipulate all of this to get the same behavior in a report?
Private Sub cboFilter_Change()
On Error Resume Next
' If the combo box is cleared, clear the form filter.
If Nz(Me.cboFilter.Text) = "" Then
Me.Form.Filter = ""
Me.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.cboFilter.ListIndex <> -1 Then
Me.Form.Filter = "[SupplierID] = '" & _
Replace(Me.cboFilter.Text, "'", "''") & "'"
Me.FilterOn = True
' If a partial value is typed, filter for a partial SupplierID name match.
Else
Me.Form.Filter = "[SupplierID] Like '*" & _
Replace(Me.cboFilter.Text, "'", "''") & "*'"
Me.FilterOn = True
End If
' Move the cursor to the end of the combo box.
Me.cboFilter.SetFocus
Me.cboFilter.SelStart = Len(Me.cboFilter.Text)
End Sub
Any thoughts on how I must manipulate all of this to get the same behavior in a report?