default to print selected records in Access

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

Guest

The default print range for printing forms in Access is to print all. I
would like to change the print range default so that selected records are
printed. How do I do this?
 
You don't print forms, you print reports.

Build a report to print waht you want, then add a button on your form to
print the report. If you would only like that report to print he CURRENT
record, you can use the following code. If you want to ask for a range of
records, I'd probably include a prompt in my report's query to ask the user
for a start and stop number.

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.
 

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