Hi all,
I have a sub-form that has 196 controls on it. The name for each control is a nubmer from 1 to 196.
I'd like to generate a loop that assigns a value to each control.
Is there a way to reference a control through a variable?
This is what I have now, without trying to attempt to reference through string:
(arrLayoutArray is a 28 row by 7 columns array that was generated in a seperate module) -
-
Me!sfmSubform.Form![1].Value = arrLayoutArray(1, 1)
-
Me!sfmSubform.Form![2].Value = arrLayoutArray(1, 7)
-
Me!sfmSubform.Form![3].Value = arrLayoutArray(1, 2)
-
Me!sfmSubform.Form![4].Value = arrLayoutArray(1, 3)
-
Me!sfmSubform.Form![5].Value = arrLayoutArray(1, 4)
-
Me!sfmSubform.Form![6].Value = arrLayoutArray(1, 5)
-
Me!sfmSubform.Form![7].Value = arrLayoutArray(1, 6)
-
-
I could do this 196 times, but I will be using this for a lot of variations and that isn't very practical. I tried doing this below: -
Dim counter As Variant
-
Dim counter2 As Integer
-
-
counter2 = 0
-
-
For counter = 1 To 28
-
-
Me!sfmSubform.Form![counter2].Value = arrLayoutArray(1, 1)
-
counter2 = counter2 + 1
-
Me!sfmSubform.Form![counter2].Value = arrLayoutArray(1, 7)
-
counter2 = counter2 + 1
-
Me!sfmSubform.Form![counter2].Value = arrLayoutArray(1, 2)
-
counter2 = counter2 + 1
-
Me!sfmSubform.Form![counter2].Value = arrLayoutArray(1, 3)
-
counter2 = counter2 + 1
-
Me!sfmSubform.Form![counter2].Value = arrLayoutArray(1, 4)
-
counter2 = counter2 + 1
-
Me!sfmSubform.Form![counter2].Value = arrLayoutArray(1, 5)
-
counter2 = counter2 + 1
-
Me!sfmSubform.Form![counter2].Value = arrLayoutArray(1, 6)
-
counter2 = counter2 + 1
-
-
Next
-
-
But I get an error because it's looking for counter2 for the name of the control, where I want it to look at the value. I also tried declaring counter2 as a string and variant and that didn't work either.
Please help!
4 1263
Considering that you refer to a "subform", this is in MS Access, right?
Considering that you refer to a "subform", this is in MS Access, right?
I believe you can use the Controls collection. In your example, that could make your code something like this... - Dim c As Long
-
-
For c = 0 To 27 Step 7
-
Me!sfmSubform.Form.Controls(Format$(c)).Value = arrLayoutArray(1, 1)
-
Me!sfmSubform.Form.Controls(Format$(c + 1)).Value = arrLayoutArray(1, 7)
-
Me!sfmSubform.Form.Controls(Format$(c + 2)).Value = arrLayoutArray(1, 2)
-
Me!sfmSubform.Form.Controls(Format$(c + 3)).Value = arrLayoutArray(1, 3)
-
Me!sfmSubform.Form.Controls(Format$(c + 4)).Value = arrLayoutArray(1, 4)
-
Me!sfmSubform.Form.Controls(Format$(c + 5)).Value = arrLayoutArray(1, 5)
-
Me!sfmSubform.Form.Controls(Format$(c + 6)).Value = arrLayoutArray(1, 6)
-
Next
-
My syntax may not be 100% right, but it should demonstrate the idea well enough. The form's Controls collection allows you to access all the controls by supplying the name as a string. However, there is something you need to be aware of. The controls in the collection can be accessed not only by name, but also by number (a sequential index number assigned automatically, presumably in the order they were created.)
So these two expressions would not return the same control, except by coincidence... Controls(12)
Controls("12") This is an unfortunate side-effect of using numbers as the names of your controls. And that's why I have used the old Format$ function, in an attempt to force VB to see the numbers as strings.
Hope you followed all that. I do tend to ramble on a bit.
P.S. I just changed counter to c to overcome some formatting problems in the message. TheScripts has a bit of a problem at the moment with certain long strings, and inserts weird spaces. This change avoided it.)
Alright, i'll give that a try.
Thanks for your help
It worked! Thanks again
I will visit this forum more often now...
Alright, i'll give that a try.
Thanks for your help
It worked! Thanks again
I will visit this forum more often now...
Glad to hear it. :)
Before you know it, you'll be answering other people's questions. That's how we all got hooked.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Bob Cannistraci |
last post by:
A three-tier user authentication system was running without a problem for almost a year and now is suddenly dysfunctional. We don't know of any changes to any of the servers. It's quite maddening....
|
by: michaelkatsilis |
last post by:
Hi,
Are there any issues with returning a const reference value for public
"get" accessor methods?
eg.
const string & getVal(); // or
const MyString & getVal();
|
by: muralidharan |
last post by:
WebForm1.aspx Code:
<%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI"
Assembly="ComponentArt.Web.UI" %> <ComponentArt:TreeView
id="TreeView1" Height="520"...
|
by: Zippy |
last post by:
Some months ago, we requested help from this newsgroup on how to replace
the library reference of a database with another library reference,
prior to creating an MDE. I got the following answer...
|
by: Martine |
last post by:
Hi there!
I have a problem with programmatically adding user controls to my
mobile webforms. If I load my usercontrol programmatically (in the
Page_Load), the object is instantiated, I have...
|
by: Moe Sizlak |
last post by:
Hi There,
I am trying to write the selected value of a listcontrol when a button is
clicked and I keep getting the error "object not set to a reference of an
object". The libox itself is in a...
|
by: Dave |
last post by:
Greetings,
I have a user control in my web form. I cannot reference it in code.
My HTML File has the header:
<%@ Register TagPrefix="PLB" Tagname="PIPSidebar"
src="ProjectListSidebar.ascx"...
|
by: Brano |
last post by:
HI all,
I have a problem i have a web application that was working fine and
this morning when i run it and click on a button that does
Reponse.Redirect to a page i get this error :
Server...
|
by: SAL |
last post by:
I am getting the following ERROR in my WebApp on line 30:
Server Error in '/TestWebApp' Application.
--------------------------------------------------------------------------------
Object...
|
by: Nathan Sokalski |
last post by:
I have a UserControl that I declare programmatically as follows:
Dim userctrl as New rightside_portal()
The codebehind file for this UserControl looks like the following:
Partial Public...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |