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
Please note, this is asked and answered all the time. In the future, I'd
suggest you search for your answers before posting a new thread. The
easiest way I have found is to go to
www.google.com, click the "groups"
option, and enter a search string similar to the following...
microsoft.public.access report current record
--
Rick B
Dryder said:
I have button on a form that opens up a report, is there any way to have
the
report open with the current record that's on the form? I have Auto number
field on the form, but I don't want the user to have to type the number in
to
open the report to that record, I want the report to open with the current
record automatically. Thanks in advance.