Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listing ALL forms in an application

Status
Not open for further replies.

shabnam

Programmer
Oct 3, 2000
26
0
0
US
Is there some way to list all the forms that are present in an application. I cannot use the forms collection since it only lists the loaded forms, I want to list ALL the forms that are part of an application
 
You can get the list from the project file .vbp. Probably not the solution you were looking for but here it is.

Dim strTest As String

Open "C:\SomeDir\ProjectFile.vbp" For Input As #1
Do While Not EOF(#1)
Input #1, strTest
If Left(strTest, 5) = "Form=" Then
debug.print Mid(strTest,6)
End If
Loop
Close #1
 
Actually, aside from the somewhat slow line input method, I believe it is the prefered method for VB. On the other hand, the question "looks like" an MS Access question. If THAT is the case, it is definitly not the approach, but iteration through the AllForms Collection could be used (Ms. A. 2K) or through the Forms DOCUMENTS fr earliser versions. Help is helpful for either / both (in Ms. A.)


MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Thanks for that - the application is in VB and so I cannot use AllForms property.

Now I have all the form names but how do I load them ?

Load needs a specific name cannot use

dim s as string
s = "form1"
load s

I have to say
load form1

Is there an API I can use and pass it the name of a form in a variable?
 
I think that:

myfrm = "MyFrmNameAsStr"

Load MyFrm = Forms(myfrm)

is acceptable.


It is at least CLOSE, so check the ever helpful "HELP" ... it is generally better at the exact syntax for simple operations and it is certainly faster to respond than any web site.

MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Don't think you need an API call - just add the form to the Forms Collection and it will be loaded (but not shown)

[tt]
Dim strForm As String
strForm = "Form4"
Forms.Add strForm
[/tt]
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Try this: add this code to a new project along with 2 forms Form1 and Form2 add a command button to Form1.

Public colForms As New Collection

Public Sub LoadForm(strFormName As String)
Dim frm As Form
Set frm = colForms(strFormName)
frm.Show
End Sub
Private Sub Command1_Click()
Dim i As Integer
Dim strForm As String
strForm = "Form2"
colForms.Add Form2, "Form2"
LoadForm (strForm)
End Sub
 
Oh - just do a search for FormByName in this forum. There have been several solutions to this posted.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top