Report Filter Criteria By Custom Form

  • Thread starter Thread starter Kevin Sprinkel
  • Start date Start date
K

Kevin Sprinkel

I began a prototype form to gather a report's filtering
criteria that has four combo boxes. My strategy is to
form the filter string in a hidden textbox by calling a
procedure that loops through the controls from each's
AfterUpdate event.

The following procedure produces an "Object does not
support this property or method" error on the first line
of the For loop:

Private Sub WriteFilterString()
Dim intindex As Integer
Dim ctl As Control

'Reinitialize string
Me!txtFilterString = ""

' Loop through all form controls;
' if there's data, add to filter string
For Each ctl In Me.Controls
If Nz(ctl.Value) <> 0 Then
Me!txtFilterString = Me!txtFilterString & ctl.Value
& " AND "
End If
Next ctl

' Strip end of filter
Me.txtFilterString = Left(Me.txtFilterString, Len
(Me.txtFilterString) - 5)
End Sub

Can anyone reveal my error, and/or suggest a better
strategy for this task?

Kevin Sprinkel
Becker & Frondorf

....ME's build weapons, CE's build targets...
 
I recommend enclosing your If ststement within another that
checks the type of control to be a combo e.g.

If ctl.ControlType = acComboBox Then
If Nz(ctl.value) <> 0 then

Hope That Helps
Gerald Stanley MCSD
 
Thanks, Gerald. I guess it was failing on a label control.

Best regards.
Kevin Sprinkel
 
Back
Top