Dynamic forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to create a form with some dynamic elements. I have a form
which captures certain information from the user, based on this information I
would like to create checkboxes on the next form which is opened. I am
trying to do this within the VBA in the form_open event. Please can somebody
give me an example of how I create a checkbox and add it to the form.
 
There is a method called CreateControl, however

"You can use the CreateControl and CreateReportControl methods only in form
Design view or report Design view, respectively."

alternatively, if there are only a few possible combinations of check boxes,
why not just change the Visible property depending on the information
captured?
 
There are quite a lot of possible options, and I am trying to write this so
that as the data changes overtime, it doesn't need me to go back in and
update the form. Thanks for the info, looks like I can't do this in access,
time to switch to ASP pages.
 
Hold fire for a few hours, as there are some people on this Forum who may
have knowledge of custom controls that can do this or alternative ideas.

You could have a sub form that gets opened in design programatically, have
the controlls added and then Visible=True when you are ready to view it. . .
 
Nicola,

Design changes won't work in an .mde, so if this is an app that will
eventually be distributed to users as an .mde FE, don't waste any time
on this option.
How about using an intermediate table, populated through code (so you
can handle changes over time), which is used as the recordset of the
subsequent form? Just an idea... if you care to explain what you are
trying to achieve, you might get better / more applicable suggestions.

Nikos
 
Hi Nicola, this will give you a start

Create 2 forms, one called MyNewMainForm and one called MyNewSubForm. Drag
the sub form onto the main form. Change the SourceObject property to be ""
and make it Visible = False
Now on the main form, add the following code to the OnClick of a button

Dim MyCounter As Integer
Dim objNewCheckBox As CheckBox
DoCmd.OpenForm "Mynewsubform", acDesign

For MyCounter = 1 To 5
Set objNewCheckBox = CreateControl("MyNewSubForm",
acCheckBox, acDetail)
With objNewCheckBox
.Name = "MyCheckBox" & MyCounter
.Top = MyCounter * 300
.Left = 20
End With
Next

DoCmd.Close acForm, "MyNewSubForm", acSaveYes
Forms("MyNewMainForm")!MyNewSubForm.SourceObject = "MyNewSubForm"
Forms("MyNewMainForm")!MyNewSubForm.Visible = True

Of course next time you run it, the sub form already has the controls on it,
so you'll need to do some sort of clean up (using DeleteControl ) before
adding new ones


Hope this gives you a head start
 
If you do go the data driven web FE method, have a look at XML for the
metadata for the form (which can be data driven) and the use of XLST's to
render the controls at run time.
 
Interesting, please can you point me at a good example of creating a form
from a recordset?
 
your post is kind of old, so I don't know if you ever did this. I was doing
something similar, adding controls to a form at runtime (and deleting them
later during cleanup). When I was running into difficulties, someone pointed
out to me that a given form has a limited quantity of controls that can be
added over its lifetime. Deleting the control doesn't reset the limit, so if
the same form is used over and over, eventually it will reach its limit. To
get around this, rather than reuse the same form each time, I delete the old
and create a new.
 
dchman said:
your post is kind of old, so I don't know if you ever did this. I
was doing something similar, adding controls to a form at runtime
(and deleting them later during cleanup). When I was running into
difficulties, someone pointed out to me that a given form has a
limited quantity of controls that can be added over its lifetime.
Deleting the control doesn't reset the limit, so if the same form is
used over and over, eventually it will reach its limit. To get
around this, rather than reuse the same form each time, I delete the
old and create a new.

When it's necessary to do this sort of thing, it's generally better to
create the form once, putting on it all the controls you expect ever to
need. Then at run time you only show the controls you need at the
moment, and modify their properties to get the positions and behavior
you want.
 
AMEN!

Dirk Goldgar said:
When it's necessary to do this sort of thing, it's generally better to
create the form once, putting on it all the controls you expect ever to
need. Then at run time you only show the controls you need at the
moment, and modify their properties to get the positions and behavior
you want.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Back
Top