Report Filter Criteria By Custom Form

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...
 
G

Gerald Stanley

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
 
K

Kevin Sprinkel

Thanks, Gerald. I guess it was failing on a label control.

Best regards.
Kevin Sprinkel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top