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
etech0Asked:
Who is Participating?
 
mbizupConnect With a Mentor Commented:
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
0
 
mbizupCommented:
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
0
 
etech0Author Commented:
It's a lookup field in the table. Am I supposed to pass the number, or the text?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
mbizupCommented:
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.
0
 
etech0Author Commented:
It's a number. I'll try passing a number.
0
 
etech0Author Commented:
Now I don't get the error, but it's not filtering by LinkToID!
0
 
etech0Author Commented:
Forget the last comment - it's working now.

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

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

All Courses

From novice to tech pro — start learning today.