I have the Microsoft Office Access 2003 InsideOut book -- on which page does
it discuss the invoice report? I can look at the book and likely tell you
how to modify the sample database's form.
In the meantime, I am going to assume that you want to open a form that will
let you print the invoice for a specific customer order number.
Create a form; let's call it frmPrintInvoice.
On that form, in the Detail section, put a command button and a combo box.
Name the button cmdPrint, and the combo box cboInvNumber.
Use this SQL statement as the RowSource property of cboInvNumber (if my
field and/or table names are wrong, change them to the correct names):
SELECT [Order Number]
FROM Orders
ORDER BY [Order Number] DESC;
We'll use this VBA programming for the Click event of the cmdPrint button (I
am assuming that the field [Order Number] is a numeric field in this code;
if it's a text field, a slight modification will be needed, and I've put
that modification as a separate step in the code, but commented out):
' Start of code
Private Sub cmdPrint_Click()
If Len(Me.cboInvNumber.Value & "") > 0 Then
DoCmd.OpenReport "NameOfYourInvoiceReportGoesHere", _
, , "[Order Number]=" & Me.cboInvNumber.Value
' if [Order Number] is a text field, use the next "two" code steps in
' place of the "two" steps above
' DoCmd.OpenReport "NameOfYourInvoiceReportGoesHere", _
' , , "[Order Number]='" & Me.cboInvNumber.Value & "'"
Else
MsgBox "Select an order number.", vbInformation, _
"Select Order Number"
End If
End Sub
' End of code
The above code will need to be assigned to the button's click event. Easiest
way to do that is click on the command button, open Properties window while
the form is open in design view, click on the Event tab, click in the box
next to On Click, click on "three-dot" button at far right of box, select
"event procedure" from the popup window (if it shows), and then paste the
code into the VB Editor window when it appears (note that the VBE will have
the "Private Sub cmdPrint_Click()" line, a blank line, and the "End Sub"
line showing. Paste all the code steps from above (without the Private Sub
and End Sub steps) into the blank line.