View Single Post
  #4 (permalink)  
Old January 8th, 2005, 10:03 AM
Bob Bedell Bob Bedell is offline
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

1. Open the form you want to add the control to (Form2) in design view and hide it.
2. Add a new control using the CreateControl method.
3. Toggle the form to normal view.

Also, to position the new control you are working in twips (1" * 1440), not inches.

==Code============================================ =======

' Form1 code module
Private Sub Command1_Click()

    ' used to convert inches to twips
    Const twipsPerInch As Long = 1440

    ' Open form you want to add control to
    ' in design view and hide it.
    DoCmd.OpenForm "Form2", acDesign, , , , acHidden

    ' Add new control
    With CreateControl( _
             FormName:="Form2", _
             ControlType:=acTextBox, _
             Section:=acDetail, _
             Left:=1 * twipsPerInch, _
             Top:=1 * twipsPerInch, _
             Height:=0.25 * twipsPerInch, _
             Width:=1 * twipsPerInch)

             ' set control properties
             .Name = "txtTextBox"
    End With

    ' toggle form to Normal view
    DoCmd.OpenForm "Form2"
End Sub

HTH,

Bob


Reply With Quote