This was discussed before. Please refer to the link below which will explain quite a lot about your question as well as more links to follow. http://www.daniweb.com/forums/thread96518.html
Try the following. Is this what you required help on?
Option Explicit
Private newCtrl As Control
Private Sub menuName_Click()
Dim frmNew As New Form1
With frmNew
.Show
.Caption = "My New Form"
.menuName.Visible = False 'You only want one instance of a form
End With
Set newCtrl = Form1.Controls.Add("vb.textbox", "txtTextBox", Form1)
newCtrl.Visible = True
newCtrl.Move 2000, 500, 1500, 250 'Change placement to whatever you need
menuName.Visible = False 'You only want one instance of a form
Call txtBoxName(Form1) 'Add random number to textbox
End Sub
Private Sub txtBoxName(frm As Form)
Dim strCount As String
Dim Control As Control
strCount = Int(100000 * Rnd() + 1)
For Each Control In frm.Controls
If TypeOf Control Is TextBox Then
Control.Text = strCount
End If
Next Control
End Sub
I'm making a text editor like notepad but better because i'm using an mdiform so you can have multiple files open at once.
This is the code i got.
MDIForm:
Private Sub menuAbout_Click()
frm_About.Show
End Sub
Private Sub menuName_Click()
frm_New.Show
End Sub
Private Sub menuOpen_Click()
frm_open.Show
End Sub
Private Sub menuSave_Click()
' loads save as box
MDIForm1.CommonDialog1.ShowSave
On Error GoTo error
filelocation = MDIForm1.CommonDialog1.FileName
Me.ActiveForm.Caption = MDIForm1.CommonDialog1.FileTitle
' append saves over file if it assists
Open filelocation For Output As #1
Close #1
Open filelocation For Append As #1
Print #1, Me.ActiveForm.Text1.Text
Close #1
GoTo endload
error:
errorreport (0)
endload:
End Sub
Function errorreport(error)
Dim intResponse As Integer
intResponse = MsgBox("There was an Error wile trying to load", vbExclamation, "Quit")
End Function
frm_open:
Private Sub Form_Load()
MDIForm1.CommonDialog1.ShowOpen
Me.Caption = MDIForm1.CommonDialog1.FileTitle
FileName = MDIForm1.CommonDialog1.FileName
On Error GoTo error
Open FileName For Input As #1
Do Until EOF(1)
Input #1, Data
Me.Text1.Text = Me.Text1.Text + Data + vbCrLf
EOF (1)
Loop
Close #1
FileName = ""
GoTo endload
error:
errorreport (0)
endload:
End Sub
Function errorreport(error)
Dim intResponse As Integer
intResponse = MsgBox("There was an Error wile trying to load", vbExclamation, "Quit")
End Function
Private Sub Form_Resize()
Text1.Height = Me.ScaleHeight
Text1.Width = Me.ScaleWidth
End Sub
frm_new:
Private Sub Form_Load()
Me.Caption = "text.txt"
End Sub
Private Sub Form_Resize()
Text1.Height = Me.ScaleHeight
Text1.Width = Me.ScaleWidth
End Sub
I've also got an about form but i don't think you need that.
So i need one text box on each form and up to 100 forms or so open at once (ill make a new version if someone needs more than that open at once).