-
This is the way I would do that... Does this code work with you?[VBA]Sub CreateForm()
Dim frmNewForm As Object
Dim TextBox As MSForms.TextBox
Dim LineCounter As Long
Application.VBE.MainWindow.Visible = False
Set frmNewForm = ThisWorkbook.VBProject.VBComponents.Add(3)
Set TextBox = frmNewForm.Designer.Controls.Add("Forms.TextBox.1")
With frmNewForm.CodeModule
LineCounter = .countoflines
.insertlines LineCounter + 1, "Private Sub TextBox1_Change()"
.insertlines LineCounter + 2, vbTab & "If Me.TextBox1.Text <> " & """""" & " Then TextBoxChange"
.insertlines LineCounter + 3, "End Sub"
End With
End Sub
Sub TextBoxChange()
MsgBox "Lots of code firing here"
End Sub
[/VBA]Although I don't create forms on the fly that often - there's a lot you can do in a form's initialize event to handle most situations and I tend to favour that approach if possible
K :-)

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules