Print single record based upon current form

Lanason

Registered User.
Local time
Today, 18:34
Joined
Sep 12, 2003
Messages
258
I need to Print a single record from a form but using a report layout.

I have created the form and created a report. A button on the Form kciks off the print but I get all records rather than just the one shown on the Form. Whats a really simple way of just selecting the Current record.

Where do I put an instruction saying print only this record:confused:
 
Put this bit of code in the OnClick property of you CommandButton.

This assumes that your [YourRecordID] is numeric

Private Sub cmdPrint_Click()
If Me.Dirty Then
' Make sure the record is saved
RunCommand acCmdSaveRecord
End If
DoCmd.OpenReport "rptYourReportName", acViewPreview, , "[YourRecordID] = " & Me.[YourRecordID]
End Sub

Use this if [YourRecordID] is Text

Private Sub cmdPrint_Click()
If Me.Dirty Then
' Make sure the record is saved
RunCommand acCmdSaveRecord
End If
DoCmd.OpenReport "rptYourReportName", acViewPreview, ,"[YourRecordID] = " & Chr(34) & Me.[YourRecordID] & Chr(34)
EndSub


You'll have to change the rptYourReportName and YourRecordID.

If you want the Report to print to your printer, change "acViewPreview"
to acNormal.

Hope this helps
 
Last edited:
I put that code in and changed the names of the records and reports. When I click the print button, nothing happens. What could be the problem?
 
Put this in your click event code:

MsgBox "Ihave been clicked"

What happens?
 
Something should happen even an error.

Can you attach a striipped down of your dataBase zipped (100k or under)
 
I'm trying get this working as well but still get all records displayed

I've done the code as follows

Code:
Private Sub cmdPrint_Click()
If Me.Dirty Then
    RunCommand acCmdSaveRecord
End If
    DoCmd.OpenReport "Tapehardcopy", acViewPreview, , "[01/01/2006] = " & Me.[01/01/2006]
End Sub


Private Sub Command83_Click()
On Error GoTo Err_Command83_Click

    Dim stDocName As String

    stDocName = "Tapehardcopy"
    DoCmd.OpenReport stDocName, acViewPreview

Exit_Command83_Click:
    Exit Sub

Err_Command83_Click:
    MsgBox Err.Description
    Resume Exit_Command83_Click
    
End Sub
 
Hey guys

How are you? i´m new to access. Í was having some problems in printing a form, because i only wanted to print the current record but it would print all records.
I tried to do as you posted here and inserted the code. It worked.
Then i changed acViewPreview for acNormal and nothing happened.Each time i click the button nothing happens. why do you think it can show me the print preview (acViewPreview) but it cant print (acNormal).
Thanks for your help,
João
 
Lanason said:
I need to Print a single record from a form but using a report layout.

I have created the form and created a report. A button on the Form kciks off the print but I get all records rather than just the one shown on the Form. Whats a really simple way of just selecting the Current record.

Where do I put an instruction saying print only this record:confused:
I just used the wizard. Drop a command button on to the form and choose print record. It prints the current record as seen on the form though, not from a report.
 
It prints the current record as seen on the form though, not from a report.
You don't print forms you print reports.
 

Users who are viewing this thread

Back
Top Bottom