06-23-2005, 04:10 AM
|
#1
|
|
www.kzoorice.com
Join Date: Jun 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
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
|
|
|
06-23-2005, 04:26 AM
|
#2
|
|
Newly Registered User
Join Date: Dec 2002
Location: Glasgow, UK
Posts: 10,930
Thanks: 0
Thanked 11 Times in 11 Posts
|
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
|
|
|
06-23-2005, 12:19 PM
|
#3
|
|
www.kzoorice.com
Join Date: Jun 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
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
|
|
|
06-23-2005, 06:28 PM
|
#4
|
|
Registered User
Join Date: Apr 2003
Location: Brisbane, Australia
Posts: 2,953
Thanks: 3
Thanked 178 Times in 146 Posts
|
“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, XP Pro, GMT +10, To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|
|
06-23-2005, 09:05 PM
|
#5
|
|
AWF VIP
Join Date: Nov 2002
Location: Camarillo, CA
Posts: 6,931
Thanks: 1
Thanked 18 Times in 18 Posts
|
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
|
|
|
06-24-2005, 05:46 AM
|
#6
|
|
www.kzoorice.com
Join Date: Jun 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
Quote:
|
This is part of a "im bored" project
|
Regards,
Travis
__________________
KZOORICE.COM
eat your rice, dont put it on your car
|
|
|
06-24-2005, 05:50 AM
|
#7
|
|
www.kzoorice.com
Join Date: Jun 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
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
|
|
|
06-24-2005, 05:52 AM
|
#8
|
|
Newly Registered User
Join Date: Dec 2002
Location: Glasgow, UK
Posts: 10,930
Thanks: 0
Thanked 11 Times in 11 Posts
|
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.
|
|
|
06-24-2005, 10:22 AM
|
#9
|
|
AWF VIP
Join Date: Nov 2002
Location: Camarillo, CA
Posts: 6,931
Thanks: 1
Thanked 18 Times in 18 Posts
|
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
|
|
|
06-24-2005, 11:13 AM
|
#10
|
|
www.kzoorice.com
Join Date: Jun 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
Very true. . I follow you Wayne. . thanks
__________________
KZOORICE.COM
eat your rice, dont put it on your car
|
|
|
06-24-2005, 01:38 PM
|
#11
|
|
Registered User
Join Date: Apr 2003
Location: Brisbane, Australia
Posts: 2,953
Thanks: 3
Thanked 178 Times in 146 Posts
|
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.
__________________
Access 2003, XP Pro, GMT +10, To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|
|
06-27-2005, 07:20 AM
|
#12
|
|
www.kzoorice.com
Join Date: Jun 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
Interesting ChrisO. . Thank you!
__________________
KZOORICE.COM
eat your rice, dont put it on your car
|
|
|
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
All times are GMT -8. The time now is 07:12 AM.
|
|