Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AutoCreate and fill Textboxes within a User From

Status
Not open for further replies.

bdmangum

Technical User
Dec 6, 2006
171
US
Hi,

I can't seem to get a textbox to programmatically add to a user form with the "AddTextBox" command. I'm unaware of another command which I could use to add a textbox. Also does anyone know of a way to autosize a form?

The code gets a compile error at the bolded section.

Code:
Private Sub UserForm_Initialize()

'Stores selected System in TextBox1
    TextBox1.Value = Sheets(2).Range("A1").Value
    
'Start Stores all Sub-Systems in auto-created textboxes
    Dim tNewObject As TextBox
    
'Sets WidthVar
    TempCount = 2
    WidthVar = 0
    While Worksheets(2).Cells(2, TempCount).Value <> ""
        TempCount = TempCount + 4
        WidthVar = WidthVar + 1
    Wend
    
'Inputs textboxes
    TempCount = 2
    While Worksheets(2).Cells(2, TempCount).Value <> ""
    
    'Sets position and size variables
        PosW = 12.75
        PosH = 23.25
        PosL = (Summary1.Width / WidthVar)
        PosTop = 66
        
    'Adds Textboxes
        With Summary1
            [b]Set tNewObject = .AddTextbox(msoTextOrientationHorizontal, PosL, PosTop, PosW, PosH)[/b]
            With tNewObject
                .Value = "Worksheets(2).Cells(2, TempCount).Value"
            End With
        End With
    Wend
'End Store all Sub-Systems in auto-created textboxes


'Auto-Sizes Form
    With Summary1
        .AutoSize = True
    End With

End Sub
 


Hi,

Different ADD...
Code:
    Dim tNewObject
    PosW = 12.75
    PosH = 23.25
    PosL = (UserForm1.Width / 2)
    PosTop = 66
    With UserForm1
        Set tNewObject = .Controls.Add("Forms.TextBox.1")
        With tNewObject
            .Left = PosL
            .Top = PosL
            .Width = PosW
            .Height = PosH
        End With
    End With

Skip,

[glasses] [red][/red]
[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top