Selecting a report to print based on selected data

D

David Pelizzari

I am working on an existing database where users are printing reports for
labelling small items (labels). Recently, the users have asked to modify the
label so it doesn't print two fields for a particular type of item (type C
and D). I would like to give them a single button to click to print the
label, and have the logic determine which report to run.

I have a field on the report for Type, text field of one character long.
The user's select the record from a listbox, then moved to another form to
select which printer to print to. Here is the code I have so far, but it
doesn't seem to pick the report if the type matches. I have set this up as a
preview, since I don't want to waste labels. Each label (report) is set to
print to a specific printer.

Private Sub Preview_Layout_Click()
On Error GoTo Err_Preview_Layout_Click
Dim stDocName As String
Dim stDocName1 As String
Dim stType1 As String
Dim stType2 As String
stDocName = "rptLabel03"
stDocName1 = "rptLabel02"
stType1 = "D"
stType2 = "C"
If Me.Type = stType1 Or Me.Type = stType2 Then
DoCmd.OpenReport stDocName1, acPreview, , Me.OpenArgs
Else
DoCmd.OpenReport stDocName, acPreview, , Me.OpenArgs
End If
DoCmd.Close acForm, "frmLabelSel"
Exit_Print_Layout_Click:

Exit_Preview_Layout_Click:
Exit Sub

Err_Preview_Layout_Click:
MsgBox Err.Description
Resume Exit_Preview_Layout_Click

End Sub
 

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

Top