Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / March 2007

Tip: Looking for answers? Try searching our database.

Dynamic Creation of Option Group

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Grwffyn - 27 Feb 2007 16:40 GMT
I have an application that requires a matrix of option buttons that changes
based on a table.

So far, I have a method of creating a collection that identifies each item,
but have not been able to make the item into an option button. Is this
possible?

   For intX = 0 To intTotal
   
       For intY = intX To intTotal
       
           strX = Format(intX, "00")
           strY = Format(intY, "00")
           ctlArray(intX, intY) = "ctl" & strX & "_" & strY
           colRadio.Add (ctlArray(intX, intY))
           
       Next intY
       
   Next intX
   For Each newRadio In colRadio
   
       newRadio.Left = Me.WindowLeft + 720
       newRadio.Top = Me.WindowTop - 720
       newRadio.ControlType = acOptionButton
       
   Next

This code dies at the "For Each newradio in colRadio" with "Run-time error
'424': Object required.

Thanks in advance.

Woody
Marshall Barton - 28 Feb 2007 17:57 GMT
>I have an application that requires a matrix of option buttons that changes
>based on a table.
[quoted text clipped - 25 lines]
>This code dies at the "For Each newradio in colRadio" with "Run-time error
>'424': Object required.

That's too vague and out of context for me to answer with a
specific suggestion.

A general approach is to precreate all potentially needed
controls with names like ctl03_07.  The controls can then be
referenced using this kind of syntax:
    Me("ctl" & intX & "_" & intY)

Then instead of whatever your code is trying to do, just
make the needed controls Visible and adjust the Top and Left
properties.

Signature

Marsh
MVP [MS Access]

Grwffyn - 28 Feb 2007 19:10 GMT
That is my dillema, I don't want to pre-create a mass of controls that may or
may not be used. I want them to be created dynamically based on a table that
way when a user modifies the table, the next time the form comes up with the
controls on it, it will be the correct set of controls.

> >I have an application that requires a matrix of option buttons that changes
> >based on a table.
[quoted text clipped - 37 lines]
> make the needed controls Visible and adjust the Top and Left
> properties.
Marshall Barton - 01 Mar 2007 01:21 GMT
The problem with what you want is that creating controls is
a design time operation.  If you do design kinds of things
in a running apllication, you open the door to big time
bloat, greatly increased chances of corruption and, if you
try to  convert to MDE, a complete failure to function.

Besides all that, it requires less code to modify properties
of precreated controls than it does to create them on the
fly, even if it were OK to do it.
Signature

Marsh
MVP [MS Access]

>That is my dillema, I don't want to pre-create a mass of controls that may or
>may not be used. I want them to be created dynamically based on a table that
[quoted text clipped - 42 lines]
>> make the needed controls Visible and adjust the Top and Left
>> properties.
Grwffyn - 01 Mar 2007 12:20 GMT
I understand that this is a design time operation. The purpose is to let
multiple users have their own specialized (and spelializable) matrix without
having to come to me to reprogram that screen.
What you are telling me is that there is no way to instantiate controls from
variables. Is that correct? If so, then I can go on to some other development
language that will allow this rather simple behavior.

Thanks!

> The problem with what you want is that creating controls is
> a design time operation.  If you do design kinds of things
[quoted text clipped - 52 lines]
> >> make the needed controls Visible and adjust the Top and Left
> >> properties.
Marshall Barton - 01 Mar 2007 21:55 GMT
What I am saying is that you should precreate a large (?)
pool of precreated invisible controls and manipulate them at
runtime.  The size of the pool of controls should exceed
whatever any user needs (surely you have a reasonable limit
in what users can select).  You don't even need to create
the controls manually, just write a little procedure
(utilizing CreateControl) for **you** to use one time.  This
really is not a big deal and you can easily continue to use
your table for manipulating the controls that the user want
to see.

I would hate to think that you would go to a more complex
development tool just because Access optimizations require
design changes to be saved before a form/report can be used.
Signature

Marsh
MVP [MS Access]

>I understand that this is a design time operation. The purpose is to let
>multiple users have their own specialized (and spelializable) matrix without
[quoted text clipped - 59 lines]
>> >> make the needed controls Visible and adjust the Top and Left
>> >> properties.
Grwffyn - 02 Mar 2007 12:53 GMT
Thanks.
I presume the routine would look something like:
Set ctl00_00 = Createcontrol(frm.Name, acOptioinButton, , "", "", intX, intY)
Set ctl00_01 = Createcontrol(frm.Name, acOptioinButton, , "", "", intX, intY)
etc. through the last control then manipulate them after they are all created.

> What I am saying is that you should precreate a large (?)
> pool of precreated invisible controls and manipulate them at
[quoted text clipped - 74 lines]
> >> >> make the needed controls Visible and adjust the Top and Left
> >> >> properties.
Marshall Barton - 02 Mar 2007 18:33 GMT
I was thinking of something more like:

Public Sub MakeOptions()
Dim ctl As Control
Dim intX As Integer, intY As Integer

For intX = 0 To 10
    For intY = 0 To 15
        Set ctl = CreateControl("theform", acOptionButton)
        ctl.Name = "ctl" & intX & "_" & intY
        ctl.Visible = False
    Next intY
Next intX
End Sub

Open the form in design view and run the above procedure
from the debug window.  Then close and save the form.

Then, at run time, when you want to display some of the
controls according to the data in your table, use something
along these lines (in the forms Load event??):

Set rs = OpenRecordset("SELECT f1,... FROM ... WHERE ...")
IntX = 0 : intY = 0
Do Until rs.EOF
    With Me("ctl" & intX & "_" & intY)
        .Top = 300*intY    'vertical spacing in twips
        .Left = 1000*intX    'horizontal spacing
        .ControlSource = rs!fieldname
        .Visible = True
    End With
    rs.MoveNext
Loop
Signature

Marsh
MVP [MS Access]

>I presume the routine would look something like:
>Set ctl00_00 = Createcontrol(frm.Name, acOptioinButton, , "", "", intX, intY)
[quoted text clipped - 79 lines]
>> >> >> make the needed controls Visible and adjust the Top and Left
>> >> >> properties.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.