Modules(index) and Modules("name") return different modules?

D

Derek Boutang

I'm converting some dev utilities from 97 to 2003 and
struggling with the new coding environment. Is the
following behaviour a bug, or am I not coding this
correctly?

According to the help, the following code is supposed to
load the names of open modules into an array:

intCount = Modules.Count - 1
For intCounter = 0 To intCount
aObjects(intCounter) = Modules(intCounter).Name
Debug.Print aObjects(intCounter)
Next intCounter

Instead, it loads every module in my database PLUS every
module in every library database reference.

But, when I attempt to reference a module in one of the
libraries using the following syntax, Access produces
Error 9: Subscript out of range:

?Modules("name").Name

To me, this looks like Modules(index) and Modules("name")
return different lists. Further, it looks like
Modules.Count is now a meaningless construct because it
doesn't really tell you how many modules are open, just
how many are available to be referenced within the
database.

Thoughts? Comments?
 
G

George Nicholson

You might try using the CurrentProject.AllModules collection if you only
want to know about the Access db. Members of this collection also have an
"IsLoaded" property, so you can easily calculate the Open count via a loop.

This option isn't available in Access 97. I know that CurrentProject, et al
was new for 2000 or 2002/XP but i'm fuzzy on which. (Pretty sure it's 2000,
I associate it with the addition of ADP support and why there was such a
major file-type change after 97).
 
D

Derek Boutang

You might try using the CurrentProject.AllModules

Thanks George. Been down that road already. Despite what
the help says, CurrentProject.AllModules fetches only
standard modules, not form and report class modules too.
Plus, you have to inspect each one to identify whether
it's open or not.

Also, this doesn't explain why Modules(index) and Modules
("name") seem to have different behaviour, again, despite
what the help says.
 
D

david epsom dot com dot au

I seem to remember that in A97, I could edit loaded
library modules, but in A2K I can't ??? Is that correct ???
(because library modules are loaded in shared mode ????)

(david)
 
B

Brendan Reynolds

That's correct. You can edit the code in a referenced MDB, but your edits
are discarded *without warning* when you close. I just checked, and I'm
afraid this behaviour hasn't changed in Access 2003. (I hadn't expected to
be able to save the changes, but I had rather hoped for a warning that they
would not be saved).

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 

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