DoCmd.OpenReport WHERE - cant get it to work

jadeIT

Systems Analyst
Local time
Tomorrow, 04:19
Joined
Jul 16, 2002
Messages
50
I want to filter a report by vendor. The user types in the name of the vendor in a text box, and then the code does the following:

DoCmd.OpenReport stDocName, acPreview, , "[vendorcode] = " & text1

However, I get a prompt for some reason. For example if I enter 'GEORGE' into the text box, when i try to run the report I get a input box with the word GEORGE'.

I also get the same problem if I try to explicitly code it:

DoCmd.OpenReport stDocName, acPreview, , "[vendorcode] = GEORGE"

Why is it doing this?
 
Suggestion.
Why don't you put a list or combo box on the form that allows the user to pick a vendor. With the use of a filter you can open your new form or report with specs for that vendor.
 
DoCmd.OpenReport stDocName, acPreview, , "[vendorcode] = " & Me!text1
 
If [vendorcode] is text...

...then you are missing '

DoCmd.OpenReport stDocName, acPreview, , "[vendorcode] = '" & Me!text1 & "'"
 
Marilor - That's exactly what I needed to know. Thanks.
 
:)

Glad I was able to help, after all the help I've received.


Maria
 
Including calculated fields in the WHERE clause

I have another question, more out of interest:

Can you use the WHERE clause to include calculated fields on the report?

For example, if i have a field on the report called text1 and it contains the calculation field: =[cost]*[qty].

In a form can I use a line of code that uses this field in the WHERE clause, for example:

docmd.openReport, stDocName,, "[text1] =< Me![txtCost]"

I have tried it like that, but it doesn't recognise text1. I tried changing it to Reports!ReportName.text1 but that didnt work either.
 
yes thats exactly what i want to do. thats why i was asking if it was possible to do. i seems it is not, however.
 

Users who are viewing this thread

Back
Top Bottom