Filter records by a form field

P

Paul Fenton

I have a form that displays Client records and has a combo box field
that displays the source of the lead. I want to filter the records
displayed on the form by a certain value in that combo box and I want
to place a command button on the form that will set the filter. I've
tried this code:

DoCmd.OpenForm "Browse Client List", acNormal, , "'Lead Source' =" &
me.cboReferrals

All I get with the above is an error "The open form action was
cancelled".

Is what I'm trying to do possible without a toolbar and if so, what's
wrong with the line above?


Paul Fenton
(e-mail address removed)
 
N

Nikos Yannacopoulos

Paul,

I think you need to change the syntax of the field reference from 'Lead
Source' to [Lead Source].
Also, you need to take into account the data type of field [Lead Source].
Your filter expression will work for numeric, but not for text. If it is a
text field, then you need to change the filter expression to:

"[Lead Source] = ' " & Me.cbo Referrals & " ' "

to enclose the the combo value in single quotes.
Another possible problem is that Me. in your combo reference refers to a
different form, in case there is a pop-up form open; if that's the case,
changing the reference to an absolute one (Foms!FormName!cboReferrals) will
solve it.

HTH,
Nikos
 

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