WHERE in "open Report"

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
 
R

Rick Brandt

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"
 
G

Graham Mandeno

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
 

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