How to enumerate forms i DB

D

Domac

I would like to enumerate all forms in my Db.
No matter if it is open or closed.


Thanks!
 
A

Arvin Meyer [MVP]

Domac said:
I would like to enumerate all forms in my Db.
No matter if it is open or closed.

This will fill a listbox (lstFormList) with all the form names:

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Handler
Dim db As Database
Dim i As Integer
Dim contr As Container
Dim strFormList As String
Dim StrFormName As String
Dim Length As Integer

Set db = CurrentDb()
Set contr = db.Containers("Forms")

strFormList = ""
For i = 0 To contr.Documents.Count - 1
StrFormName = contr.Documents(i).name
If strFormList <> "" Then strFormList = strFormList & ";"
Length = Len(StrFormName)
strFormList = strFormList & StrFormName
Next i

Me!lstFormList.RowSource = strFormList

Exit_Here:
Exit Sub
Err_Handler:
msgbox err & " " & Error, , "Form Open"
Resume Exit_Here

End Sub
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
G

Guest

Arvin Meyer said:
For i = 0 To contr.Documents.Count - 1
StrFormName = contr.Documents(i).name

Arvin, what does one do to get form object references,
either instead of strings or by converting strings ?
(I thought that maybe it would be contr.Documents(i), but it is not.)
 
D

Douglas J. Steele

miguel said:
I figured it out. It would be Forms(strFormName).

Yes, but note that you can only do that if the form is already open, as the
Forms collection only contains open forms.

If the form of interest isn't already open, you'll have to use
DoCmd.OpenForm to open it first. (You can open it hidden if need be)
 
G

Guest

It would be Forms(strFormName).

Douglas J. Steele said:
Yes, but note that you can only do that if the form is already open, as the
Forms collection only contains open forms.

Right. In my immediate case, open form also is required by the operations
that demand object reference.

I imagine that some operations that demand object reference may not require
open form, in which case I would prefer to provide a form reference that does
not depend on open state. What would be the reference syntax then?
 
D

Douglas J. Steele

miguel said:
Right. In my immediate case, open form also is required by the operations
that demand object reference.

I imagine that some operations that demand object reference may not
require
open form, in which case I would prefer to provide a form reference that
does
not depend on open state. What would be the reference syntax then?

If by "form reference", you mean you want to be able to work with objects on
the form, there is no other way but to open the form and refer to it using
the syntax you've already determine.

If all you're trying to do is get the list of forms, Arvin's shown you how.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top