Dear Fred,
Sorry, I just copied/pasted your code. Here is what I have that produces
the error:
strFilter = "[vendorID] = """ & Me!VendorID & """ AND "
Year([OrderDate]) = " & Me.cboYear "
DoCmd.OpenReport "PurchasesReport", acPreview, , strFilter
When I step into the code, I see the error occurs on the
Year([OrderDate])line.
Error message: . . . "database can't find the field '|' referred to in your
expression."
One thing I noticed is that your Year([OrderDate]) line didn't have a
double-quote (") at the end of it. I pasted without the double-quote and
Access adds the double-quote at the end of that line. Could that be the
problem? If so is there a way to force it not to add the double-quote?
Newsgroup messages are usually formatted to display about 70 or so
characters on one line. You have to be aware of this when copying
from a newsgroup message, as the VBA editor will add an ending line
quote if it detects one missing from the end of a line.
There is the added " after the word AND in your code ...
strFilter = "[vendorID] = """ & Me!VendorID & """ AND "
which is incorrect ...
as is the final quote after the word cboYear.
Copied from my original reply it should be (ALL ON ONE LINE):
strFilter = "[vendorID] = """ & Me!VendorID & """ AND
Year([OrderDate]) = " & Me.cboYear
When you copy the above into your code, remove the line break after
the word AND so that the above code is all on one line (and also make
sure there is a space between the word AND and the word YEAR).
Or ...
Use the line continuation characters (a space and _)
strFilter = "[vendorID] = """ & Me.[vendorID] & """ And " _
& "Year([OrderDate]) = " & Me.cboYear
Now that quote after the word AND is now necessary to end the text.
Note also that there is now a quote in front of the word Year.
There is NO quote after cboYear on the second line as cboYear is a
Number value (not text).
Another method to split long lines is to break the syntax into more
manageable portions.
The below is on 2 lines:
strFilter = "[vendorID] = """ & Me.[vendorID] & """"
strFilter = strFilter & " AND Year([OrderDate]) = " & Me.cboYear
Note that now there are 4 quotes at the end of the first line.
Try again using any one of the 3 above methods (better yet, try each
one so you get the hang of it).