print specific reports

C

coconut78

I have a report - that gets its data from a query - and I have a form that
lists the results from the query.

I would like to put a command button next to each record, and which ever
button I click, it will print only that data, not the entire query.

Can anyone help me please? I've been working on this all day and I'm going
nowhere fast.
 
R

Rick B

Asked and answered pretty often in here...

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

See also: http://www.databasedev.co.uk/print_form_record.html
 
C

coconut78

Thanks man, you're the greatest

Rick B said:
Asked and answered pretty often in here...

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

See also: http://www.databasedev.co.uk/print_form_record.html


--
Rick B



coconut78 said:
I have a report - that gets its data from a query - and I have a form that
lists the results from the query.

I would like to put a command button next to each record, and which ever
button I click, it will print only that data, not the entire query.

Can anyone help me please? I've been working on this all day and I'm going
nowhere fast
 
Top