Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Calling Curiousty (A2K)

    As always, I look for a way to cut down the amount of code in a module.

    Throughout my stuff, I run a lot of reports and have a need to use the <> 2501 On Error routine as
    displayed below.

    Is there any way that this could be defined once only and "Called" within each On Click Run My Report Code either at the single module level or Publicly throughout the System?


    '==============================================
    Private Sub prv_120a_Click()
    strFunction = "F00_Function Like '11'"
    strService = "F01_RA_Service Like 'Regul*'"
    strRA = "F01_RA_No Like '1110'"
    '------------------------------------------
    strCombine = strFunction & " AND " & strService & " And " & strRA
    '------------------------------------------
    On Error GoTo Err_Click
    DoCmd.OpenReport ReportName:="rpt 00120 - Fuji", View:=acViewPreview, _
    WhereCondition:=strCombine
    DoCmd.RunCommand acCmdZoom75
    Exit Sub
    Err_Click:
    If Err <> 2501 Then
    MsgBox Err.Description, vbExclamation
    End If
    End Sub
    '==============================================

    Ps. Curiousity killed the . . .
    Cheers,
    Andy

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Calling Curiousty (A2K)

    You could create a procedure in a general module (the kind you create by selecting Insert | Module in the Visual Basic Editor):

    Public Sub ErrorHandler(obj As ErrObject)
    If Not obj.Number = 2501 Then
    MsgBox obj.Description, vbExclamation
    End If
    End Sub

    Change the error handling section of your code as follows:

    Err_Click:
    Call ErrorHandler(Err)
    End Sub

  3. #3
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calling Curiousty (A2K)

    Hans,

    I'm seriously thinking of changing my signature to:

    Cheers & Thanks, Hans

    But in the meantime, Thanks Hans, accurate and complete as always
    Cheers,
    Andy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •