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 2005

Tip: Looking for answers? Try searching our database.

Accessing a member of the controls collection with a variable

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
toolsgg - 14 Jul 2005 12:52 GMT
I am trying to set the value of a set of controls on a form programmatically.
Using something like the following code:
Do While Not rs.EOF
   sCtlName = "txt" + LTrim(Str(i))
   Forms![main menu].Controls(sCtlName).Caption = rs![menu_item_description]
   i = i + 1
   rs.MoveNext
Loop
where the controls are named txt0, txt1, txt2 etc..  If I substitute "txt0"
into the line above it works fine but with the variable it gives me an
"object does not support this property or method" message.
How do I format this line so it will accept the variable for the control
name?
Brendan Reynolds - 14 Jul 2005 13:55 GMT
The prefix 'txt' is usually used for text boxes. Text boxes don't have a
Caption property. If 'txt0' works for you, then I guess 'txt0' must be a
different type of control, probably a label. What about the other controls
named 'txt...' - are they all labels? If one or more of them are text boxes,
or any other kind of control that doesn't have a Caption property, you would
get that error message.

BTW: You could replace these two function calls ...
LTrim(Str(i))
... with one ...
CStr(i)

Unlike Str(), CStr() does not put a space in front of positive numbers, so
you won't need the call to LTrim().

Signature

Brendan Reynolds (MVP)

>I am trying to set the value of a set of controls on a form
>programmatically.
[quoted text clipped - 12 lines]
> How do I format this line so it will accept the variable for the control
> name?
toolsgg - 14 Jul 2005 14:10 GMT
Thanks.  It is a text box.  One of those ones where you spend hours looking
for the complex answer when the simple one is staring you in the face.

> The prefix 'txt' is usually used for text boxes. Text boxes don't have a
> Caption property. If 'txt0' works for you, then I guess 'txt0' must be a
[quoted text clipped - 27 lines]
> > How do I format this line so it will accept the variable for the control
> > name?
David C. Holley - 15 Jul 2005 00:21 GMT
try rs!(variableName)

> I am trying to set the value of a set of controls on a form programmatically.
>  Using something like the following code:
[quoted text clipped - 9 lines]
> How do I format this line so it will accept the variable for the control
> name?
 
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.