Looping External forms

J

JonWayn

How can I loop thru all the forms in an external database? Say I got a
reference to the external db thru a database variable with OpenDatabase, and
I need to access the module object attached to a specific form, how do I
navigate my way to the module?
 
D

Douglas J. Steele

Try something like:

Sub ListFormsInOtherDB(DatabaseName As String)
Dim dbCurr As DAO.Database
Dim conForms As DAO.Container
Dim docCurr As DAO.Document
Dim intLoop As Integer

DoCmd.Hourglass True

Set dbCurr = DBEngine.Workspaces(0).OpenDatabase(DatabaseName)
Set conForms = dbCurr.Containers!Forms
With conForms
For Each docCurr In .Documents
Debug.Print docCurr.Name
Next docCurr
End With

Set docCurr = Nothing
Set conForms = Nothing
dbCurr.Close
Set dbCurr = Nothing

DoCmd.Hourglass False

End Sub

Note that this uses DAO code. If you're using Access 2000 or newer, you'll
need to ensure that you have a reference set to DAO. With any code module
open, select Tools | References from the menu bar, scroll through the list
of available references until you find the one for Microsoft DAO 3.6 Object
Library, and select it. If you're not going to be using ADO, uncheck the
reference to Microsoft ActiveX Data Objects 2.x Library

If you have both references, you'll find that you'll need to "disambiguate"
certain declarations, because objects with the same names exist in the 2
models. For example, to ensure that you get a DAO recordset, you'll need to
use Dim rsCurr as DAO.Recordset (to guarantee an ADO recordset, you'd use
Dim rsCurr As ADODB.Recordset)

The list of objects with the same names in the 2 models is Connection,
Error, Errors, Field, Fields, Parameter, Parameters, Property, Properties
and Recordset
 

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