How to navigate to specific procedure in a module or class module

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    How to navigate to specific procedure in a module or class module

    Thanks to TheSmileyCoder' s Access Crash Reporter, I get an email when an error occurs in my database. Part of the information in the email is the name of the module/class module and the name of the procedure in which the error occurred. I would like to be able to copy this information into a procedure that would take me to the specified procedure.

    I already have the code in place to take the string "Error 52 has occured in procedure [AttachFile] in module [modTreeView] on line [60] on the following code:" and get the module and procedure name from that (using RegEx), but now I'm stuck on how to go to that place in my code. If the module is a regular module and not a form's class module, then I can use the DoCmd.OpenModul e command, but it errors out saying that it can't find the module if I try to use it to open a form's class module.
  • jforbes
    Recognized Expert Top Contributor
    • Aug 2014
    • 1107

    #2
    Something like this might get you close...
    Code:
    Application.VBE.VBProjects(1).VBComponents("Form_FormName").CodeModule.CodePane.Show
    or
    Code:
    Application.VBE.ActiveVBProject.VBComponents("Form_FormName").CodeModule.CodePane.Show

    Comment

    • Seth Schrock
      Recognized Expert Specialist
      • Dec 2010
      • 2965

      #3
      That opens the module perfectly, but now I need to go to the procedure. Any ideas?

      Comment

      • Seth Schrock
        Recognized Expert Specialist
        • Dec 2010
        • 2965

        #4
        Never mind. I found it.
        Code:
            Dim lngStartLine As Long
            With Application.VBE.ActiveVBProject.VBComponents(strModule).CodeModule
                .codepane.Show
                lngStartLine = .ProcStartLine(strProcedure, vbext_pk_Proc)
                .codepane.SetSelection lngStartLine, 1, lngStartLine, 1
            End With

        Comment

        • jforbes
          Recognized Expert Top Contributor
          • Aug 2014
          • 1107

          #5
          That is pretty neat.

          Comment

          Working...