Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code Not showing and working var not declared 3

Status
Not open for further replies.

newToVBA2003

Programmer
Jan 7, 2009
12
US
Hello,
I have 2 questions, I am working on a project in Access 2003 and I can view the code for all of the forms except one. It runs like it is suppose to I just can't view the code for it.

1. Is there anyway to view the code?

I also have an issue with a variable that isn't declared and works fine. It is located in two different code sections, I've looked at all of the code and it's not declared anywhere, not as local or global.

2. How can I locate a variable that is not declared anywhere?
 
Use the Option Explicit instruction at the top of all your code modules.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The project was already setup before I started working on it and it uses "Option Compare Database" every where, by changing it to Option Explicit what will change?
 
Don't CHANGE what's there.

ADD that statement.

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks...In what case would you not want to declare your variables?
 
If you were lazy or did not care if you get errors.

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Now now Skip, be nice.

"In what case would you not want to declare your variables? "

newToVBA2003, the point being is that all good programmers DO declare their variables. Using Option Explicit forces this.

In other words, best-practice is that there is NO case where you would not want to declare your variables.

You seem to have contradictory statements.

"It is located in two different code sections,"

"How can I locate a variable "

Why are you asking about how to locate a variable, if you already state it is located in two code "sections"? I do not really know what you mean by "sections". Do you mean procedures? Do you mean modules?

It is strongly recommended you use Option Explicit. It will save you pain. I would also strongly recommend reading up on Scope.

Gerry
 
It is located in two different code sections,"
I have a list of forms with code behind them. The var in which I am speaking about is used in two different form code behind sections. I don't see where the var was declared for either sections.
 
If you use OPTION EXPLICIT (as mentioned) your code will error if the variable isn't declared. So if it doesn't error when you put it in, then the variable is declared somewhere

As Gerry mentioned scope is also important, if it's used in the code behind two forms then it's entirely possible it may be intended to be used within the just scope of the form(s) (independantly of each other) or that it may be intended to be used globally (i.e. declared in a module where both forms can access it).

How the variable is intended to be used would affect where in the code (and how, Private, Public etc.) you would declare it if you find it's not already declared.

Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
If a variable is not explicitly declared, it is implicitly declared on first use.

As for your question no. 1: an Access Form does not necessarily have VBA code.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top