Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / July 2007

Tip: Looking for answers? Try searching our database.

Access the Control Source of txtBox by variable?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kou Vang - 31 Jul 2007 21:56 GMT
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...)
Kou Vang - 31 Jul 2007 22:14 GMT
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
Dirk Goldgar - 31 Jul 2007 22:28 GMT
> I also want to know if it's possible to set a variable to equal a
> control source based on a variable?
[quoted text clipped - 5 lines]
> 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.

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Dirk Goldgar - 31 Jul 2007 22:27 GMT
> 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
[quoted text clipped - 12 lines]
>
> 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

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Kou Vang - 31 Jul 2007 22:52 GMT
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

> > 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
[quoted text clipped - 17 lines]
>
>     Me.Controls(Array(I)).Controlsource = "=" & SomeFormula
Dirk Goldgar - 31 Jul 2007 23:10 GMT
> 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.

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.