Looping External forms

  • Thread starter Thread starter JonWayn
  • Start date Start date
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?
 
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
 
Back
Top