Selected report based on text box

G

Guest

Hi,
I have a form with a text box (txtbox) and I want to preview a report
showing only records whose ItemDecription begin with the data entered in the
text box.

I have the following code in the "on click" event of the command button that
calls the report and thought it would work........

Dim stDocName As String
Dim strcriteria As String

strcriteria = "left$([ItemDescription]) = '" & [txtBox] & "'"
stDocName = "ByItem main"
DoCmd.OpenReport stDocName, acPreview, strcriteria

It didn't work. Any help would be appreicated.

Also, I want to do another report which would only show records in which the
any part of ItemDescription would contains the data in the text box.

Thanks,
 
M

Marshall Barton

Phil said:
I have a form with a text box (txtbox) and I want to preview a report
showing only records whose ItemDecription begin with the data entered in the
text box.

I have the following code in the "on click" event of the command button that
calls the report and thought it would work........

Dim stDocName As String
Dim strcriteria As String

strcriteria = "left$([ItemDescription]) = '" & [txtBox] & "'"
stDocName = "ByItem main"
DoCmd.OpenReport stDocName, acPreview, strcriteria

It didn't work. Any help would be appreicated.

Also, I want to do another report which would only show records in which the
any part of ItemDescription would contains the data in the text box.


You need another comma before strCriteria and use this:

strcriteria = "ItemDescription Like '" & [txtBox] & "*'"

For the other report, use:

strcriteria = "ItemDescription Like '*" & [txtBox] & "*'"
 

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

Similar Threads


Top