473,394 Members | 1,811 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to create an array of labels?

Hello,

In regular VB, I remember I could create a generic label (call it something
like lblFieldNames) and copy it and paste it. VB would say that I already
have an object by that name then ask me if I wanted to create an array. So
I would end up with lblFieldNames(0) to lblFieldNames(n). Then I could
cycle through the QueryDef and fill the captions of the labels with the
correct field names. Is that possible in VBA, and more specifically, in an
Access report?

Rich Hollenbeck
Moreno Valley, CA

Jun 13 '07 #1
3 19233
Access doesn't support control arrays like VB does. However, you can
manually name your controls in such a way that you can still loop through
them in code.

Say your control is called MyControl. Simply create a MyControl1,
MyControl2, MyControl3, etc. Then, when you want to loop through the
controls, do something like this:

For i = 1 to N
Me.Controls("MyControl" & i).Caption = "whatever"
Next

where N = the highest numbered control.

Of course, if you're not in the code module of the form or report you're
modifying, you can replace ME in the above with Forms!MyForm or
Reports!MyReport, or whatever your form or report name is.

HTH,

Neil

"Richard Hollenbeck" <ri****************@verizon.netwrote in message
news:ueObi.5628$c45.3477@trndny06...
Hello,

In regular VB, I remember I could create a generic label (call it
something like lblFieldNames) and copy it and paste it. VB would say that
I already have an object by that name then ask me if I wanted to create an
array. So I would end up with lblFieldNames(0) to lblFieldNames(n). Then
I could cycle through the QueryDef and fill the captions of the labels
with the correct field names. Is that possible in VBA, and more
specifically, in an Access report?

Rich Hollenbeck
Moreno Valley, CA

Jun 13 '07 #2
That works! Thanks.

"Neil" <no****@nospam.netwrote in message
news:fr******************@newssvr14.news.prodigy.n et...
Access doesn't support control arrays like VB does. However, you can
manually name your controls in such a way that you can still loop through
them in code.

Say your control is called MyControl. Simply create a MyControl1,
MyControl2, MyControl3, etc. Then, when you want to loop through the
controls, do something like this:

For i = 1 to N
Me.Controls("MyControl" & i).Caption = "whatever"
Next

where N = the highest numbered control.

Of course, if you're not in the code module of the form or report you're
modifying, you can replace ME in the above with Forms!MyForm or
Reports!MyReport, or whatever your form or report name is.

HTH,

Neil

"Richard Hollenbeck" <ri****************@verizon.netwrote in message
news:ueObi.5628$c45.3477@trndny06...
>Hello,

In regular VB, I remember I could create a generic label (call it
something like lblFieldNames) and copy it and paste it. VB would say
that I already have an object by that name then ask me if I wanted to
create an array. So I would end up with lblFieldNames(0) to
lblFieldNames(n). Then I could cycle through the QueryDef and fill the
captions of the labels with the correct field names. Is that possible in
VBA, and more specifically, in an Access report?

Rich Hollenbeck
Moreno Valley, CA


Jun 13 '07 #3
Great! Of course, you can always just create an array in code that holds the
names of the controls you want to modify, and then name them whatever you
want. That would work as well, but it's more work to set up.

Neil
"Richard Hollenbeck" <ri****************@verizon.netwrote in message
news:lvUbi.8307$yS4.3216@trnddc04...
That works! Thanks.

"Neil" <no****@nospam.netwrote in message
news:fr******************@newssvr14.news.prodigy.n et...
>Access doesn't support control arrays like VB does. However, you can
manually name your controls in such a way that you can still loop through
them in code.

Say your control is called MyControl. Simply create a MyControl1,
MyControl2, MyControl3, etc. Then, when you want to loop through the
controls, do something like this:

For i = 1 to N
Me.Controls("MyControl" & i).Caption = "whatever"
Next

where N = the highest numbered control.

Of course, if you're not in the code module of the form or report you're
modifying, you can replace ME in the above with Forms!MyForm or
Reports!MyReport, or whatever your form or report name is.

HTH,

Neil

"Richard Hollenbeck" <ri****************@verizon.netwrote in message
news:ueObi.5628$c45.3477@trndny06...
>>Hello,

In regular VB, I remember I could create a generic label (call it
something like lblFieldNames) and copy it and paste it. VB would say
that I already have an object by that name then ask me if I wanted to
create an array. So I would end up with lblFieldNames(0) to
lblFieldNames(n). Then I could cycle through the QueryDef and fill the
captions of the labels with the correct field names. Is that possible
in VBA, and more specifically, in an Access report?

Rich Hollenbeck
Moreno Valley, CA



Jun 13 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Francois | last post by:
Is it possible to automatically create an array on load page? I want my script to be external. (<script language="JavaScript" src="somescript.js"></script>) Several pages should use this...
3
by: John Haigh | last post by:
I have the need to create an array of objects. Now this sound fairly trivial but I can't figure this out. I have one class called PostingObjectService that has a method GetPostings where the...
2
by: SaT | last post by:
Does anyone know how to create hyperlink labels within a datagrid, on the fly? Thanks SaT
2
by: Mikey | last post by:
Sample VB .NET source code to create mailing labels or customized letters using MS Word MailMerge This VB .NET source code will start MS Word and call methods and set properties in MS Word to...
0
by: Raju | last post by:
Hi all i am Rajendran I am working as a asp.net programmer. I am frish to this field so please any of u garify my doubt I Create array of Textbox Dynamically and not passible to retrieve data...
1
by: dragannis | last post by:
Hello, I realy need help about this, I have database that I want to use in my Vb code, and I need to create array from elements of one field from that mdb. Why : I need to do some calculations...
12
by: =?Utf-8?B?RGFuaWVs?= | last post by:
Hi, I have create a class name employee. Next, i would like to create array for the employee class. The code as below: dim eply(5) as employee when i call eply(0).name="Khrish", an error...
0
by: dbsog7777 | last post by:
I was trying to use the sample code below, but I encountered two errors: Application.DoEvents() and AutoText(entry). I am not sure how to correct the errors. I trying to use the sample code to...
4
by: ingaivey | last post by:
I have 81 text boxes on a form and would like to create a text array in code that will equate to these boxes on the form. Once I've assigned each text box from the form to the array entry, I'd just...
0
by: davaahuu | last post by:
how to create array with audio files?, Is it possible?
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.