PC Review


Reply
Thread Tools Rate Thread

Access the Control Source of txtBox by variable?

 
 
=?Utf-8?B?S291IFZhbmc=?=
Guest
Posts: n/a
 
      31st Jul 2007
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...)
 
Reply With Quote
 
 
 
 
=?Utf-8?B?S291IFZhbmc=?=
Guest
Posts: n/a
 
      31st Jul 2007
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
 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      31st Jul 2007
In news:3C91E467-349D-47C1-99E8-(E-Mail Removed),
Kou Vang <(E-Mail Removed)> wrote:
> 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

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      31st Jul 2007
In news:511C16B7-68BD-4658-AE52-(E-Mail Removed),
Kou Vang <(E-Mail Removed)> wrote:
> 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.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
=?Utf-8?B?S291IFZhbmc=?=
Guest
Posts: n/a
 
      31st Jul 2007
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

"Dirk Goldgar" wrote:

> In news:3C91E467-349D-47C1-99E8-(E-Mail Removed),
> Kou Vang <(E-Mail Removed)> wrote:
> > 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
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)
>
>
>

 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      1st Aug 2007
In news:8436056A-E8AE-4208-ACA3-(E-Mail Removed),
Kou Vang <(E-Mail Removed)> wrote:
> 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.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Image control - No Control Source property in Access 2000/2003? Gino Microsoft Access 4 17th Mar 2010 05:17 AM
Access Form contains TxtBox with Hyperlink from source Table RLC603 Microsoft Access 0 19th Dec 2008 07:52 PM
How to Run query based on txtbox value that is part of control source Armin Microsoft Access Forms 0 16th Sep 2007 12:41 AM
refer to a control on another form in access as a control source =?Utf-8?B?dGhlQnJ1Y2VHdXk=?= Microsoft Access Form Coding 7 21st Feb 2007 08:35 PM
Send unbound txtbox value to variable GR Microsoft Access Reports 0 15th Jan 2004 03:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:30 PM.