Creating Controls On The Fly

  • Thread starter Thread starter MDW
  • Start date Start date
M

MDW

Background:
I'm trying to create an administrative section to a
database that will show/hide certain buttons for users.
I'm going to feed the info into a text file and then read
the file on startup. I've got all that in line.

However, the form whose buttons will be shown/hidden may
change in the future - i.e. buttons may be added/removed.
I'd like for the administrative form to reflect those
changes. The admin feature will be simple: one checkbox on
the admin form corresponding to each button on another
form. I want to create those checkboxes dymanically.
Here's the pseudocode I'm hashing out.

For each objCtl on MyDB!Forms!TheOtherForm.Controls

If objCtl.Type = acButton Then

' ** CODE TO CREATE THE CHECKBOX - HERE'S WHERE I
NEED HELP
objMyNewCheckBox.Name = objCtl.Name
objMyNewCheckBox.Caption = objCtl.Caption
' I can figure out positioning, etc.

End If

Next

Can anyone help me out?
 
Background:
I'm trying to create an administrative section to a
database that will show/hide certain buttons for users.
I'm going to feed the info into a text file and then read
the file on startup. I've got all that in line.

However, the form whose buttons will be shown/hidden may
change in the future - i.e. buttons may be added/removed.
I'd like for the administrative form to reflect those
changes. The admin feature will be simple: one checkbox on
the admin form corresponding to each button on another
form. I want to create those checkboxes dymanically.
Here's the pseudocode I'm hashing out.

For each objCtl on MyDB!Forms!TheOtherForm.Controls

If objCtl.Type = acButton Then

' ** CODE TO CREATE THE CHECKBOX - HERE'S WHERE I
NEED HELP
objMyNewCheckBox.Name = objCtl.Name
objMyNewCheckBox.Caption = objCtl.Caption
' I can figure out positioning, etc.

End If

Next

Can anyone help me out?
You would use the CreateControl Method. -

Dim ctl As Control

Set ctl = CreateControl("frmMyFormName", acCheckBox, acDetail, vbNullString, _
"BoundField", 100, 100, 280, 280)
ctl.Name = "chkMyCheckBox"
ctl.DefaultValue = False
ctl.Visible = True
'etc....

Set ctl = Nothing

See Help for more details.

Wayne Gillespie
Gosford NSW Australia
 
Back
Top