open report where condition

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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
 
Take the "" out of the third argument

DoCmd.OpenReport "Report", acViewPreview, , "DocID = """ & Me.DocID &
"""", acNormal
 
this is a text field, and the "" from the third argument made no diference.
is opens always and only the first record.


"Klatuu" escreveu:
 
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
 
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

Back
Top