Use of For Each

  • Thread starter Thread starter Hallgeir
  • Start date Start date
H

Hallgeir

In my report code I have a format event for the toptext on page section. I
need to go trough every label in the section and do a couple of things like
setting the caption and the borderstyle. I belive it's a good idea to use
the for each statement, but I can't figur out what to use instead of the
questions mark in my example.
Example:
For Each ??? in ???
Label.caption="x"
Next

I hope someone can help me. Do I need to declare any variables?
Thanks!

Hallgeir
 
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Type = acLabel Then
ctl.Caption = "my caption"
End If
Next ctl
 
"Ken Snell [MVP]" wrote in message
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Type = acLabel Then
ctl.Caption = "my caption"
End If
Next ctl

Ken Snell
<MS ACCESS MVP>

Thank you Ken, you understood my problem, but unfortunately I can't get your
solution to work.
I got the error: "Runtime error '438': Object doesn't support this property
or method". The debugger stops at the line: If ctl.Type = acLabel Then.
Can your or anyone see whats wrong?

Thanks!
Hallgeir
 
Hallgeir said:
"Ken Snell [MVP]" wrote in message

Thank you Ken, you understood my problem, but unfortunately I can't get your
solution to work.
I got the error: "Runtime error '438': Object doesn't support this property
or method". The debugger stops at the line: If ctl.Type = acLabel Then.
Can your or anyone see whats wrong?

Hallgeir

I solved it myself. The solutions is to write like this: If ctl.ControlType
= acLabel Then.

Hallgeir
 
My apology...it was late when answering your post and I decided to use
"memory" instead of going back to check. Glad that you found the right
answer!
 
Back
Top