Can't trap this error

cybhunter

Registered User.
Local time
Today, 12:51
Joined
Sep 11, 2007
Messages
17
Hello,

I have a form based on a parameter query. The form is launched via a command button from another form with vba code. When I click to "Choose Report" (my command button) I am prompted to enter a report numer. If I enter an ID all is happy -- if I click cancel w/o entering anything I get a runtime error 2501 -- The OpenForm operation was cancelled. It works if I click OK w/o any data. The problem is when I click CANCEL.

Does anyone know how to handle this error?

Code:

Private Sub Command2600_Click()
On Error GoTo ErrHandler
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmSearchForMainList"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exithere:
Exit Sub

ErrHandler:
Select Case Err.Number
Case 2501
Resume exithere
Case Else
MsgBox Err.Number & " - " & Err.Description
Resume exithere
End Select
End Sub


Thank you,
Kurt
 
What is the code in the other form? The code you showed should complete just fine as there is nothing to stop it from running and it opens the form. The error will likely be from something on the

frmSearchForMainList

form.
 
2501 is the cancel event. i code my reports to cancel if the query feeding the report returns no records. this event is also triggered if user presses "cancel" from a dialog box like you described. i handle the cancel in the following way:

Report_NoData event:
Code:
Cancel = True
OnClick event from form:
Code:
[COLOR=Red]On Error GoTo Err_cmd160R_Click[/COLOR]

    Dim stDocName As String
    Dim strOpenArg As String

    stDocName = "rptIsolates_Primary"
    
    'strOpenArg = Report "Recordsource; Title; Subline"
    strOpenArg = "qryGENTprimariesNOTdoneRLB;Primary GENT Isolates;RLB to be performed"
    
    DoCmd.OpenReport stDocName, acViewPreview, , , acWindowNormal, strOpenArg

[COLOR=Red]Exit_cmd160R_Click:
    Exit Sub

Err_cmd160R_Click:
    [B]Select Case Err.Number
        Case 2501 ' triggered by a "no data" event (cancel = true) in the report properties
            strMessage = "No purity-confirmed primary isolates in RLB queue."
            MsgBox strMessage, vbOKOnly + vbInformation, "ICU Cycling Study database"
        Case Else
            Msg = "Error # " & Str(Err.Number) & Chr(13) & Err.Description
            MsgBox Msg, vbOKOnly, "ICU Cycling Study database", Err.HelpFile, Err.HelpContext
    End Select[/B]
    Resume Exit_cmd160R_Click[/COLOR]
 

Users who are viewing this thread

Back
Top Bottom