WHERE in "open Report"

  • Thread starter Thread starter Rover
  • Start date Start date
R

Rover

I have a button on a form from where I run this:

DoCmd.OpenReport "Customers", acViewPreview, , CustomerID = 1

I've hard coded the customerID as 1 . It is an autonumber. The report
runs, the command does not error off, but I get all customers returned.

Ideas?

TIA
Jim
 
Rover said:
I have a button on a form from where I run this:

DoCmd.OpenReport "Customers", acViewPreview, , CustomerID = 1

I've hard coded the customerID as 1 . It is an autonumber. The report
runs, the command does not error off, but I get all customers returned.

The WHERE clause need to be in quotes.

DoCmd.OpenReport "Customers", acViewPreview, , "CustomerID = 1"
 
Hi Jim

In addition to what Rick said, I assume you have hard-coded 1 only for
testing purposes, and that in due cource you will want to use a variable or
the current value of a form control. In this case, you will need to
construct the string using the & operator - for example:

DoCmd.OpenReport "Customers", acViewPreview, , _
"CustomerID = " & Me!CustomerID
 
Back
Top