Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code not Sending me Back to Form

Status
Not open for further replies.

gornza

Technical User
Apr 15, 2008
2
0
0
US
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
 
It is best to use forms to get parameters for the report, that way you woukld be able to check if the number existed with DlookUp or a combobox, for example, before opening the report.

Otherwise, you will probably need to use the NoData event of the report and an error trap - 2501 is the number, I think.
 
Can you not create a macro that closes the form and brings up the main one?
 

Use as Select case for more clear picture
Code:
Private Sub cmdOpenReport_Click()
    Select Case Me.GRPIO.Value
    Case Is = 1
        'Report View by Invoice number
    Case Is = 2
        'Report view by Company
    Case Is = 3
        'Print here
    End Select
End Sub

and the "DoCmd.Maximize" is to be behind the report, also you need "DoCmd.Restore" to restore the form's size

________________________________________________________
Zameer Abdulla
Help to find Missing people
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top