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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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
SteveL13Author Commented:
Nope.  Same error.
Rgonzo1971Commented:
Have you tried my edited code and

what is the value of  Forms!frmReportsMenu.cboReportYear?
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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

DoCmd.OpenReport "rptWorkOrderItemDetails", acViewPreview, , "[PROGRAM_YEAR]<>" & Forms!frmReportsMenu.cboReportYear
Dale FyeOwner, Developing Solutions LLCCommented:
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

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 =)
Dale FyeOwner, Developing Solutions LLCCommented:
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.
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.