Print one record from FORM - Error

  • Thread starter Thread starter Bill
  • Start date Start date
B

Bill

I am getting a strange error when I print from a VB Script. The error is:

Syntax error in date in query expression '(Report # = 08-001)'

The script is:

DoCmd.OpenReport "IR_Report", acPreview
Reports![IR_Report].Filter = "Report # = " & Me![Report]
Reports![IR_Report].FilterOn = True

The report name is IR_Report
The primary key field name is Report

Theres no date anywhere in the VB. Why is this happening????? Thx!
 
There are 2 problems with the filter string:

a) You need square brackets around the Report # field name, since it
contains non-alphanumeric characters.

b) You need quotes around the 08-001 value. (I'm assuming that Report # is a
Text field, as it contains non-numeric characters.)

It would also be more efficient to apply the filter before opening the
report. Try:
Dim strWhere As String
strWhere = "[Report #] = ""08-001"""
DoCmd.OpenReport "IR_Report", acViewPreview, , strWhere

For more details, see:
Print the record in the form
at:
http://allenbrowne.com/casu-15.html
 
Back
Top