Print one record from FORM - Error

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!
 
A

Allen Browne

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top