Filter by Contains

brsawvel

Registered User.
Local time
Today, 12:42
Joined
Sep 19, 2007
Messages
256
I tried doing a search on this, but apparently "contains" is too common of a word that the search automatically deletes it as a keyword....

I have an unbound textbox where I want the user to place keywords. Then when they click the report button, I want the report generated to show all records where the keyword appears in any of the columns.

What I have right now is something to the effect of (not working anyway):

Code:
If Me.txtA Not Is Null Then [COLOR=Blue]'preview rptA only showing records where one of the fields contains the keywords in txtA[/COLOR]

Else [COLOR=Blue]'?Exit If?[/COLOR]

End If
 
I've edited the code, but it doesn't bring back anything when I enter a value I know is contained in one of the records fields:

Code:
If Not IsNull(Me.Text21.Value) Then

stDocName = "rptReport"
DoCmd.OpenReport stDocName, acPreview, , Chr(34) & Me.Text21 & Chr(34) & "In ([fldTitle])"

End If
What is wrong with my code? HELP!
 
You might want to take a look at how the In() function works in help. I'm pretty sure it's not gonna work this way. Also, you have a space issue, though that doesn't matter since it's not being evaluated anyway.

Code:
FieldName In(value1, value2, value3, ... valueN)

You should assign the string you are building to a variable first (like the doc name variable) and output it to the Immediate window (using Debug.Print). Put that value into a temporary query as the where clause and see if it works. If not, keep trying. If you need help, paste the value in the immediate window in this thread along with the new code.

You need to be a lot more descriptive when you're communicating to the forum on issues like this. For instance "doesn't bring back anything" doesn't really mean anything to us. How do you know it doesn't bring back anything? We cannot see what you see.
 
Thanks for the info.

I'm not very knowledgeable with SQL and VB so I just picked up a few things here and there.

The 2 paragraphs after the code are confusing. I'm not sure what you mean. I know how to put code into a query to see if it works. But I'm not sure how to assign strings or outputing to debug.print.

Is it possible to be a little more simple for the ignorant guy here? :)
 

Users who are viewing this thread

Back
Top Bottom