470,822 Members | 1,230 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,822 developers. It's quick & easy.

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

Seth Schrock
2,965 Expert 2GB
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.OpenModule 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.
Aug 12 '15 #1
4 1265
1,107 Expert 1GB
Something like this might get you close...
Expand|Select|Wrap|Line Numbers
  1. Application.VBE.VBProjects(1).VBComponents("Form_FormName").CodeModule.CodePane.Show
Expand|Select|Wrap|Line Numbers
  1. Application.VBE.ActiveVBProject.VBComponents("Form_FormName").CodeModule.CodePane.Show
Aug 12 '15 #2
Seth Schrock
2,965 Expert 2GB
That opens the module perfectly, but now I need to go to the procedure. Any ideas?
Aug 12 '15 #3
Seth Schrock
2,965 Expert 2GB
Never mind. I found it.
Expand|Select|Wrap|Line Numbers
  1.     Dim lngStartLine As Long
  2.     With Application.VBE.ActiveVBProject.VBComponents(strModule).CodeModule
  3.         .codepane.Show
  4.         lngStartLine = .ProcStartLine(strProcedure, vbext_pk_Proc)
  5.         .codepane.SetSelection lngStartLine, 1, lngStartLine, 1
  6.     End With
Aug 12 '15 #4
1,107 Expert 1GB
That is pretty neat.
Aug 12 '15 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

42 posts views Thread by WindAndWaves | last post: by
2 posts views Thread by windandwaves | last post: by
4 posts views Thread by Brad Parks | last post: by
17 posts views Thread by chris.atlee | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.