Trying to open report with certain criteria

I'm using this VBA code to attempt to open a report.  But it isn't working.  Note that PROGRAM_YEAR in a number field.  I'm getting an error:  "Microsoft can't find the field '|1' referred to in your expression."


DoCmd.OpenReport "rptWorkOrderItemDetails", acViewPreview, , [PROGRAM_YEAR] = Forms!frmReportsMenu.cboReportYear
SteveL13Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,

pls try

DoCmd.OpenReport "rptWorkOrderItemDetails", acViewPreview, , "[PROGRAM_YEAR] = " & Forms!frmReportsMenu.cboReportYear

Regards
0
SteveL13Author Commented:
Nope.  Same error.
0
Rgonzo1971Commented:
Have you tried my edited code and

what is the value of  Forms!frmReportsMenu.cboReportYear?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

SteveL13Author Commented:
Yes.  I tried your code.  The value is 2015 from a combobox selection on frmReportsMenu.
0
Rgonzo1971Commented:
Just to test it

DoCmd.OpenReport "rptWorkOrderItemDetails", acViewPreview, , "[PROGRAM_YEAR]<>" & Forms!frmReportsMenu.cboReportYear
0
Dale FyeCommented:
Is there a chance that the combo box is displaying one value, but that the bound column holds another value?

I usually do this as:

Dim strCriteria as string

strCriteria = "[PROGRAM_YEAR]<>" & Forms!frmReportsMenu.cboReportYear
debug.print strCriteria
DoCmd.OpenReport "rptWorkOrderItemDetails", acViewPreview, , strCriteria
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SteveL13Author Commented:
This just worked:

Dim strCriteria As String

    strCriteria = "[PROGRAM_YEAR]=" & Forms!frmReportsMenu.cboReportYear
    Debug.Print strCriteria
    DoCmd.OpenReport "rptWorkOrderItemDetails", acViewPreview, , strCriteria

(Dale, I changed <> to =)
0
Dale FyeCommented:
Steve,

Good catch, I didn't realize I had copied the example that RGonzo had used,

But I don't understand why my solution (with the correction) would not work when  Rgonzo's original post didn't work?  They should be the same, and if they are, he should get the points.

The advantage of defining strCriteria on a separate line is that you can print it out and actually the value the value that you are using in the OpenReport method.  I do this for all of my domain functions as well.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.