Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How difficult would it be to list all objects in database by last modification date?

56 views
Skip to first unread message

MLH

unread,
Aug 8, 2007, 2:13:36 AM8/8/07
to
Would like to extract list of database objects
in A97 database and each of their last-modified
dates. What's the best way to proceed? And, is
the last-modified date a property I can read in a
straightforward approach?

Salad

unread,
Aug 8, 2007, 3:53:46 AM8/8/07
to
MLH wrote:

Not very difficult. Here's an axample for tables.
Sub LastTdfMod()
Dim tdf As TableDef
For Each tdf In CurrentDb.TableDefs
MsgBox tdf.name & " " & tdf.LastUpdated & " " & tdf.DateCreated
End If
Next
Endif

Sub LastQDFMod()
Dim qdf As QueryDef
For Each qdf In CurrentDb.QueryDefs
MsgBox qdf.name & " " & qdf.LastUpdated & " " & qdf.DateCreated
End If
Next
Endif

For forms, reports, modules use Document. Ex:
Dim dbs As Database
Dim doc As Document

Set dbs = CurrentDb

With dbs.Containers!Forms
For Each doc In .Documents

Use !Script for Macros

MLH

unread,
Aug 8, 2007, 7:48:08 AM8/8/07
to
Thx, Salad

I got the impression, when reading HELP on LastUpdated
and LastModified, the date returned would be the most recent
date changes were made to DATA in the table. I was more
interested in other database objects, though. Am looking forward
to trying your suggestions on form & report objects.

MLH
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

lyle

unread,
Aug 8, 2007, 9:08:31 AM8/8/07
to

It would take you a few minutes examining the Object Browser. The use
of the Object Browser has been explained to you before. It seems you
have ignored the advice, in favour of posting questions here.

It took me less than a minute to find

Debug.Print DBEngine(0)(0).Containers("Forms")
("Categories").Properties("DateCreated").Value
Debug.Print DBEngine(0)(0).Containers("Forms")
("Categories").Properties("LastUpdated").Value

which show

1995-09-13 10:51:50
2007-08-05 11:22:27

for the form "Categories" in my copy of Northwinds.mdb in Access 2000.

It would take me perhaps two minutes to loop through all the objects
and retrieve these values for all the exposed objects in the db.

It might have taken you a little longer but not as long as waiting for
answers here.

If you were to practice using the Object Browser you might even be
able (and willing?) to answer a few questions.

And David might remove you from his killfile; and you might learn
something. But I guess we couldn't count on that.

MLH

unread,
Aug 8, 2007, 9:34:58 AM8/8/07
to
I appreciate both the answer and the criticism.

>
>It would take you a few minutes examining the Object Browser. The use
>of the Object Browser has been explained to you before. It seems you
>have ignored the advice, in favour of posting questions here.
>
>It took me less than a minute to find
We each have our own areas of expertise now, don't we?
I cannot recall the last time I fooled with the Object Browser.
I'll take another look at it, as you have suggested. Thanks
for taking the 1 minute to share your knowledge with this NG.
I'm sure I'm not the only one who appreciates your generousity.

MLH

unread,
Aug 8, 2007, 10:09:30 AM8/8/07
to
I'll try to contribute by taking your example code and expanding upon
it, posting the procedure for looping through all the form objects...

Testing your posted example in my own MDB...
Debug.Print
DBEngine(0)(0).Containers("Forms")("frmMainMenu").Properties("DateCreated").Value
4/10/2007 9:18:37 PM
Debug.Print
DBEngine(0)(0).Containers("Forms")("frmMainMenu").Properties("LastUpdated").Value
8/6/2007 9:23:04 PM

That worked just as you said. Then I tried taking one more baby
step...
Dim dbs As Database, wsp As Workspace, ctr As Container, MyForm As
Form
' Return reference to default workspace.
100 Set wsp = DBEngine.Workspaces(0)
' Return reference to current database.
120 Set dbs = CurrentDb
' Return reference to Modules container.
140 Set ctr = dbs.Containers!Forms
MsgBox ctr.Count
160 For Each MyForm In ctr
180 Debug.Print MyForm.Name
200 Next MyForm
220 Set dbs = Nothing

Of course, I got an error in line #160. To enumerate the names of the
form objects in Container ctr - what syntax should I be using in lines
160 to 200? I thought the above would work - but it didn't.

MLH

unread,
Aug 8, 2007, 10:47:32 AM8/8/07
to
Dim dbs As Database, wsp As Workspace, ctr As Container, , doc As
Document
On Error GoTo ErrorCommand0_Click
Dim ThisForm As String
ThisForm = Me.Name

' Return reference to default workspace.
100 Set wsp = DBEngine.Workspaces(0)
' Return reference to current database.
120 Set dbs = CurrentDb
' Return reference to Modules container.
140 Set ctr = dbs.Containers!Forms

160 For Each doc In ctr.Documents
180 Debug.Print doc.Name; " "; doc.LastUpdated
200 Next doc


220 Set dbs = Nothing

OK, the above works. Had to loop through documents, as it turned out.
So, there's my small contribution for the day.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

lyle

unread,
Aug 8, 2007, 10:52:10 AM8/8/07
to

This works for me:

Dim pDocument As Document
For Each pDocument In DBEngine(0)(0).Containers("Forms").Documents
With pDocument
Debug.Print .Name, .DateCreated, .LastUpdated
End With
Next pDocument

A couple of things to consider here. The containers contains
documents, not the actual objects. The form documents "define", so to
speak, the forms (objects). In (early access like 97) there are no
forms until they are opened, using of course, the documents
definition. That's why the Forms.Count of your DB is zero unless there
are forms open. It's not that they're not counted unless they're open,
they don't exist until they're open.

Everybody except me loves CurrentDB. Try the above replacing
DBEngine(0)(0) with CurentDB. Problem! CurrentDB reinitializes itself
every time it's referenced. So it can't be used to loop. I know, we
can set a reference to it and use the reference. But why when
DBEngine(0)(0) works well and faster (probably not noticably). Oh you
think DBEngine(0)(0) might not be Current? C'Mon!!!!!!!!!! Oh you
think the leprechauns of Wizards might have DBEngine(0)(0) pointing to
another DB? Yeah, yeah, sure sure whatever. Who in his/her right mind
would actually USE a wizard (except those that sneak up on you) ? Blah
Blah Blah ... my motto ... "Don't let Micorsoft do anything for you
that you can do for yourself". Hey, Lyle, NO ONE agrees with you on
this matter so just SHUT UP.

David W. Fenton

unread,
Aug 8, 2007, 7:52:14 PM8/8/07
to
lyle <lyle.fa...@gmail.com> wrote in
news:1186584730.7...@b79g2000hse.googlegroups.com:

> Everybody except me loves CurrentDB. Try the above replacing
> DBEngine(0)(0) with CurentDB. Problem! CurrentDB reinitializes
> itself every time it's referenced. So it can't be used to loop. I
> know, we can set a reference to it and use the reference. But why
> when DBEngine(0)(0) works well and faster (probably not
> noticably). Oh you think DBEngine(0)(0) might not be Current?

I am always suspicious of any paths to objects that are more than
two levels deep, so your:

DBEngine(0)(0).Containers("Forms").Documents

looks very dangerous to me. That's the kind of thing that leaves
implicit references open all over the place. I never navigate any of
the document collections without assigning the container to a
variable. You will notice that this is a practice followed quite
rigorously in all the Microsoft documentation for Access.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/

lyle

unread,
Aug 8, 2007, 9:37:10 PM8/8/07
to
On Aug 8, 7:52 pm, "David W. Fenton" <XXXuse...@dfenton.com.invalid>
wrote:

I can't think of any reason at all that "DBEngine(0)
(0).Containers("Forms").Documents" should be dangerous. I've used that
particular syntax, and similar, a few billion times without any
problem. I suspect that one of the reasons is that I do not set an
explicit reference to the collection, and that there is no such thing
as an implicit reference, except in the imagination.
If something is followed quite rigorously in Microsoft Documentation
then, IMO, it's very likely to be ill-conceived, inefficient and just
plain crap. Where do they get these bozoes who write this crud,
anyway?
(Well, there goes my MVP nomination, eh?).
Ah well, I'm going into the wilderness for forty days now, David, so
don't bother to insult me about this. I won't read any response until
it's long dead, and I'll be busy with fasting and Satan tempting me,
anyway.

David W. Fenton

unread,
Aug 9, 2007, 10:54:40 AM8/9/07
to
lyle <lyle.fa...@gmail.com> wrote in
news:1186623430.4...@d55g2000hsg.googlegroups.com:

> I can't think of any reason at all that "DBEngine(0)
> (0).Containers("Forms").Documents" should be dangerous. I've used
> that particular syntax, and similar, a few billion times without
> any problem. I suspect that one of the reasons is that I do not
> set an explicit reference to the collection, and that there is no
> such thing as an implicit reference, except in the imagination.

Except for the fact that VBA uses reference counting and isn't 100%
accurate, I guess you're right.

All that rs.Close, Set rs = Nothing crap is just a waste of time, I
guess?

> If something is followed quite rigorously in Microsoft
> Documentation then, IMO, it's very likely to be ill-conceived,
> inefficient and just plain crap. Where do they get these bozoes
> who write this crud, anyway?

The fact is that a lot of the bugs that show up in Access would have
been avoided if one followed the practices established in the
documentation for Access. A long time ago I was annoyed at too many
variable declarations in those code examples, but now I understand
exactly why it's done.

CDMAP...@fortunejames.com

unread,
Aug 9, 2007, 5:41:30 PM8/9/07
to
On Aug 9, 10:54 am, "David W. Fenton" <XXXuse...@dfenton.com.invalid>
wrote:

Since Lyle is off in the wilderness being tempted to say something
nice about Microsoft :-):

Dim MyDB As DAO.Database
Dim MyForm As Document
Dim ctr As Container

Set MyDB = CurrentDb
For Each ctr In MyDB.Containers
If ctr.Name = "Forms" Then
For Each MyForm In ctr.Documents
MsgBox MyForm.Name
Next MyForm
End If
Next ctr
Set MyDB = Nothing

You can resume your argument when he gets back.

James A. Fortune
CDMAP...@FortuneJames.com

Larry Linson

unread,
Aug 10, 2007, 2:02:30 AM8/10/07
to
"lyle" <lyle.fa...@gmail.com> wrote

> Where do they get these bozoes who write
> this crud, anyway?

Surely, you do not expect anyone in this newsgroup to leap to their feet,
raise their hand, and shout, "Me, me, it was me!", do you?

Hope you enjoyed your camping trip... I'd been wondering why they were
preserving "Wilderness Areas" when "National Parks" were so nice, all things
considered... thanks for enlightening me that it is a place for developers
to go when they need forty days of fasting and temptation. Does anyone ever
_need_ that?

Larry


0 new messages