fieldnames in variables

  • Thread starter Thread starter Richard
  • Start date Start date
R

Richard

Hi

I wish to automate some code as I have 42 text boxes to show a value, they
are names [Carv1], [Carv2], [Carv3] Etc
To save writing many lines of code I have evaluated the names into a variable

code example is:
--------------------------
dim NameVariable As String
dim intCounter As Integer

NameVariable = "[Carv" & intCounter & "]" 'With intCounter value =1,

NameVariable evaluates to "[Carv1]"
NameVariable = 25 This evaluates
Namevariable to 25
not the
Fieldname [Carv1] as required

-------------------------------------------------------------
How do I evaluate into the fieldname held in NameVariable?

Ideas anyone?

Many Thanks
 
dim NameVariable As String
dim intCounter As Integer

NameVariable = "Carv" & intCounter & ""
Me.Controls(NameVariable) = 25
 
Brilliant! Many thanks
That has saved me well over 40 lines of code!
--
Richard


Douglas J. Steele said:
dim NameVariable As String
dim intCounter As Integer

NameVariable = "Carv" & intCounter & ""
Me.Controls(NameVariable) = 25


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Richard said:
Hi

I wish to automate some code as I have 42 text boxes to show a value, they
are names [Carv1], [Carv2], [Carv3] Etc
To save writing many lines of code I have evaluated the names into a
variable

code example is:
--------------------------
dim NameVariable As String
dim intCounter As Integer

NameVariable = "[Carv" & intCounter & "]" 'With intCounter value =1,

NameVariable evaluates to "[Carv1]"
NameVariable = 25 This evaluates
Namevariable to 25
not the
Fieldname [Carv1] as required

-------------------------------------------------------------
How do I evaluate into the fieldname held in NameVariable?

Ideas anyone?

Many Thanks
 
Back
Top