Like with Parameters statement in code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible to use "Like" instead of "=" in a parameters statement?

Instead of:

qdf2.Parameters("[Forms]![frmForm]![cboSite]") = [Forms]![frmForm]![cboSite]

Something like:

qdf2.Parameters("[Forms]![frmForm]![cboSite]") Like
[Forms]![frmForm]![cboSite]

I have a field on a form that is optional. If the user leaves it blank, then
I want all of the possible values to show. If the user enters a value, then
only show records with that value to show. Null keeps giving me the dreaded
Too Few Parameters error.

If I was using a SQL statement to do this, it would something like:

SELECT & FROM tblTest WHERE [Division] Like '*" &
[Forms]![frmForm]![cboSite] & "';"
 
cherman said:
Is it possible to use "Like" instead of "=" in a parameters statement?

Instead of:

qdf2.Parameters("[Forms]![frmForm]![cboSite]") = [Forms]![frmForm]![cboSite]

Something like:

qdf2.Parameters("[Forms]![frmForm]![cboSite]") Like
[Forms]![frmForm]![cboSite]

I have a field on a form that is optional. If the user leaves it blank, then
I want all of the possible values to show. If the user enters a value, then
only show records with that value to show. Null keeps giving me the dreaded
Too Few Parameters error.

If I was using a SQL statement to do this, it would something like:

SELECT & FROM tblTest WHERE [Division] Like '*" &
[Forms]![frmForm]![cboSite] & "';"


You would be better off doing away with the query parameters
and using the OpenForm or OpenReport method's WhereCondition
argument. This way you can just omit the Division criteria
when you want all the records.

If you are opening a recordset instead of a form or report,
then you could construct the entire query and include (or
exclude) any criteria you want (or don't want).

I that's too advanced for you, then use a criteria like this
instead of mucking around with Like:

Division = Forms!frmForm!cboSite OR Forms!frmForm!cboSite Is
Null
 
Back
Top