From: ab on
I have two labels on a form and want to populate them during the run
time of my form. The name of the labels are "1" the other is called
"2" (without the quotes of course). Field 1 runs OK but two returns a
run-time error 2465.
Of course, the real form is much bigger. A lot of fields called 1
through 31 are populated from within a loop. To simplify my question I
down sized this post to two label fields.

Any one know how to solve the problem with label "2"? Any help or hint
is appreciated.


' This works OK
Me![1].Caption = "abc"

' This return a Run-time error '2465': Can't find field 'x'
Dim x As String
x = "2"
Me![x].Caption = "def"

From: Jon Lewis on
Try Me.Controls(x).Caption = "def"

Jon
"ab" <absmienk(a)gmail.com> wrote in message
news:dabdb911-0788-40db-b80b-8790ac749c3e(a)o39g2000vbd.googlegroups.com...
>I have two labels on a form and want to populate them during the run
> time of my form. The name of the labels are "1" the other is called
> "2" (without the quotes of course). Field 1 runs OK but two returns a
> run-time error 2465.
> Of course, the real form is much bigger. A lot of fields called 1
> through 31 are populated from within a loop. To simplify my question I
> down sized this post to two label fields.
>
> Any one know how to solve the problem with label "2"? Any help or hint
> is appreciated.
>
>
> ' This works OK
> Me![1].Caption = "abc"
>
> ' This return a Run-time error '2465': Can't find field 'x'
> Dim x As String
> x = "2"
> Me![x].Caption = "def"
>


From: ab on
Works! Thanks a bunch!

Cheers,
Ab


On May 17, 2:12 pm, "Jon Lewis" <jon.le...(a)cutthespambtinternet.com>
wrote:
> Try  Me.Controls(x).Caption = "def"
>
> Jon"ab" <absmi...(a)gmail.com> wrote in message
>
> news:dabdb911-0788-40db-b80b-8790ac749c3e(a)o39g2000vbd.googlegroups.com...
>
> >I have two labels on a form and want to populate them during the run
> > time of my form. The name of the labels are "1" the other is called
> > "2" (without the quotes of course). Field 1 runs OK but two returns a
> > run-time error 2465.
> > Of course, the real form is much bigger. A lot of fields called 1
> > through 31 are populated from within a loop. To simplify my question I
> > down sized this post to two label fields.
>
> > Any one know how to solve the problem with label "2"? Any help or hint
> > is appreciated.
>
> >    ' This works OK
> >    Me![1].Caption = "abc"
>
> >    ' This return a Run-time error '2465': Can't find field 'x'
> >    Dim x As String
> >    x = "2"
> >    Me![x].Caption = "def"