UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Create Loop To Change Caption On Multiple Labels On Form, Access 2016    
 
   
TimTDP
post Jan 11 2017, 09:03 AM
Post#1



Posts: 1,009
Joined: 16-June 05



On a form I have numerous labels called Label1, Label2, Label3...........

I want to create code that will loop through each label and change each label's caption. This is what I have:
CODE
Dim vCount As Long
Dim dDate as Date

dDate  = Date

For vCount = 1 To 3  'nimber of labels
    "Label" & vCount.Caption = Format(dDate  , "d")  'day number
    dDate  = DateAdd("d",1,dDate)   'inc Date
Next


Access doesn't like the line of code
CODE
"Label" & vCount.Caption = Format(vDate, "d")  'calc day number and display"Label" & vCount.Caption = Format(vDate, "d")  'calc day number and display


What am I doing wrong?

Thanks in advance
Go to the top of the page
 
jwhite
post Jan 11 2017, 09:15 AM
Post#2


UtterAccess VIP
Posts: 5,801
Joined: 31-August 06
From: North Carolina, USA


Trying changing: "Label" & vCount.Caption = Format(dDate , "d") 'day number
to: Me.Controls("Label" & CStr(vCount)).Caption = Format(dDate , "d") 'day number

*: Edited to correct syntax for .Caption portion

--------------------
Go to the top of the page
 
BruceM
post Jan 11 2017, 10:19 AM
Post#3


UtterAccess VIP
Posts: 6,742
Joined: 24-May 10
From: Downeast Maine


I think the Caption property may need to be outside the parentheses:

Me.Controls("Label" & CStr(vCount)).Caption = Format(dDate , "d") 'day number

Go to the top of the page
 
jwhite
post Jan 11 2017, 10:21 AM
Post#4


UtterAccess VIP
Posts: 5,801
Joined: 31-August 06
From: North Carolina, USA


Yea, I did that on the fly.

Confirmed: Me.Controls("Label96").Caption = "Foobar"

--------------------
Go to the top of the page
 
TimTDP
post Jan 11 2017, 10:31 AM
Post#5



Posts: 1,009
Joined: 16-June 05



Thanks very much
Go to the top of the page
 
BruceM
post Jan 11 2017, 02:00 PM
Post#6


UtterAccess VIP
Posts: 6,742
Joined: 24-May 10
From: Downeast Maine


We're both glad to help. Good luck with the project.
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    19th August 2017 - 04:26 AM