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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop through Forms in Access97 1

Status
Not open for further replies.

Beren1h

Technical User
Jul 19, 2001
104
US
Hello all,

I've been trying to loop through all the forms (open and closed) in my database. I've read the help about using the documents collection of the container object, but I can't figure it out. My code (forgive the variable names):

Dim dbs As DAO.Database
Dim a As Container
Dim b As Document

Set dbs = CurrentDb

Set a = dbs.Containers("Forms")

For Each b In a

MsgBox b.Name

Next b

Can anyone tell me how to capture all the form names in an Access97 database?

Thanks...
 
Dim i As Long
For i = 0 To CurrentProject.AllForms.Count - 1
MsgBox CurrentProject.AllForms(i).Name
Next i

This worked for my in Access2000. I assume it'll work in 97, but I can't say for sure.
 
Do It With SQL.....


Sub EnumForms()

Dim r As Recordset

Set r = CurrentDb.OpenRecordset("select name from msysobjects where type=-32768")

While r.EOF = False
MsgBox r!Name
r.MoveNext
Wend

End Sub
 
Whoa Yeah! That worked perfectly Pezamystik.

You couldn't point me towards a good reference to this msysobjects (table?). It looks like there might be several useful things you could do with that...

 
You just need to be aware that direct access to system tables is not supported by Microsoft. Such code could fail in a later version of Access as they may redesign the tables or change the values stored in them.

Otherwise a good idea :)

Ken
 
I try to keep the naming convention for forms (prefix "frm", like "frmEditRecord", "frmOptions",...), this way I know exactly which are my app and which ones the system forms. E.g. this function closes all my forms...

Function closeAllForms()
Dim frm As Form
For Each frm In Forms
If Left(frm.Name, 3) = "frm" Then
DoCmd.Close acForm, frm.Name, acSaveYes
End If
Next frm
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top