Results 1 to 13 of 13

Thread: duplicating forms at runtime RESOLVED

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    51

    Resolved duplicating forms at runtime RESOLVED

    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?
    Last edited by simgirl; Mar 20th, 2005 at 05:26 PM. Reason: Resolved

  2. #2
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313

    Re: duplicating forms at runtime

    Something like this:
    VB Code:
    1. Sub FireUpForms(ByVal iNumForms As Integer)
    2.     Dim oForm As frmComputerCards
    3.     Dim i As Integer
    4.         For i = 0 To iNumForms - 1
    5.         Set oForm = New frmComputerCards
    6.         oForm.Show
    7.         Set oForm = Nothing
    8.     Next i
    9. End Sub

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: duplicating forms at runtime

    Quote Originally Posted by simgirl
    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?
    or something like this:

    Code:
    Dim FormObj as Form
    Set FormObj = Forms.Add("frmComputerCards")
    Load FormObj

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: duplicating forms at runtime

    Quote Originally Posted by szlamany
    or something like this:

    Code:
    Dim FormObj as Form
    Set FormObj = Forms.Add("frmComputerCards")
    Load FormObj
    Does that actually create an instance of frmComputerCards?
    I use:
    Code:
    Private Sub ShowNewForm()
    Dim frmNew   As frmMyForm
       Set frmNew = New frmMyForm
       Load frmNew
       frmNew.Show
       Set frmNew = Nothing
    End Sub
    This can be extended to show items from a DB.
    Etc.
    Code:
    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
    Woka

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: duplicating forms at runtime

    Quote Originally Posted by Wokawidget
    Does that actually create an instance of frmComputerCards?
    I use:
    Code:
    Private Sub ShowNewForm()
    Dim frmNew   As frmMyForm
       Set frmNew = New frmMyForm
       Load frmNew
       frmNew.Show
       Set frmNew = Nothing
    End Sub
    This can be extended to show items from a DB.
    Etc.
    Code:
    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
    Woka
    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.

    You would have to have a different line of code for every FORM you could possibly add.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6

  7. #7

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    51

    Re: duplicating forms at runtime

    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?

  8. #8
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: duplicating forms at runtime

    Code:
    Set frmComputerCards1 = New frmComputerCards
    Load frmComputerCards1
    frmComputerCards1.Caption = "Computer Player 1"
    frmComputerCards1.txtUsername.Text = "Woka"
    frmComputerCards1.Show
    Woka

  9. #9
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: duplicating forms at runtime

    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"...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  10. #10
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: duplicating forms at runtime

    I would write this as:
    Code:
    Dim frmNew    As frmComputerCards
       Set frmNew = New frmComputerCards
       Load frmNew
       With frmNew
          .Caption = "Woof"
          .txtUsername.Text = "Woka"
          .Show
       End With
       Set frmNew = Nothing
    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.

    Woof

  11. #11

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    51

    Re: duplicating forms at runtime

    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?

  12. #12
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: duplicating forms at runtime

    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.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  13. #13

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    51

    Resolved Re: duplicating forms at runtime

    Thanks everybody for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width