BetaMike said:
In an effort to reduce switching from 'Forms' to 'Reports' all the time, I
inserted a 'Print' command button on a form that points to the relevant
report.
Can I set it up so that it only prints the current record? It tried to
print
105 reports earlier!
Here are 2 simple possible examples.
(change pk, rptMyReport, txtpk to match your
field name, report name, textbox name)
The first assumes a primary index of type string
shown in textbox "txtpk" on form:
Private Sub cmdPreviewReport_Click()
On Error GoTo Err_cmdPreviewReport_Click
Dim stDocName As String
Dim strWhere As String
Const cQuote = """"
stDocName = "rptMyReport"
strWhere = "[pk] = " & cQuote & Me!txtpk & cQuote
DoCmd.OpenReport stDocName, acPreview, , strWhere
Exit_cmdPreviewReport_Click:
Exit Sub
Err_cmdPreviewReport_Click:
MsgBox Err.Description
Resume Exit_cmdPreviewReport_Click
End Sub
///////////////////////////////////////////////////////////////////////
If primary index is of type Long and shown
in textbox "txtpk" on form:
Private Sub cmdPreviewReport_Click()
On Error GoTo Err_cmdPreviewReport_Click
Dim stDocName As String
Dim strWhere As String
stDocName = "rptMyReport"
strWhere = "[pk] = " & CLng(Me!txtpk)
DoCmd.OpenReport stDocName, acPreview, , strWhere
Exit_cmdPreviewReport_Click:
Exit Sub
Err_cmdPreviewReport_Click:
MsgBox Err.Description
Resume Exit_cmdPreviewReport_Click
End Sub