PC Review


Reply
Thread Tools Rate Thread

Allforms Collection in another db (A2007)

 
 
JimS
Guest
Posts: n/a
 
      7th Jan 2010
I want to walk through the Allforms collection (and the querydefs, etc
collections) from one db("object") to another("source") (both A2007). I want
to use the last modified date from the source db to populate a listbox on the
object db. I'll then ask the user to select the forms (queries, etc.) he
wants to transfer to the object db. Similar to the Access Wizard, except the
Access Import wizard doesn't tell me anything about the forms, queries, etc.
I'm transferring.

Anyway, how do I refer to the forms collection on another database using
vba? It appears I use the "OpenDatabase" method, but I haven't gotten much
farther.

Thanks in advance!
--
Jim
 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      8th Jan 2010
"JimS" <(E-Mail Removed)> wrote in message
news:B80D7BAE-FD76-4944-8FD9-(E-Mail Removed)...
>I want to walk through the Allforms collection (and the querydefs, etc
> collections) from one db("object") to another("source") (both A2007). I
> want
> to use the last modified date from the source db to populate a listbox on
> the
> object db. I'll then ask the user to select the forms (queries, etc.) he
> wants to transfer to the object db. Similar to the Access Wizard, except
> the
> Access Import wizard doesn't tell me anything about the forms, queries,
> etc.
> I'm transferring.
>
> Anyway, how do I refer to the forms collection on another database using
> vba? It appears I use the "OpenDatabase" method, but I haven't gotten much
> farther.



You can't get at the "All..." collections of another database without
opening the database in an instance of Access, because those collections are
properties of the CurrentProject and CurrentData objects, which are in turn
properties of the Access Application object. If you must, you can open the
other database in a separate instance of Access, and get at the collections
in that instance by automation. For this approach, you would not be using
the DAO OpenDatabase method. But it's a lot of overhead to incur for what
you want to do.

Instead, you can use the OpenDatabase method to open a DAO Database object,
and use various collections belonging to the Database object to get the
information you want. It's not quite as tidy as the All... collections,
because the appropriate collections vary according to the type of object.

Suppose you wanted to build a list of all the tables, queries, forms,
reports, macros, and modules in a database. Suppose you have a text box
named "txtDBPath" on a form, where the user has entered the path to the
database in question. Suppose you also have a list box named "lstObjects",
with three columns for the object type, object name, and last-updated date
of each object. Then you might have a function like this to list the
objects in the database:

'------ start of code ------
Function ListObjects()

On Error GoTo Err_Handler

Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim qdf As DAO.QueryDef
Dim cnt As DAO.Container
Dim doc As DAO.Document
Dim strObjType As String
Dim strObjName As String
Dim strObjDate As String

' Clear the list box, to start with.
Me.lstObjects.RowSource = ""

If IsNull(Me.txtDBPath) Then
Exit Function
End If

DoCmd.Hourglass True

Set db = DBEngine.OpenDatabase(Me.txtDBPath, , True)

' Add all tables to the list box.
strObjType = "Table"
For Each tdf In db.TableDefs
strObjName = tdf.Name
If Left(strObjName, 4) <> "MSys" Then
strObjDate = Format(tdf.LastUpdated, "short date")
Me.lstObjects.AddItem _
strObjType & ";" & strObjName & ";" & strObjDate
End If
Next tdf

' Add all queries to the list box.
strObjType = "Query"
For Each qdf In db.QueryDefs
strObjName = qdf.Name
If Left(strObjName, 3) <> "~sq" Then
strObjDate = Format(qdf.LastUpdated, "short date")
Me.lstObjects.AddItem _
strObjType & ";" & strObjName & ";" & strObjDate
End If
Next qdf

' Add all forms to the list box.
strObjType = "Form"
Set cnt = db.Containers("Forms")
For Each doc In cnt.Documents
strObjName = doc.Name
strObjDate = Format(doc.LastUpdated, "short date")
Me.lstObjects.AddItem _
strObjType & ";" & strObjName & ";" & strObjDate
Next doc
Set cnt = Nothing

' Add all reports to the list box.
strObjType = "Report"
Set cnt = db.Containers("Reports")
For Each doc In cnt.Documents
strObjName = doc.Name
strObjDate = Format(doc.LastUpdated, "short date")
Me.lstObjects.AddItem _
strObjType & ";" & strObjName & ";" & strObjDate
Next doc
Set cnt = Nothing

' Add all macros to the list box.
strObjType = "Macro"
Set cnt = db.Containers("Scripts")
For Each doc In cnt.Documents
strObjName = doc.Name
strObjDate = Format(doc.LastUpdated, "short date")
Me.lstObjects.AddItem _
strObjType & ";" & strObjName & ";" & strObjDate
Next doc
Set cnt = Nothing

' Add all modules to the list box.
strObjType = "Module"
Set cnt = db.Containers("Modules")
For Each doc In cnt.Documents
strObjName = doc.Name
strObjDate = Format(doc.LastUpdated, "short date")
Me.lstObjects.AddItem _
strObjType & ";" & strObjName & ";" & strObjDate
Next doc
Set cnt = Nothing

Exit_Point:
On Error Resume Next
DoCmd.Hourglass False
If Not db Is Nothing Then
db.Close
Set db = Nothing
End If
Exit Function

Err_Handler:
DoCmd.Hourglass False
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_Point

End Function
'------ end of code ------

You could call the function from the AfterUpdate event of the text box.

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

 
Reply With Quote
 
JimS
Guest
Posts: n/a
 
      8th Jan 2010
Dick, you've gone way above and beyond. Thank you so much. I learn from you
guys every day.

My objective is to identify all routines with a modified date that's more
recent than my production front end. I use sandboxes, then transfer objects
I've modified to the production front end. I use Tony's autofe as well.

Once I've identified the ones I need to transfer (I suggest to the user
which ones have changed by selecting them, then letting the user alter the
selections...) I think I can transfer them with one of the standard access
methods. What if I wanted the program to be in a third db, pointing to the
source and object db's?

Is that doable?

--
JimS


"Dirk Goldgar" wrote:

> "JimS" <(E-Mail Removed)> wrote in message
> news:B80D7BAE-FD76-4944-8FD9-(E-Mail Removed)...
> >I want to walk through the Allforms collection (and the querydefs, etc
> > collections) from one db("object") to another("source") (both A2007). I
> > want
> > to use the last modified date from the source db to populate a listbox on
> > the
> > object db. I'll then ask the user to select the forms (queries, etc.) he
> > wants to transfer to the object db. Similar to the Access Wizard, except
> > the
> > Access Import wizard doesn't tell me anything about the forms, queries,
> > etc.
> > I'm transferring.
> >
> > Anyway, how do I refer to the forms collection on another database using
> > vba? It appears I use the "OpenDatabase" method, but I haven't gotten much
> > farther.

>
>
> You can't get at the "All..." collections of another database without
> opening the database in an instance of Access, because those collections are
> properties of the CurrentProject and CurrentData objects, which are in turn
> properties of the Access Application object. If you must, you can open the
> other database in a separate instance of Access, and get at the collections
> in that instance by automation. For this approach, you would not be using
> the DAO OpenDatabase method. But it's a lot of overhead to incur for what
> you want to do.
>
> Instead, you can use the OpenDatabase method to open a DAO Database object,
> and use various collections belonging to the Database object to get the
> information you want. It's not quite as tidy as the All... collections,
> because the appropriate collections vary according to the type of object.
>
> Suppose you wanted to build a list of all the tables, queries, forms,
> reports, macros, and modules in a database. Suppose you have a text box
> named "txtDBPath" on a form, where the user has entered the path to the
> database in question. Suppose you also have a list box named "lstObjects",
> with three columns for the object type, object name, and last-updated date
> of each object. Then you might have a function like this to list the
> objects in the database:
>
> '------ start of code ------
> Function ListObjects()
>
> On Error GoTo Err_Handler
>
> Dim db As DAO.Database
> Dim tdf As DAO.TableDef
> Dim qdf As DAO.QueryDef
> Dim cnt As DAO.Container
> Dim doc As DAO.Document
> Dim strObjType As String
> Dim strObjName As String
> Dim strObjDate As String
>
> ' Clear the list box, to start with.
> Me.lstObjects.RowSource = ""
>
> If IsNull(Me.txtDBPath) Then
> Exit Function
> End If
>
> DoCmd.Hourglass True
>
> Set db = DBEngine.OpenDatabase(Me.txtDBPath, , True)
>
> ' Add all tables to the list box.
> strObjType = "Table"
> For Each tdf In db.TableDefs
> strObjName = tdf.Name
> If Left(strObjName, 4) <> "MSys" Then
> strObjDate = Format(tdf.LastUpdated, "short date")
> Me.lstObjects.AddItem _
> strObjType & ";" & strObjName & ";" & strObjDate
> End If
> Next tdf
>
> ' Add all queries to the list box.
> strObjType = "Query"
> For Each qdf In db.QueryDefs
> strObjName = qdf.Name
> If Left(strObjName, 3) <> "~sq" Then
> strObjDate = Format(qdf.LastUpdated, "short date")
> Me.lstObjects.AddItem _
> strObjType & ";" & strObjName & ";" & strObjDate
> End If
> Next qdf
>
> ' Add all forms to the list box.
> strObjType = "Form"
> Set cnt = db.Containers("Forms")
> For Each doc In cnt.Documents
> strObjName = doc.Name
> strObjDate = Format(doc.LastUpdated, "short date")
> Me.lstObjects.AddItem _
> strObjType & ";" & strObjName & ";" & strObjDate
> Next doc
> Set cnt = Nothing
>
> ' Add all reports to the list box.
> strObjType = "Report"
> Set cnt = db.Containers("Reports")
> For Each doc In cnt.Documents
> strObjName = doc.Name
> strObjDate = Format(doc.LastUpdated, "short date")
> Me.lstObjects.AddItem _
> strObjType & ";" & strObjName & ";" & strObjDate
> Next doc
> Set cnt = Nothing
>
> ' Add all macros to the list box.
> strObjType = "Macro"
> Set cnt = db.Containers("Scripts")
> For Each doc In cnt.Documents
> strObjName = doc.Name
> strObjDate = Format(doc.LastUpdated, "short date")
> Me.lstObjects.AddItem _
> strObjType & ";" & strObjName & ";" & strObjDate
> Next doc
> Set cnt = Nothing
>
> ' Add all modules to the list box.
> strObjType = "Module"
> Set cnt = db.Containers("Modules")
> For Each doc In cnt.Documents
> strObjName = doc.Name
> strObjDate = Format(doc.LastUpdated, "short date")
> Me.lstObjects.AddItem _
> strObjType & ";" & strObjName & ";" & strObjDate
> Next doc
> Set cnt = Nothing
>
> Exit_Point:
> On Error Resume Next
> DoCmd.Hourglass False
> If Not db Is Nothing Then
> db.Close
> Set db = Nothing
> End If
> Exit Function
>
> Err_Handler:
> DoCmd.Hourglass False
> MsgBox Err.Description, vbExclamation, "Error " & Err.Number
> Resume Exit_Point
>
> End Function
> '------ end of code ------
>
> You could call the function from the AfterUpdate event of the text box.
>
> --
> Dirk Goldgar, MS Access MVP
> Access tips: www.datagnostics.com/tips.html
>
> (please reply to the newsgroup)
>

 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      8th Jan 2010
"JimS" <(E-Mail Removed)> wrote in message
news:88E9481D-27B3-4BD6-BD4B-(E-Mail Removed)...
>
> My objective is to identify all routines with a modified date that's more
> recent than my production front end. I use sandboxes, then transfer
> objects
> I've modified to the production front end. I use Tony's autofe as well.
>
> Once I've identified the ones I need to transfer (I suggest to the user
> which ones have changed by selecting them, then letting the user alter the
> selections...) I think I can transfer them with one of the standard access
> methods. What if I wanted the program to be in a third db, pointing to the
> source and object db's?
>
> Is that doable?



Should be, but with certain complications. The TransferDatabase and
CopyObject methods only take one database argument; they assume that one of
the databases participating in the operation is the current one. You could
handle this by first importing an object from the source DB to the utility
DB, then exporting it from the utility DB to the target DB, and then
deleting the object from the utility DB. Or you could go ahead and open
either the target or the source database in a second, hidden instance of
Access via automation, and import/export the selected objects using that
instance. You would want to suppress any startup code in the database that
you opened in that way -- see http://www.mvps.org/access/api/api0068.htm .

Both of those approaches have drawbacks, but I'd be inclined to use the
utility application as a middleman, importing into it and exporting from it,
just for simplicity's sake. It's not something I've done, so I don't have
any real experience to draw on. The closest I've come is using a "patch" DB
to update a production database, but in that case all the objects to be
transfered were already in the patch DB.

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

 
Reply With Quote
 
JimS
Guest
Posts: n/a
 
      8th Jan 2010
Good thoughts, resources and judgements. Thank you for that, it's exactly
what I need. I'll let you know what I end up with. Perhaps I'll publish it
for others.
--
Jim


"Dirk Goldgar" wrote:

> "JimS" <(E-Mail Removed)> wrote in message
> news:88E9481D-27B3-4BD6-BD4B-(E-Mail Removed)...
> >
> > My objective is to identify all routines with a modified date that's more
> > recent than my production front end. I use sandboxes, then transfer
> > objects
> > I've modified to the production front end. I use Tony's autofe as well.
> >
> > Once I've identified the ones I need to transfer (I suggest to the user
> > which ones have changed by selecting them, then letting the user alter the
> > selections...) I think I can transfer them with one of the standard access
> > methods. What if I wanted the program to be in a third db, pointing to the
> > source and object db's?
> >
> > Is that doable?

>
>
> Should be, but with certain complications. The TransferDatabase and
> CopyObject methods only take one database argument; they assume that one of
> the databases participating in the operation is the current one. You could
> handle this by first importing an object from the source DB to the utility
> DB, then exporting it from the utility DB to the target DB, and then
> deleting the object from the utility DB. Or you could go ahead and open
> either the target or the source database in a second, hidden instance of
> Access via automation, and import/export the selected objects using that
> instance. You would want to suppress any startup code in the database that
> you opened in that way -- see http://www.mvps.org/access/api/api0068.htm .
>
> Both of those approaches have drawbacks, but I'd be inclined to use the
> utility application as a middleman, importing into it and exporting from it,
> just for simplicity's sake. It's not something I've done, so I don't have
> any real experience to draw on. The closest I've come is using a "patch" DB
> to update a production database, but in that case all the objects to be
> transfered were already in the patch DB.
>
> --
> Dirk Goldgar, MS Access MVP
> Access tips: www.datagnostics.com/tips.html
>
> (please reply to the newsgroup)
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A2007 Data Collection via Email Guy Microsoft Access VBA Modules 0 23rd Jan 2008 12:19 AM
AllForms Collection Ghost Dog Microsoft Access 4 11th Sep 2005 10:26 AM
Enumerating Through the AllForms Collection and Setting Properties For All Forms Stuart Conner via AccessMonster.com Microsoft Access Form Coding 1 30th Dec 2004 09:38 AM
Re: Proper use of the AllForms collection Gerald Stanley Microsoft Access Forms 0 27th Aug 2004 09:47 PM
RE: Proper use of the AllForms collection =?Utf-8?B?SXZhciBTdmVuZHNlbg==?= Microsoft Access Forms 0 27th Aug 2004 09:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:21 AM.