Access Printing

L

Linda

when I go into my access database and want to print I have to always remember
to click on selected record for it to print only that page or it will print
the whole database. How can I set the database to always print only the one
page?
 
R

Rick B

You print reports, not tables, forms, or queries. If you want a record to
print, build a report and include a filter.

Personally, I create a report and add a button to my form. When I click the
button, it prints the report for whatever record I am viewing. I have used
this to print "employee worksheets" and "project tickets" etc.

Here is the code that would be tied to a button to print a report for the
current 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
 
S

Scott

Boy am I glad I read this, it helped me get something fixed in one of my
databases. It was very thoughtful of you to include the differences for TEXT
Primary ID fields.

Thanks,
Scott


Rick B said:
You print reports, not tables, forms, or queries. If you want a record to
print, build a report and include a filter.

Personally, I create a report and add a button to my form. When I click the
button, it prints the report for whatever record I am viewing. I have used
this to print "employee worksheets" and "project tickets" etc.

Here is the code that would be tied to a button to print a report for the
current 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





--
Rick B



Linda said:
when I go into my access database and want to print I have to always
remember
to click on selected record for it to print only that page or it will
print
the whole database. How can I set the database to always print only the
one
page?
 
Top