I am getting a runtime error in VBA. I have no error-handling and don't really wish to employ this unless necessary. When I get the run-time error window option to End, Debug or Help, I press Debug. The code editor window opens but in my case it highlights in yellow a line "Load Frm" - which is obviously tells me the error has occurred somewhere in the process of loading the form, but I then have to F8 throughout the whole series of routines which are called until I reach the line that has actually caused the error. This can take a long time! Am I missing something?
- 2Sounds like typical debugging to me. You could add error handling, logging, or other techniques to narrow it down some.Brian M Stafford– Brian M Stafford2020-09-25 15:13:54 +00:00Commented Sep 25, 2020 at 15:13
- What is the whole error message?dwirony– dwirony2020-09-25 15:20:04 +00:00Commented Sep 25, 2020 at 15:20
- Thanks Brian. But I don't understand why the default error handling doesn't actually highlight and position the offending line, instead the load statement (which is several 100 lines of code short of the actual error)Ali Wood– Ali Wood2020-09-25 15:37:06 +00:00Commented Sep 25, 2020 at 15:37
- Thanks dwirony, the error itself is immaterial to the question - I could reproduce this with many different type of errors.Ali Wood– Ali Wood2020-09-25 15:38:21 +00:00Commented Sep 25, 2020 at 15:38
- 3Break in class module.BigBen– BigBen2020-09-25 16:07:31 +00:00Commented Sep 25, 2020 at 16:07
2 Answers
I use Google Translator, so there may be some inaccuracies, but I think you understand.
- In the "Tools" menu of the VBA editor select "Options"
- Select the "General" tab
- In the "Error detection" frame select "Abort in class module" and confirm with OK.
1 Comment
In order to quickly find the line with the actual error you can use the following hot keys:
Shift+F8 when pressed on a line containing a procedure will run the whole procedure (even if it contains several lines inside) and then stop at the next line. If you have stepped inside a procedure you can press Ctrl+Shift+F8 to run everything inside it and go to the next line of the outer procedure. In other words if Sub A at line 5 calls Sub B and you stepped into Sub B, pressing Ctrl+Shift+F8 will run everything in Sub B and return to line 6 of Sub A.
Don't forget about breakpoints, they're very useful.