Ms access Option Explicit

Hi I declared at module  as
Option Compare Database
Option Explicit
Dim var_part_del_participant(100) As String
Dim var_counter As Integer
Dim var_selected_records As Integer


But in i have a lot of code in a form_current sub


I keep gettting the error as variable not defined

You use the Option Explicit statement to protect your modules from having undeclared variables and to eliminate the possibility of inadvertently creating new variables when typographical errors occur. This error has the following cause and solution:

You used an Option Explicit statement to require the explicit declaration of variables, but you used a variable without declaring it.
Explicitly declare the variable, or change the spelling of the variable to match that of the intended variable.

For additional information, select the item in question and press F1 (in Windows) or HELP (on the Macintosh).

what should i do . I need the declaration of those variables declared as option expicit. because i using those variables in different events in the same module/. so what to do

vihaanAsked:
Who is Participating?
 
puppydogbuddyCommented:
<<<what should i do . I need the declaration of those variables declared as option expicit. because i using those variables in different events in the same module/. so what to do>>>

If a variable is referenced by more than one sub procedure, declare it once in the declarations section of the module on the line following Option Explicit, instead of declaring it in each sub procedure.  If the variable is referenced by more than one class (e.g.form) module, declare it once in a standard module as a global variable.
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
"Option Explicit" means that VBA requires you to declare your variables before using them. Without setting Option Explicit, I can write this:

myValue = SomeField * 4.3

and then later use the myValue variable as I need. The problem comes when you refer to that variable incorrectly:

myValue = SomeField * 4.3
<more code>
SomeOtherValue = my_value + 6

The compiler will throw an error, because it has no concept of "my_value".

Your error means that somewhere you have used a variable that you haven't defined correctly (normally just a typo). To find it, try to Compile your VBA code - from the VBA editor, click Debug - Compile and the compiler should find it (and any other errors you may have).
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.