Textbox query filters

  • Thread starter SteelFire via AccessMonster.com
  • Start date
S

SteelFire via AccessMonster.com

I have a form that has combo and text boxes that are used as filters for a
query. The text box that I am having a hard time with is the box that will
filter by the description of the part(record). I was thinking of setting it
up so that it would find any record with what ever you typed into the text
box. I have mine set up as:
If Not IsNull(Me.txtDesc) Then
strWhere = strWhere & "([Description] = ""*" & Me.txtDesc & "*"") AND
"
End If
This adds the description as a filter if something has been entered into the
text box. This is not working and I am not sure why. Any help would be nice.
 
F

fredg

I have a form that has combo and text boxes that are used as filters for a
query. The text box that I am having a hard time with is the box that will
filter by the description of the part(record). I was thinking of setting it
up so that it would find any record with what ever you typed into the text
box. I have mine set up as:
If Not IsNull(Me.txtDesc) Then
strWhere = strWhere & "([Description] = ""*" & Me.txtDesc & "*"") AND
"
End If
This adds the description as a filter if something has been entered into the
text box. This is not working and I am not sure why. Any help would be nice.

I don't know what your strWhere looks like up until this point, but if
you use the wild card "*" you must use the Like operator:

strWhere = strWhere & "[Description] Like ""*" & Me.[TxtDesc] & "*"""

For clarity, the quotes are:

"[Description] Like " " * " & Me.[TxtDesc] & " * " " "

The above results in a string such as this:
[Description] Like "*Jones*"
Then continue adding additional strWhere's

strWhere = strWhere & " And .... etc."

You can then filter the records displayed on the form without using a
query.

Me.Filter = strWhere
Me.FilterOn = True

Of course the above syntasx is only for Text datatype fields.
Number datatypes require a different syntax.
See:
Restrict data to a subset of records
in VBA help.
 

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