print one record in a form without all the records in the table p

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

Guest

I created a form to entire customer information. I then created a report to
print this information. I made a button to print the information. I thought
everything print fine until I relized that all the old records in that table
also printed. How can I print just the information in the form that I am
working on?
 
Please be sure to search for previous posts before posting a new one. This
is a pretty common question...

Button to print specific record
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
 

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