Is it possible to pass an operator from a form to a query limit?

W

WildlyHarry

I want a to use a field on my form to pass a limit to a query. I want the
field on the form to contain the operator and the value that will be passed
to the query limit. For example form 1 field 1 = "<> monkey". The query
limit reads [forms]![form1]![field 1]. The query would then return all
records that are not equal "monkey". Unfortunately, it looks like the form
is passing the operator and the value as one chunk of text ie "<> monkey"
instead of <> "monkey". No matter how I manipulate the value in the field on
the form. Is there anyway to pass an operator from a field on a form?
Thanks in advance for the help.
 
J

Jeff Boyce

Tried looking into the Eval() function?

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
J

John W. Vinson

Is there anyway to pass an operator from a field on a form?

Not really. You'll need to use VBA code to construct a SQL string
incorporating the text supplied by the user.

I'd avoid this scenario if at all possible, since it gives the user the
ability to inject ANYTHING into your query; if they're skilled at SQL syntax,
fine, but otherwise you'll risk getting no results, query errors, or (worst)
normal-looking but incorrect results. You may want to consider instead giving
the user a combo box with a choice of comparison operators (=, <>, <=, <,
etc.) and building the SQL using these.
 

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