Create 100 text boxes with VBA

  • Thread starter Thread starter Katrina
  • Start date Start date
K

Katrina

I would like to create 100 text boxes named
country00
to
country99

I'm sure there is a simple way to do this with code, but
I can't seem to find the command in my help files (which
seem to be corrupted.)

Thanks for any help.

Katrina
 
Check out the CreateControl method


Sub CreateControls()
DoCmd.OpenForm "Form2", acDesign
Dim ctl As Control
Dim i As Integer
Dim top As Integer
top = 0
For i = 0 To 99
Set ctl = CreateControl("Form2", acTextBox,
acDetail, , , , top)
top = top + ctl.Height
ctl.Name = "Country" & i
Next i
DoCmd.Close acForm, "Form2", acSaveYes
End Sub


Chris Nebinger
 
Katrina said:
I would like to create 100 text boxes named
country00
to
country99

I'm sure there is a simple way to do this with code, but
I can't seem to find the command in my help files (which
seem to be corrupted.)


When/Why do you want to do this?

If you just want to save yourself some typing time while
you're designing a form, you can create a Sub procedure in a
standard module that uses the CreateControl method. Fix
your Help files so you can see all the details.

If you're thinking about doing this at run time, forget it.
Precreate the controls at deisgn time and then make them
Visible as needed.
 
Back
Top