creating textbox using commands

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • elias97pro
    New Member
    • Feb 2014
    • 1

    creating textbox using commands

    i've got this code to create a textbox using a command button but i can't understand anything of it , please can you explain what each word especially(set, prevtextcontrol ,controlid) mean and what each line mean, here is the code :
    Code:
    Private Sub Command1_Click()
        Dim TextControl As TextBox
        Dim PrevTextControl As TextBox
        ControlID = ControlID + 1
        Set TextControl = Form1.Controls.Add("Vb.TextBox", "Text" & ControlID)
        If (ControlID > 1) Then
            Set PrevTextControl = Form1.Controls("Text" & (ControlID - 1))
        Else
            Set PrevTextControl = TextControl
        End If
        With TextControl
            .Left = (PrevTextControl.Left + PrevTextControl.Width) + 10
            .Top = 20
            .Width = 50
            .Height = 20
            .Visible = True
        End With
    End Sub
    Last edited by Rabbit; Feb 26 '14, 07:24 PM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.
  • Honduras2811
    New Member
    • Apr 2014
    • 21

    #2
    Each object on a form has a ControlID for use by the system. When you create a new object you have to create a new ControlID for it. Textboxes also need to know the ControlID of the previous Textbox, probably because of the Validation option.

    The line that starts with set instantiates the new Textbox.
    Everything after the line that starts with 'With' just sets the position of the new Textbox.
    All the If End If structure is doing is getting the ControlID of the previous Textbox if there is one.

    Comment

    Working...