While Loop error can't find the field referred to in your expression.

  • Thread starter gmazza via AccessMonster.com
  • Start date
G

gmazza via AccessMonster.com

Hey there,
I have a While loop at the end of my VBA code and I keep getting an error
that is making no sense to me. Here is the end of my code:
While intCount <= 29
intCount = intCount + 1
Me.Controls("Label" & intCount).Visible = False
Wend

I get the error that my for can't find the field Label29 referred to in your
expression.
When I put my mouse over the intCount, it says intCount = 29
So why is it even going into the While condition if the intCount = 29?

Any help is appreciated.
 
D

Dirk Goldgar

gmazza via AccessMonster.com said:
Hey there,
I have a While loop at the end of my VBA code and I keep getting an error
that is making no sense to me. Here is the end of my code:
While intCount <= 29
intCount = intCount + 1
Me.Controls("Label" & intCount).Visible = False
Wend

I get the error that my for can't find the field Label29 referred to in
your
expression.
When I put my mouse over the intCount, it says intCount = 29
So why is it even going into the While condition if the intCount = 29?

Any help is appreciated.


Your While statement says to loop while intCount is less than *or equal to*
29.
 
G

gmazza via AccessMonster.com

I apologize, my code is While intCount <= 28 and the error is on Label29.
I even follow the code through the debug and it literally goes into the While
loop when the value is 29, its weird.


Dirk said:
Hey there,
I have a While loop at the end of my VBA code and I keep getting an error
[quoted text clipped - 11 lines]
Any help is appreciated.

Your While statement says to loop while intCount is less than *or equal to*
29.
 
C

Clifford Bass

Hi,

No weirdness. It is doing exactly what you are telling it to do. It
goes into the loop when the count is 28, adds 1 to the count and then
attempts to access Label29. Perhaps you should increment the count after
dealing with the label instead of before:

intCount = 1 ' or whatever the first label uses
While intCount <= 28
Me.Controls("Label" & intCount).Visible = False
intCount = intCount + 1
Wend

Or use intCount <= 27. Or use intCount < 28.

Clifford Bass
 

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