PDA

Click to See Complete Forum and Search --> : Loading Forms


Candu
Jan 19th, 2000, 01:10 AM
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

Aaron Young
Jan 19th, 2000, 01:52 AM
Try this:

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
aarony@redwingsoftware.com
ajyoung@pressenter.com

Candu
Jan 19th, 2000, 07:49 PM
Thank you very much Araon. Your solution works like a charm.