Variable Not Defined

B

Brad

I am working with a number of large VBA modules. Several times while
reviewing the code, I have hit the wrong key by accident and unintentionally
changed a line of code. Sometime later, I will try to use the module and I
receive the message “Variable Not Definedâ€. The problem is that because some
of these modules are quite large, it is very difficult to find the line of
code that I accidentally changed.

I have worked with several other programming languages over the years, but I
am new to VBA. All of the other languages that I have worked with in the
past would point out the offending line in a situation like this. Is there a
way to get VBA to explicitly tell which variable it is complaining about?

Thanks,
Brad
 
J

John W. Vinson

I am working with a number of large VBA modules. Several times while
reviewing the code, I have hit the wrong key by accident and unintentionally
changed a line of code. Sometime later, I will try to use the module and I
receive the message “Variable Not Defined”. The problem is that because some
of these modules are quite large, it is very difficult to find the line of
code that I accidentally changed.

I have worked with several other programming languages over the years, but I
am new to VBA. All of the other languages that I have worked with in the
past would point out the offending line in a situation like this. Is there a
way to get VBA to explicitly tell which variable it is complaining about?

Thanks,
Brad

Put a line at the very beginning of every module (before the first Sub or
Function declaration):

Option Explicit

When you compile the database, this will flag every line containing an
undimensioned variable as an error. It's essential security, and I have no
idea why it's not automatically specified!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top