Report for a specific record

  • Thread starter Thread starter Lindsay
  • Start date Start date
L

Lindsay

I am creating a database that acts as a purchase order system. I need
each purchase order that is processed to create an independent report,
but everything that I have tried creates a report that includes all the
purchase orders that I have created to date. Does anyone have any
suggestions on how to make one report at a time. Any help would be
appreciated!
 
Just include the criteria in the query that you used to build your report.
Or, include a "filter" or "where" statement in your report.

Personally, I would add a button on my forms to do all this. After I view
or add a purchase order, I'd click the button and have it print the P.O. for
the currently displayed record.

Here is code for a button that works in a similar manner. You can modify it
to meet your needs...

--
Rick B



Private Sub cmdPrint_Click()

Dim strWhere As String

If Me.Dirty Then 'Save any edits.

Me.Dirty = False

End If

If Me.NewRecord Then 'Check there is a record to print

MsgBox "Select a record to print"

Else

strWhere = "[ID] = " & Me.[ID]

DoCmd.OpenReport "MyReport", acViewPreview, , strWhere

End If

End Sub



Notes: If your primary key is a Text type field (not a Number type field),
you need extra quotes: strWhere = "[ID] = """ & Me.[ID] & """"

If you want the report to print without preview, replace acViewPreview with
acViewNormal.



See also: http://allenbrowne.com/casu-15.html
 
Thank you for the help, but I forgot to add that openning the report is
part of a macro that updates several other tables as well. Is this
still the correct code? Can I put the WHERE statement in the macro?
 
Anything you can do in a macro, can be done just as easily in code. Just
include whatever updates you are doing in the code. I can't think of any
situation where this would be needed though. You could put the WHERE
statement in the report's record source, but then you'd only be able to run
that report when your form was open. You could always create two versions
of the report. One that only runs with this form and one that the user
could run without the form open.

Lots of options.
 
Back
Top