Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

why this doesn't work

Status
Not open for further replies.

skate

Technical User
Nov 29, 2002
65
CA
I have a listbox that searches according to my textbox entry. Now i want to print that list. I have a preview button, and used this code on click. Why doesn't it work? It keeps giving me a syntax error.

DoCmd.OpenReport "File Report", acViewPreview, , "[Files].[File Index]" = & Forms![File Search]!lstResults
 
Try this:

DoCmd.OpenReport "File Report", acViewPreview, , "[Files].[File Index]='" & Forms![File Search]!lstResults & "'"
 
ahh...no, that doesn't work either
 
Hi!

A couple of questions. Is the list box multiselect? Is there any more to the error message you get?

Jeff Bridgham
bridgham@purdue.edu
 
If you're trying to print out the contents of your list box then the code you're using (even if it was correct) wont work. The List Box value is equal to what is selected and not it's entire contents.

If it is set to Multi-Select then it has no value and you must use the ItemsSelected property to decipher what has been chosen.

What datatype is your bound column? If it is an integer, without checking, I think the correct syntax is:

DoCmd.OpenReport "File Report", acViewPreview, , "[Files].[File Index] = " & Forms![File Search]!lstResults

But to reiterate if your trying to filter based on every entry in your listbox you'll have to go about it differently. I used the 'IN' clause within my SQL when I wanted to filter based on either all the contents of my list box or if the Multi-Select facility was enabled.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top