Control Arrays? (1 Viewer)

TravisJRyan

www.kzoorice.com
Local time
Today, 07:44
Joined
Jun 16, 2005
Messages
11
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
 

Mile-O

Back once again...
Local time
Today, 14:44
Joined
Dec 10, 2002
Messages
11,316
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
 

TravisJRyan

www.kzoorice.com
Local time
Today, 07:44
Joined
Jun 16, 2005
Messages
11
shitty.. . . .thanks for the info tho. . Microsoft sucks man. . .but they are improving I suppose. . . :)
 

ChrisO

Registered User.
Local time
Tomorrow, 01:44
Joined
Apr 30, 2003
Messages
3,202
“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.
 

WayneRyan

AWF VIP
Local time
Today, 14:44
Joined
Nov 19, 2002
Messages
7,122
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
 

TravisJRyan

www.kzoorice.com
Local time
Today, 07:44
Joined
Jun 16, 2005
Messages
11
WayneRyan said:
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
 

Mile-O

Back once again...
Local time
Today, 14:44
Joined
Dec 10, 2002
Messages
11,316
WayneRyan said:
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.
 

WayneRyan

AWF VIP
Local time
Today, 14:44
Joined
Nov 19, 2002
Messages
7,122
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
 

ChrisO

Registered User.
Local time
Tomorrow, 01:44
Joined
Apr 30, 2003
Messages
3,202
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.
 

Attachments

  • Rectangles_676_Max_A97.zip
    37.9 KB · Views: 373

Users who are viewing this thread

Top Bottom