By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,294 Members | 2,681 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,294 IT Pros & Developers. It's quick & easy.

How to determine whether module is class module?

P: n/a
Hi all,

Wondering if there is a way to determine that a given module is a class
module or not.

In looping through the AllModules collection, it would be useful for me
to do different things to class vs. standard modules. I can't get at
properties via the AccessObject or the Container in DAO, so.

I guess I could instantiate and trap the error, but I don't know how to
instantiate a variable name.

Any thoughts? The archive was tough to search for this, but I don't
think it's out there.

Jan 17 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Check the module's 'Type' property. Standard modules are type 0, while
class modules, like those underlying a form or a class module you've
created is type 1.

Use something like:

If Modules("ModuleName").Type = 0 Then
.....
End If

Jan 18 '06 #2

P: n/a
On 17 Jan 2006 15:36:06 -0800, "downwitch" <do*******@gmail.com> wrote:
Hi all,

Wondering if there is a way to determine that a given module is a class
module or not.

In looping through the AllModules collection, it would be useful for me
to do different things to class vs. standard modules. I can't get at
properties via the AccessObject or the Container in DAO, so.

I guess I could instantiate and trap the error, but I don't know how to
instantiate a variable name.

Any thoughts? The archive was tough to search for this, but I don't
think it's out there.


Sub WhatAreMyModules()
Dim cont As Container
Dim doc As Document

Set cont = DBEngine(0)(0).Containers("Modules")

For Each doc In cont.Documents
DoCmd.OpenModule doc.Name
If Modules(doc.Name).Type = acStandardModule Then
Debug.Print doc.Name, "Standard Module"
Else
Debug.Print doc.Name, "Class Module"
End If
DoCmd.Close acModule, doc.Name
Next doc

Set doc = Nothing
Set cont = Nothing

End Sub

Wayne Gillespie
Gosford NSW Australia
Jan 18 '06 #3

P: n/a
Thanks to both, just what I needed.

Jan 18 '06 #4

P: n/a
Not extensively tested and not documented at all TTBOMK, but seems to
work and does not require the Module to be opened (>= Ac2K ):

Public Function IsClassModule(ByVal ModuleName As String) As Boolean
IsClassModule = CurrentProject.AllModules(ModuleName).Attributes
And 256
End Function

Sub test()
Debug.Print IsClassModule("Class1")
End Sub

(A standard Module seems to have no Attribues; Attributes = 0).

Jan 18 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.