Data Type Mismatch?

pgsibson

Registered User.
Local time
Today, 21:58
Joined
Jan 24, 2008
Messages
44
Hi Everyone
I have a Command Button to Preview a report, filtered on the options selected by a combo box. If no selection is made the preview works fine but is a selection is made I get a Data Mismatch error.
The code is

DoCmd.OpenReport stDocName, acViewPreview, , "Directorate=" & Me!optSelectICIDDirectorate

The combo selects from a list in the underlying table. What am I doing wrong?

Regards :confused:
 
If I had to guess:

DoCmd.OpenReport stDocName, acViewPreview, , "Directorate='" & Me!optSelectICIDDirectorate & "'"
 
Thanks PBaldy for getting back so quickly.

Unfortunately doing what you suggested bring up the error
Syntax error in string in query expression '(Directorate=8')' which led me to believe I was working with the wrong boound column in the underlying query

SELECT Directorates.ID, Directorates.Directorate FROM Directorates ORDER BY [Directorate];

so I changed to bound column 2 which causes the preview button to open a "Enter Parameter Value" screen with the display showing the option I had selcted above the enter text box?
Regards Paul
 
What is the data type of Directorate in the table?
 
There are two coumns ID and Directorate. ID is an integer and Directorate is Text. Hence the Syntax error of =8. Now with your alteration to the code the syntax error is "Community" i.e the first try was reading the ID column and now reads the Directorate column. But still an error?
Paul
 
You probably could have left the bound column alone and changed the code to:

DoCmd.OpenReport stDocName, acViewPreview, , "ID=" & Me!optSelectICIDDirectorate
 
Thanks.

Added back an if isnull statemetn and it works fine.

You are brilliant.

Paul
 
No problem; glad we sorted it out.
 

Users who are viewing this thread

Back
Top Bottom