access open report criteria - error!

I'm trying to open a report with the following statement:

DoCmd.OpenReport "CatWebWork2CommentR", acViewPreview, , "LinkToID = 526 AND CommentTypeID = 'CatWebWork'"

I get an error: "Data type mismatch in criteria expression", and access crashes.

What can be causing this?
LVL 10
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.

Is commentTypeID numeric?  You are passing a string literal.  

If CatWebWork is a variable or field on your form, and commenttypeID is numeric, try this syntax:

DoCmd.OpenReport "CatWebWork2CommentR", acViewPreview, , "LinkToID = 526 AND CommentTypeID = " & CatWebWork
etech0Author Commented:
It's a lookup field in the table. Am I supposed to pass the number, or the text?
Look at the properties for CommentTypeID in the table's design view.

If it is a numeric field, you should pass a number.

If it is a text field, you should pass the text value.
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

etech0Author Commented:
It's a number. I'll try passing a number.
etech0Author Commented:
Now I don't get the error, but it's not filtering by LinkToID!
Then the criteria are probably mutually exclusive - ie: you don't have any records in the recordsource where both of these are found:
          LinkToID = 526
          CommentTypeID  =  the number that you passed

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
etech0Author Commented:
Forget the last comment - it's working now.

Just give me a few minutes to test it out...
etech0Author Commented:
That must have been it.

Thanks a million!
Glad to help out :)
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.