View Full Version : Report Preview Erroring Out Instead of Opening


quest4
08-12-2008, 04:26 AM
Good morning, I have a cmdButton and it is supposed to open a report on the current user being displayed in the form. Instead, I get an error, Data type mismatch in criteria expression. Here is the procedure:
Private Sub Preview_Click()
On Error GoTo Err_Preview_Click
Dim stDocName As String
stDocName = "RptFactSheet"
DoCmd.OpenReport "RptFactSheet", acPreview, , "[AddressID] = " & [AddressID]
Exit_Preview_Click:
Exit Sub
Err_Preview_Click:
MsgBox Err.Description
Resume Exit_Preview_Click
End Sub
I can not see what I am doing wrong here, any suggestions? Thank you in advance for any help.:confused:

namliam
08-12-2008, 04:33 AM
Is your addressID a number field??
If it is a text field you must encluse it with quotes, like so:
"[AddressID] = '" & [AddressID] & "'"
If it were a date field, use # around your fields.

If this is not the problem your problem lays in the query that is used in the report or a calculation that is beeing done in the report.

Oh... If/when you post code please use [ code ] and [/ code ] (without the spaces) around your code, this preserves the indentations....

quest4
08-12-2008, 05:15 AM
Thanks a lot that did the trick.