I agree with June7. A form is a better idea displaying all relevant vendor data. Put a series of command buttons to open the various reports you require for each vendor, or a single command button to open a menu of reports available to print.
In the OnClick Event of the Command Button, put this code:
Code:
DoCmd.OpenReport "YourReportName", acViewPreview, "", "[VendorName]=[Forms]![YourFormName]![VendorName]"
DoCmd.SelectObject acReport, "YourReportName"
Or if you choose the menu option, put this code in the OnClick Event of the Command Button on the form:
Code:
DoCmd.OpenForm "YourMenuFormName", acNormal, , , , acWindowNormal
DoCmd.SelectObject acForm, "YourMenuFormName""
Of course you would have to create the print menu form. I would use option buttons labelled with each report type to print (call it Frame0), and 2 Command buttons labelled "Print" and "Cancel".
In the OnClick event of the Print Button on the menu form, put this code:
Code:
Private Sub btnPrint_Click()
On Error GoTo Err_btnPrint_Click
'To open the selected report in Print Preview
Select Case Me.Frame0.Value
Case 1 'If the user selects Invoice
DoCmd.OpenReport "rptInvoice", acViewPreview, "", "[VendorName]=[Forms]![YourVendorFormName]![VendorName]"
DoCmd.Close acForm, "frmPrintMenu", acSaveNo
DoCmd.SelectObject acReport, "rptInvoice"
Case 2 'If the user selects Order report
DoCmd.OpenReport "rptOrder", acViewPreview, "", "[VendorName]=[Forms]![YourVendorFormName]![VendorName]"
DoCmd.Close acForm, "frmPrintMenu", acSaveNo
DoCmd.SelectObject acReport, "rptOrder"
Case 3 'If the user selects Something Else
DoCmd.OpenReport "rptSomethingElse", acViewPreview, "", "[VendorName]=[Forms]![YourVendorFormName]![VendorName]"
DoCmd.Close acForm, "frmPrintMenu", acSaveNo
DoCmd.SelectObject acReport, "rptSomethingElse"
Case 4 'And so on....
Put Code Here....
End Select
Exit_btnPrint_Click:
Exit Sub
Err_btnPrint_Click:
MsgBox Err.Description, vbInformation, "Error"
Resume Exit_btnPrint_Click
End Sub
You would use as many case statements as you have option buttons on the print menu form. Just make sure you include the WHERE clause in the OpenReport statement (shown in red). That way it will only print the report for the vendor you have the main form open to.
In the OnClick event of the Cancel Button on the print menu form, put this code:
Code:
Private Sub Cancel_Click()
DoCmd.Close acForm, "frmPrintMenu", acSaveNo
End Sub
Hope this helps.
Wayne