Data type mismatch in criteria expression

darreno

Registered User.
Local time
Today, 14:16
Joined
Jun 16, 2007
Messages
54
I am getting an error message when clicking on a preview button to retreive a report for the record shown and can't figure out why. The code is

Private Sub PrintPreview_Click()

Dim strReportName As String
Dim strCriteria As String

strReportName = "rptSales"
strCriteria = "[sales_id]=" & Me![sales_id] & ""
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

End Sub


Attached is the db. Thanks for any help.
 

Attachments

You were just missing a couple of single quotes:

strCriteria = "[sales_id]='" & Me![sales_id] & "'"
 
By the way, you really should store it as a number (if it will never have text in it). And, you should make it your primary key in the table, if it will never have duplicate numbers. If it will, you should probably use an autonumber field as your primary key and use that for opening your reports, etc.
 
Thank you very much. Its working now and I have changed the field to number & primary key.
 

Users who are viewing this thread

Back
Top Bottom