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

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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).
<<<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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.