Go Back   Access World Forums > Microsoft Access Discussion > General

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 06-23-2005, 04:10 AM   #1
TravisJRyan
www.kzoorice.com
 
TravisJRyan's Avatar
 
Join Date: Jun 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
TravisJRyan is on a distinguished road
Send a message via AIM to TravisJRyan
Control Arrays?

I am not even totally sure that is what you call it. . but I have most of my experience in VB.NET and this VBA in Access 2002 is killin me. HA. . .

I am trying to dynamically create checkboxes (50 of them) in 10 rows and 5 columns. This is part of a "im bored" project and would like to be able to tackle the dynamic controls area.

I am thinking I want to keep the naming convention as "chkBox01. . .02. . .03" so that I can use the mid() function to determine its "value" and apply the value in the proper place.

I suppose the only thing I need is an example if anyone has one of a checkbox or any control for that matter being made by VBA and not placed on the form manually. 50 check boxes suck when trying to rename them all. sigh

__________________
KZOORICE.COM
eat your rice, dont put it on your car
TravisJRyan is offline   Reply With Quote
Old 06-23-2005, 04:26 AM   #2
Mile-O
Back once again...
 
Join Date: Dec 2002
Location: Glasgow, UK
Posts: 11,067
Thanks: 3
Thanked 42 Times in 42 Posts
Mile-O is on a distinguished road
Unfortunately, Control Arrays aren't supported in VBA.

What you can do is create an array and then assign the controls to it.

i.e.

Code:
Dim lngCounter As Long
Dim myControls(1 To 50) As Control

For lngCounter = 1 To 50
    Set myControls(lngCounter) = Me("TextBox" & lngCounter)
Next lngCounter
Mile-O is offline   Reply With Quote
Old 06-23-2005, 12:19 PM   #3
TravisJRyan
www.kzoorice.com
 
TravisJRyan's Avatar
 
Join Date: Jun 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
TravisJRyan is on a distinguished road
Send a message via AIM to TravisJRyan
shitty.. . . .thanks for the info tho. . Microsoft sucks man. . .but they are improving I suppose. . .

__________________
KZOORICE.COM
eat your rice, dont put it on your car
TravisJRyan is offline   Reply With Quote
Old 06-23-2005, 06:28 PM   #4
ChrisO
Newly Registered User
 
ChrisO's Avatar
 
Join Date: Apr 2003
Location: Brisbane, Australia
Posts: 3,204
Thanks: 7
Thanked 221 Times in 178 Posts
ChrisO is just really nice ChrisO is just really nice ChrisO is just really nice ChrisO is just really nice
“Microsoft sucks man. . .but they are improving I suppose. . .”

There may be times that a Microsoft product does not behave in the way that you think it should.
There will also be other times that you don’t understand how a particular Microsoft product behaves.

If I were a betting man I would prefer to flip a coin that had Microsoft on both sides.

What exactly are you trying to do?

If you are trying to create controls on an existing form or if the form exists in an MDE file then both will fail. The first will fail because of the number of controls in the life of the form and deleting controls makes no difference. The second will require the form to be opened in design view and that can’t happen in an MDE file.

So, in general, creating controls on the fly makes little sense in Access, apart from the coding exercise, and don’t expect to be able to use that technique in a production environment.

Regards,
Chris.
__________________
Access 2003, Win7, GMT +10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
ChrisO is offline   Reply With Quote
Old 06-23-2005, 09:05 PM   #5
WayneRyan
AWF VIP
 
Join Date: Nov 2002
Location: Camarillo, CA
Posts: 7,022
Thanks: 2
Thanked 36 Times in 36 Posts
WayneRyan has a spectacular aura about WayneRyan has a spectacular aura about WayneRyan has a spectacular aura about
Travis,

It's not really that inflexible. There's not much difference between referencing
them: Me.Controls("chkBox" & CStr(i)) <----> CheckBoxArray(i)

Logically that maps as easily as an array to whatever you're doing.

What are you trying to do?

Wayne
WayneRyan is offline   Reply With Quote
Old 06-24-2005, 05:46 AM   #6
TravisJRyan
www.kzoorice.com
 
TravisJRyan's Avatar
 
Join Date: Jun 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
TravisJRyan is on a distinguished road
Send a message via AIM to TravisJRyan
Quote:
This is part of a "im bored" project


Regards,

Travis
__________________
KZOORICE.COM
eat your rice, dont put it on your car
TravisJRyan is offline   Reply With Quote
Old 06-24-2005, 05:50 AM   #7
TravisJRyan
www.kzoorice.com
 
TravisJRyan's Avatar
 
Join Date: Jun 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
TravisJRyan is on a distinguished road
Send a message via AIM to TravisJRyan
Quote:
Originally Posted by WayneRyan
Travis,

It's not really that inflexible. There's not much difference between referencing
them: Me.Controls("chkBox" & CStr(i)) <----> CheckBoxArray(i)

Logically that maps as easily as an array to whatever you're doing.

What are you trying to do?

Wayne
I am trying to start with an empty pane. . .form .. whatever. . and then create 50 check boxes with a sequential naming convention. That's all. its easy to do in .NET and actually I think I figured it out in VBA with the CStr(i) idea. . Thanks dude

__________________
KZOORICE.COM
eat your rice, dont put it on your car
TravisJRyan is offline   Reply With Quote
Old 06-24-2005, 05:52 AM   #8
Mile-O
Back once again...
 
Join Date: Dec 2002
Location: Glasgow, UK
Posts: 11,067
Thanks: 3
Thanked 42 Times in 42 Posts
Mile-O is on a distinguished road
Quote:
Originally Posted by WayneRyan
There's not much difference between referencing
them: Me.Controls("chkBox" & CStr(i)) <----> CheckBoxArray(i)

Logically that maps as easily as an array to whatever you're doing.
It's just that you can't have one event for the whole array with the Index passed as the parameter.
Mile-O is offline   Reply With Quote
Old 06-24-2005, 10:22 AM   #9
WayneRyan
AWF VIP
 
Join Date: Nov 2002
Location: Camarillo, CA
Posts: 7,022
Thanks: 2
Thanked 36 Times in 36 Posts
WayneRyan has a spectacular aura about WayneRyan has a spectacular aura about WayneRyan has a spectacular aura about
SJ,

I don't normally develop things with that many controls, but one
form used for scheduling equipment had a grid of TextBoxes used
to represent usage times.

My short-term solution was to write a few lines of code to
produce the following; varying [n]:

Private Sub Control[n]_Click
Call EventHandler
End Sub

With very little effort, I then had only one common "event" to
code.

Not very sophisticated, but I don't really see it as a limiting
factor.

I would advise against programmatically creating/deleting controls
though; they don't really go away. Once you've introduced about
750 controls to the form it goes "brain dead". Not really sure
about the number, but 750 is close enough.

I'd make a static form, trigger a common event, and let one
routine process what each CheckBox means. You can still map
your controls to an array or table to define their characteristics.

Wayne
WayneRyan is offline   Reply With Quote
Old 06-24-2005, 11:13 AM   #10
TravisJRyan
www.kzoorice.com
 
TravisJRyan's Avatar
 
Join Date: Jun 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
TravisJRyan is on a distinguished road
Send a message via AIM to TravisJRyan
Very true. . I follow you Wayne. . thanks
__________________
KZOORICE.COM
eat your rice, dont put it on your car
TravisJRyan is offline   Reply With Quote
Old 06-24-2005, 01:38 PM   #11
ChrisO
Newly Registered User
 
ChrisO's Avatar
 
Join Date: Apr 2003
Location: Brisbane, Australia
Posts: 3,204
Thanks: 7
Thanked 221 Times in 178 Posts
ChrisO is just really nice ChrisO is just really nice ChrisO is just really nice ChrisO is just really nice
Another method, just for the coding exercise, is attached.

It will build the form with some controls and also place in the form some code that can be modified to do what you want.

Only one event handler for each type of event is created and linking controls to that event is dynamic in as much that they could be altered at runtime.

Have fun and regards,
Chris.
Attached Files
File Type: zip Rectangles_676_Max_A97.zip (37.9 KB, 234 views)
__________________
Access 2003, Win7, GMT +10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
ChrisO is offline   Reply With Quote
Old 06-27-2005, 07:20 AM   #12
TravisJRyan
www.kzoorice.com
 
TravisJRyan's Avatar
 
Join Date: Jun 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
TravisJRyan is on a distinguished road
Send a message via AIM to TravisJRyan
Interesting ChrisO. . Thank you!

__________________
KZOORICE.COM
eat your rice, dont put it on your car
TravisJRyan is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use a combo box to populate a field that is not its control source? etalent Forms 2 03-23-2004 02:37 PM
control arrays bauer Reports 1 03-05-2002 12:53 PM
control arrays in VBA? golgo1 Forms 2 02-11-2002 10:33 PM
Control arrays blackbird Modules & VBA 1 02-10-2002 07:17 PM
[SOLVED] Control Arrays in Access VBA Zeich Modules & VBA 1 02-05-2000 07:12 PM




All times are GMT -8. The time now is 03:49 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
(c) copyright 2010 Access World