Dynamically created controls on Access forms

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

Guest

Hi,

Is it possible to create dynamic controls (text boxes and labels) on an
Access form. The Access help only mentions ControlBars, although VB allows
for more controls.

Using

Dim txt As TextBox
For i = 1 To dbRes.RecordCount
Set txt = Controls.Add("TextBox", "txt" & CStr(i))
txt.visible = True
Next i

results in an 'Object required' error message.

Thanks in advance for any help on this.
APS
 
aps said:
Hi,

Is it possible to create dynamic controls (text boxes and labels) on an
Access form. The Access help only mentions ControlBars, although VB allows
for more controls.

No, ms-access does not. In vb, there is the "clone" method, but it was
usually a bad idea at best...

However, in most cases, if your design is good, then you can usually work
around the problem..and not have to create runtime changes to a form.

In fact, if you "can" avoid creating things on a form, then you should
make "extra" efforts. Remember, if you are adding fields to the form..then
often you need to do the same to a report..and then all hell breaks
loose..as you now start having to change a LOT of things each time.

I can only suggest that you place some controls on the form, and then hide
them...or show them. You REALLY want to avoid the idea of creating
controls as you go. While this creating controls works well with a
web based type system, for forms in windows applications, it
don't work well at all.

And, if you need repeating controls..take a look at the following screen
shots, as they demonstrate repeating data.

http://www.members.shaw.ca/AlbertKallal/Articles/Grid.htm
 
Back
Top