open report where condition

R

Raul Sousa

I have this code:
DoCmd.OpenReport "Report", acViewPreview, "", "DocID = """ & Me.DocID &
"""", acNormal

My problem is with the where condition ("DocID = """ & Me.DocID & """").
This is opening the report on the first record, always.
It should be opening the report on the current record instead.

I can’t see what is wrong.
 
L

Larry Linson

You have the WhereCondition coded as though DocID is a Text Field. If it is
a Numeric Field (including AutoNumber), the WhereCondition should read:

"DocID = " & Me.DocID

Larry Linson
Microsoft Access MVP
 
K

Klatuu

Take the "" out of the third argument

DoCmd.OpenReport "Report", acViewPreview, , "DocID = """ & Me.DocID &
"""", acNormal
 
R

Raul Sousa

this is a text field, and the "" from the third argument made no diference.
is opens always and only the first record.


"Klatuu" escreveu:
 
L

Larry Linson

Is it possible that you have the same name, DocID, for the Field and for the
Control? If so, perhaps that is confusing Access.

As a help in debugging, instead of using the string, as you have, in the
WhereCondition, create the string in a variable "strWhere" to which you
refer in the WhereCondition, and display it in a MsgBox immediately before
the DoCmd.OpenReport to assure that you have what you think you have as the
Where Condition.

Larry Linson
Microsoft Access MVP
 
S

Steve Schapel

Raul,

Did you notice also that Klatuu added an extra comma to the code? Your
original was missing a comma.

Try it like this...
DoCmd.OpenReport "Report", acViewPreview, , "DocID = '" & Me.DocID & "'"
 

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