Link to home
Start Free TrialLog in
Avatar of mekofun
mekofun

asked on

Open Report command with 2 filter

Hi, I type below code in order open report after user click the button and the filter is Code and Exam year.
It has error message occured. "Mis match type run time error 13."

Thanks
DoCmd.OpenReport "ECVReport", acViewPreview, "ECVResult Report Query", "Code =""" & A & """" And "ExamYear =" & Chr(34) & Me!combExamYear & Chr(34)

Open in new window

Avatar of coleventures
coleventures

DoCmd.OpenReport "ECVReport", acViewPreview, "ECVResult Report Query", "Code =""" & A & """" And "ExamYear =" & Chr(34) & Me!combExamYear & Chr(34)
 


Your error is with the """.  it should be "'" (double quote, single quote, double quote).
IGNORE my response.  I erred.  I am working on the correct syntax.  Sorry.
DoCmd.OpenReport "ECVReport", acViewPreview, "ECVResult Report Query", "Code =""" & A & """" And "ExamYear =" & Chr(34) & Me!combExamYear & Chr(34)


Now, if CODE is to be the literal A character and ExamYear is an integer/value and not  a string.
"Code = 'A' AND ExamYear = " & Me!combExamYear

If examyear is a string then you'd have to do this:
"Code = 'A' AND ExamYear = '" & Me!combExamYear & "'"

That would be = single double & Me!combExamYear & double single double.

Robert
ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I would use a variable for the where clause then it is easier to debug as you can inspect its value before trying to run the report.
If A is a variabl then the code below will work for you, if A is a literal then you need to put " around it.
Finally I have put a Debug.Print strWHERE so it will show the value of strWHERE in the Immediate Window. If you put a breakpoint (F9) on the OpenReport line you can inspect the value before trying to open the report.
Cheers, Andrew
Dim strWHERE as String
strWHERE = "Code =" & Chr(34) & A & Chr(34) & " And "ExamYear = " & Chr(34) & Me!combExamYear & Chr(34)
Debug.Print strWHERE
DoCmd.OpenReport "ECVReport", acViewPreview, "ECVResult Report Query", strWHERE
 

Open in new window