Access the Control Source of txtBox by variable?

K

Kou Vang

I have several txtBoxes that I want to edit the Control Sources of each of
them. If I set a variable to the name of the txtBox, can I somehow
dynamically call the control source of the txtBox by a variable as suppose to
writing out the code for each one in long form? Confused? Here's my code

Option Explicit
Dim SomeFormula

Me.txtBox.controlsource = "=" & SomeForumula

Can I somehow do this:

Me. & Array(I) & .controlsource= "=" & SomeFormula

Is this possible? Still Confused? (So am I sometimes...)
 
K

Kou Vang

I also want to know if it's possible to set a variable to equal a control
source based on a variable?

dim x

x=Me. & var1 & .ControlSource.Text

Can this be done without actually typing the txtboxes name as to using a
variable in its place? Thanks.

Kou
 
D

Dirk Goldgar

In
Kou Vang said:
I have several txtBoxes that I want to edit the Control Sources of
each of them. If I set a variable to the name of the txtBox, can I
somehow dynamically call the control source of the txtBox by a
variable as suppose to writing out the code for each one in long
form? Confused? Here's my code

Option Explicit
Dim SomeFormula

Me.txtBox.controlsource = "=" & SomeForumula

Can I somehow do this:

Me. & Array(I) & .controlsource= "=" & SomeFormula

Is this possible? Still Confused? (So am I sometimes...)

You can use the name of the control as a string index into the Controls
collection; like this:

Me.Controls(Array(I)).Controlsource = "=" & SomeFormula
 
D

Dirk Goldgar

In
Kou Vang said:
I also want to know if it's possible to set a variable to equal a
control source based on a variable?

dim x

x=Me. & var1 & .ControlSource.Text

Can this be done without actually typing the txtboxes name as to
using a variable in its place? Thanks.

Use:

x = Me.Controls(var1).ControlSource

There is no ".Text" property of the ControlSource, which is itself a
text property.
 
K

Kou Vang

I forgot to mention that I am trying to edit txtBoxes that are in a report
through a form I am running. Can I open a report while running the code from
the form, and edit the txtboxes of the report through the forms code?

Kou
 
D

Dirk Goldgar

In
Kou Vang said:
I forgot to mention that I am trying to edit txtBoxes that are in a
report through a form I am running. Can I open a report while
running the code from the form, and edit the txtboxes of the report
through the forms code?

I think you'd better put the code to modify controlsources in the Open
event of the report. Even if Access will let you do it after the
report's Open event has finished -- and it may not -- I'm not sure if
there's any other way for you to ensure that the text boxes'
controlsources are set before the report actually starts to print them.
 

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