|
-
Nov 19th, 2007, 02:35 AM
#1
Thread Starter
Lively Member
Open a form with name as string
Hi all
i have to open a form with its name.. my form name is in string type so i used the following code to open the form using forms object
Code:
Forms.Add(FormName).Show
and this works too.. the problem is that it opens a instance of the original form so resulting is that when i try to open the form from menu another form (ie) original form is being opened...
so plz tell me how to open a form with form name as string.. and not the instance...
-
Nov 19th, 2007, 04:33 AM
#2
Re: Open a form with name as string
If you use Forms.Add to add the form you must cycle thru the Forms collection to load it. Here's an example the way I use it.
Code:
Public Sub ShowForm(FormName As String)
Dim frm As Form
If Not IsLoaded(FormName) Then
Forms.Add (FormName)
Forms.Item(Forms.Count - 1).Tag = FormName
Else
For Each frm In Forms
If frm.Tag = FormName Then
frm.Show
End If
Next
End If
End Sub
-
Nov 19th, 2007, 04:46 AM
#3
Thread Starter
Lively Member
Re: Open a form with name as string
but what does that isLoaded function will return?
-
Nov 19th, 2007, 05:50 AM
#4
Frenzied Member
Re: Open a form with name as string
can you clarify if you want to create a form or just open a form already created during design time? If you want to just open an existing form. Iam sure you can do more with the below snippet 
Code:
Dim frm2 As Form2
Private Sub Command1_Click()
Set frm2 = New Form2
frm2.Hide
End Sub
Public Sub gOpenHiddenForm(FormToOpenName As String)
For i = 1 To Forms.Count
If Forms(i).Name = FormToOpenName Then
'Do whatever you want
'say close the openForm
'
'
Forms(i).Show
Exit Sub
End If
Next i
End Sub
-
Nov 19th, 2007, 08:54 AM
#5
Thread Starter
Lively Member
Re: Open a form with name as string
when i use the above code am getting "Subscript out of range" error....
-
Nov 19th, 2007, 09:03 AM
#6
Re: Open a form with name as string
How are you using it?
Post what you have and indicate what line is giving you the error.
-
Nov 19th, 2007, 12:07 PM
#7
Re: Open a form with name as string
Code:
Public Function IsLoaded(frmName As String) As Boolean
Dim frm As Form
IsLoaded = False
For Each frm In Forms
If frm.Tag = frmName Then
IsLoaded = True
Exit For
End If
Next
End Function
-
Nov 19th, 2007, 02:30 PM
#8
Re: Open a form with name as string
I think you might confuse him by using the tag property.
-
Nov 19th, 2007, 10:11 PM
#9
Re: Open a form with name as string
Yeah, but if it works for him he can attempt to understand it later...
-
Nov 21st, 2007, 12:57 AM
#10
Frenzied Member
Re: Open a form with name as string
when i use the above code am getting "Subscript out of range" error....
Pls post the snippet you are using so that we may be able to help you
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|