What I am trying to do in the following is prompt a user to enter an invoice number. If the invoice number is in the table, then bring up the Invoice Report. If the invoice number is not in the table, then display a messagebox stating so, and when the user clicks ok to that message box, to take them back to the main form. When I enter an invoice number that is not in the database , the messagebox comes up, I click ok, but the blank invoice remains on the screen, which is not what I want it to do.. The following is my code......
On Error GoTo CMDpreviewInvoiceReport_Click_Err
'note, below GRPIO is the name of the Form containing the option buttons.
If (GRPIO = 1) Then
' Select by Invoice #
DoCmd.OpenReport "INVOICE REPORT", acViewPreview, "", "[INVOICE QUERY].[Invoice Number]=[What Invoice Number?]", acNormal
On Error GoTo CMDpreviewInvoiceReport_Numb_Err
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
CMDpreviewInvoiceReport_Numb_Err:
MsgBox "That Invoice number does not exist"
Resume CMDpreviewInvoiceReport_Click_Exit
CMDpreviewInvoiceReport_Click_Exit:
Exit Sub
CMDpreviewInvoiceReport_Click_Err:
MsgBox Error$
Resume CMDpreviewInvoiceReport_Click_Exit
End Sub
On Error GoTo CMDpreviewInvoiceReport_Click_Err
'note, below GRPIO is the name of the Form containing the option buttons.
If (GRPIO = 1) Then
' Select by Invoice #
DoCmd.OpenReport "INVOICE REPORT", acViewPreview, "", "[INVOICE QUERY].[Invoice Number]=[What Invoice Number?]", acNormal
On Error GoTo CMDpreviewInvoiceReport_Numb_Err
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
CMDpreviewInvoiceReport_Numb_Err:
MsgBox "That Invoice number does not exist"
Resume CMDpreviewInvoiceReport_Click_Exit
CMDpreviewInvoiceReport_Click_Exit:
Exit Sub
CMDpreviewInvoiceReport_Click_Err:
MsgBox Error$
Resume CMDpreviewInvoiceReport_Click_Exit
End Sub