Results 1 to 3 of 3

Thread: Loading Forms

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2000
    Location
    Edmonton,AB, Canada
    Posts
    30

    Post

    I am trying to load forms into memory using a generic load form routing and I keep getting a "Type Mismatch Error". I would like to do something like the following:

    Function fcnLoadForm(strFormName As String)
    Forms(strFormName).Load
    End Function

    Or

    Function fcnLoadForm(strFromName As String)
    Load strFormName
    End Function

    I know that I should be able to do something like this, but at this moment in time it is eluding me.

    Also I am noticing and confirmed with MSDN that a Form is only in the Forms Collection after it is loaded into memory.

    Any help would be greatly appreciated.
    Thank you
    Candu

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Try this:
    Code:
    Private Sub Command1_Click()
        LoadForm "Form3", True
    End Sub
    
    Sub LoadForm(ByVal Formname As String, Optional ByVal bShow As Boolean = False)
        Dim iIndex As Integer
        
        'Add the Form to the Forms Collection
        '>>> Formname MUST exist to add it to the Collection <<<
        Forms.Add Formname
        'Find the Index of the Form we just added
        For iIndex = 0 To Forms.Count - 1
            If Forms(iIndex).Name = Formname Then Exit For
        Next
        If iIndex < Forms.Count Then
            'If the Form Existed Then Load it
            Load Forms(iIndex)
            If bShow Then Forms(iIndex).Show
        End If
    End Sub
    I included the Optional Parameter bShow so you can Show the Form after loading it if you want to.

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2000
    Location
    Edmonton,AB, Canada
    Posts
    30

    Post

    Thank you very much Araon. Your solution works like a charm.

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