How do you duplicate a form at run time? I got a form called frmComputerCards. I wanting to duplicate the form and have it work the same way that frmcomputercards works. Is that possible?
Printable View
How do you duplicate a form at run time? I got a form called frmComputerCards. I wanting to duplicate the form and have it work the same way that frmcomputercards works. Is that possible?
Something like this:
VB Code:
Sub FireUpForms(ByVal iNumForms As Integer) Dim oForm As frmComputerCards Dim i As Integer For i = 0 To iNumForms - 1 Set oForm = New frmComputerCards oForm.Show Set oForm = Nothing Next i End Sub
or something like this:Quote:
Originally Posted by simgirl
Code:Dim FormObj as Form
Set FormObj = Forms.Add("frmComputerCards")
Load FormObj
Does that actually create an instance of frmComputerCards?Quote:
Originally Posted by szlamany
I use:
This can be extended to show items from a DB.Code:Private Sub ShowNewForm()
Dim frmNew As frmMyForm
Set frmNew = New frmMyForm
Load frmNew
frmNew.Show
Set frmNew = Nothing
End Sub
Etc.
WokaCode:Private Sub ShowUser(ByVal plngUserID As Long)
Dim frmNew As frmUser
'code to load user data/object (this can also be in the form load if you want)
Set frmNew = New frmMyForm
'pass data/object to form
Load frmNew
frmNew.Show
Set frmNew = Nothing
End Sub
Yes it does - and the reason we use it is because the FORM name can be in a variable. That's helpful in a MDI-type app.Quote:
Originally Posted by Wokawidget
You would have to have a different line of code for every FORM you could possibly add.
I didn't know that.
Very handy to know :thumb:
Woka
I am able now to duplicate a form but not changing anything on the duplicated form at run time. I can't change the text in labels or anything. How can I fix that problem?
frmMenu
Set frmComputerCards1 = New frmComputerCards
frmComputerCards1.Caption = "Computer Player 1"
frmComputerCards1.Show
I'm trying to make changes to that new form from the main players game screen form. Why am I getting this problem?
WokaCode:Set frmComputerCards1 = New frmComputerCards
Load frmComputerCards1
frmComputerCards1.Caption = "Computer Player 1"
frmComputerCards1.txtUsername.Text = "Woka"
frmComputerCards1.Show
Keep in mind that "frmComputerCards1" is a form object local to whatever sub/func you are creating the new instance of the form in.
It will not be the name of the form throughout the program - right?
We always use the FORMS() collection to access the forms we "duplicate"...
I would write this as:
szlamany, yup, you are right. frmNew will only be a local object name in the confines of the funtion you have: Dim frmNew As, in.Code:Dim frmNew As frmComputerCards
Set frmNew = New frmComputerCards
Load frmNew
With frmNew
.Caption = "Woof"
.txtUsername.Text = "Woka"
.Show
End With
Set frmNew = Nothing
Woof
Thanks that helped a lot. I got 1 last question related to this topic. If I want the user to be able to choose between 1 to 8 computer players. Whats the easiest way to load the forms?
Use either method - FORMS.ADD("formname") or the .SHOW/LOAD method with a FORM object.
But then in some GLOBAL array you could store the (FORMS.COUNT-1) value of the newly added form.
You can refer to the form by FORMS(x).whatever with x being the value of the newly added form.
Thanks everybody for your help.