Forms - Printing

G

Garry

I have a from that I would like to add a command button to that will print
only the current record. Is this possible & how do I do it?

Thanks -- Garry Gross
 
D

Dirk Goldgar

Garry said:
I have a from that I would like to add a command button to that will
print only the current record. Is this possible & how do I do it?

Forms aren't really very good for printing. Your best bet is to create
a report that shows the same information, and even looks like your form
if you want -- you can even use the File -> Save As... menu item to save
your form as a report -- and then create a command button with a Click
event procedure similar to :

'----- start of example event procedure -----
Private Sub cmdPrintRecord_Click()

DoCmd.OpenReport "YourReportName", _
WhereCondition:="YourPKField=" & Me!YourPKField

End Sub
'----- end of example event procedure -----

The above assumes that your form has a primary key field named
"YourPKField". It will print the report directly, rather than opening
it in Print Preview, but only a small change would be needed to do that.
 
6

'69 Camaro

Hi, Garry.
I have a from that I would like to add a command button to that will print
only the current record. Is this possible & how do I do it?

Forms aren't really meant for printing. That's what reports are for. But
yes, it's possible if you have Access 2003. It may work on Access 2000 and
2002, but I don't think it works on Access 97 and earlier versions.

If your form is displaying a record of a table with a primary key, then try:

Private Sub PrtRecBtn_Click()

On Error GoTo ErrHandler

DoCmd.OpenForm Me.Name, , , "ID = " & Me!txtID.Value
DoCmd.OpenForm Me.Name, acPreview
DoCmd.PrintOut acSelection

Exit Sub

ErrHandler:

MsgBox "Error in PrtRecBtn_Click( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear

End Sub

.... where txtID is the name of the text box displaying the primary key and
ID is the primary key.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
Top