Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Denmark
    Posts
    347
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Error messages (VBA generally (my is O2K, UK))

    Hi,

    This may be one of the silly ones...

    Would anyone know, if it is possible to get an error message to display, in eg. a variable, both the name of the module and the name of the procedure that caused the error... ??


    Thanks,
    ;o)) Henrik
    Bests,
    RD


    PS: Wish there were a knob on the TV to turn up the intelligence. There's a knob called "brightness," but that doesn't work

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

    Re: Error messages (VBA generally (my is O2K, UK))

    There is no standard feature in VBA to do what you want. You can create your own error handling, or use a utility for this. Office Developer Edition has an add-in for creating error handlers, and you can also use MZ Tools for this (free).

    Home-grown error handling could look like this:

    (in a module basUtilities)

    Sub MyProcedure()
    On Error GoTo ErrHandler

    ... ' Your code here

    ExitHandler:
    ' Cleaning up here
    Exit Sub

    ErrHandler:
    MsgBox Err.Description, vbExclamation, "basUtilities - MyProcedure"
    Resume ExitHandler
    End Sub

  3. #3
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Denmark
    Posts
    347
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error messages (VBA generally (my is O2K, UK))

    Thanks Hans,

    Feared you would say this...
    Having to add it as separate code does take a bit of the flexibility out of it. (Then I have to code modName and ProcedureName anyway - somewhere...)

    What I had hoped for was to be able to do something like Err.Number & ":" & Err.Description & " (" & Err.modName & ";" & Err.ProcName & ")"
    - but apparently this is not a way forward - pitty though.


    ;o)) Henrik
    Bests,
    RD


    PS: Wish there were a knob on the TV to turn up the intelligence. There's a knob called "brightness," but that doesn't work

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

    Re: Error messages (VBA generally (my is O2K, UK))

    If you look up the Err object in the online help, or in the Object Browser (F2), you will see that it has a property Source, but that is the entire "project" (Word doc, Excel workbook, ...). There are no properties that refer to the procedure or module.

  5. #5
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Denmark
    Posts
    347
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error messages (VBA generally (my is O2K, UK))

    I had noted exactly that and thought the logical extension would be modName and ProcName
    - but I couldn't find these so apparently MS thought otherwise, my second hope was then that some of you clever guys out there had made some sort of a tweak for this...

    Thanks anyway
    Bests,
    RD


    PS: Wish there were a knob on the TV to turn up the intelligence. There's a knob called "brightness," but that doesn't work

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

    Re: Error messages (VBA generally (my is O2K, UK))

    Take a look at the EH procedure written by <!profile=st3333ve>st3333ve<!/profile> in <post#=280572>post 280572</post#> - it is in the Access forum but should work in VBA in other apps too. You need to set a reference to Microsoft Visual Basic for Applications Extensibility 5.3 in Tools | References...

Posting Permissions

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