print report based on value selected in cboBox

rbemiller

Registered User.
Local time
Today, 04:19
Joined
Apr 17, 2002
Messages
14
My form has a combo box w/ 6 options, all of which have a corresponding report that needs to be printed. How do I have a specific report print based on the value selected in the combo box?

The combo box values are:
Chair - Standard
Chair - Non Standard
LS/Sofa - Standard
LS - Non Standard
Sofa - Nonstandard
OTHER

My current print command code, which works, but only for one specific report, is below:
Private Sub cmdPrint_Click()
On Error GoTo PrintXCopies_Err

Dim Copies As Integer

txtPrtQtyIDtags.SetFocus

Copies = txtPrtQtyIDtags.Text

DoCmd.OpenReport "rptName", acPreview, "", ""

DoCmd.PrintOut acPrintAll, , , acHigh, Copies, False
DoCmd.Close acReport, "rptName"
PrintXCopies_Exit:

Exit Sub
PrintXCopies_Err:

MsgBox Error$

Resume PrintXCopies_Exit
End Sub
 
I'm thinking I can handle this with an IF/Then statement...something like:

If Me.cboCat = "Chair - Standard" Then
'print rptStandardChair
Else
'print rptOTHER
End If

Would this work? And if so, could someone please help me with the code??? I'm lost.
 
Change the OpenReport to refer to the combobox. This statatement will print whichever report is currently selected by the combo:

DoCmd.OpenReport Me.cboCat, acPreview
 
thanks Pat..looks like it work but it say sumting like this...
"The report name 'sumting' u entered either the property sheet or macro misspelled or refer to a report that doesnt exist"

am i missed sumthing there?
 
Hi, I got something similar. But my combo has to filter certain data with a query from which it feeds. I know my case is different but maybe it can be of some use to you:

Code:
Private Sub cmdOpenRpt_Click()
    On Error GoTo Err_cmdOpenRpt_Click
    Dim strWhere As String
    If Not IsNull(Me.cboTypeId) Then
        strWhere = "[TypeId] = " & Me.cboTypeId
    End If
    Dim stDocName As String
    stDocName = "Products"
    'MsgBox "strWhere: " & strWhere
    DoCmd.OpenReport stDocName, acPreview, , strWhere
    
Exit_cmdOpenRpt_Click:
   Exit Sub

Err_cmdOpenRpt_Click:
   Select Case Err
       Case 2501
            'ignore
       Case Else
            MsgBox Err.Description
   End Select
    Resume Exit_cmdOpenRpt_Click
End Sub

That's the code for the combo to open the report & this is for the report in case there is no data (to avoid errors...):
Code:
Private Sub Report_NoData(Cancel As Integer)
   MsgBox "There are no records to report.", _
      vbOKOnly + vbInformation, "No Data"
   Cancel = True
End Sub

It works for me perfectly. I hope it is of some help to you.
 

Users who are viewing this thread

Back
Top Bottom