Need code for invalid (non-existing) Invoice#

G

Gornza

Hi, the following is code I have that , when the option is chosen, the user
will be prompted about what invoice # they want to display. Also if nothing
is entered, they will be kicked out ot the main screen.
What I am wondering what to code is how to handle when an Invoice # is
entered but that number does not exist (I want them to get a message box
saying such): Here is my code so far:
******
Private Sub CMDpreviewInvoiceReport_Click()

'On Error GoTo CMDpreviewInvoiceReport_Click_Err

'note, below GRPIO is the name of the Form containing the option buttons.
On Error GoTo CMDpreviewInvoiceReport_Numb_Err
' Select by Invoice #
If (GRPIO = 1) Then
'prompt user for invoice number....

DoCmd.OpenReport "INVOICE REPORT", acViewPreview, "", "[INVOICE QUERY]
..[Invoice Number]=[What Invoice Number?]", acNormal
'If user hits the "cancel" button they will be brough back to Main
Menu Screen

End If
DoCmd.Maximize
If (GRPIO = 2) Then
' Select by Company
DoCmd.OpenReport "INVOICE REPORT", acViewPreview, "", "[INVOICE QUERY]
..[Company]=[What Company?]", acNormal
End If
DoCmd.Maximize
If (GRPIO = 3) Then
' Select ALL Invoices
DoCmd.OpenReport "INVOICE REPORT", acViewPreview, "", "", acNormal
End If
DoCmd.Maximize


Exit Sub

CMDpreviewInvoiceReport_Numb_Err:
Select Case Err.Number
Case 2501 ' The OutputTo action was cancelled
Resume CMDpreviewInvoiceReport_Numb_Err 'allows rest of code to process
please don't show Dave the 2501 error access
End Select



End Sub
 
J

Jeff Boyce

By forcing the user to remember (EXACTLY) the Invoice# and/or Company,
you're making your users work a lot harder than they have to.

An alternate approach would be to provide a form on which you have a
combobox listing Invoice#(s) and another combobox listing Company(ies).
After the user indicates his/her selection (picking from a list is easier
than remembering), clicking a <Get me this report> button would open the
report, with the selection criteria passed along as part of the WHERE clause
(see the syntax for DoCmd.OpenReport ...).

Regards

Jeff Boyce
Microsoft Office/Access MVP
 

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