John Colby
jwcolby at ColbyConsulting.com
Fri Jan 13 08:32:25 CST 2006
Shamil,
Well, that didn't work. I am trying to build this as an Add-In and
apparently the .RunCommand acCmdNewObjectClassModule isn't available in the
context of code running out in an add-in. I had been using the following
code to get a module:
Dim lMdl As VBComponent
Dim VBProj As VBProject
Set VBProj = Application.VBE.ActiveVBProject
Set lMdl =
Application.VBE.ActiveVBProject.VBComponents.Add(vbext_ct_ClassModule)
lMdl.Name = strModuleName
Set AddModule = lMdl.CodeModule
The "lMdl.Name = strModuleName" does correctly set the name of the class
module. The problem is that the created class is in limbo somewhere. It
exists, i.e. if I try it again, the "lMdl.Name = strModuleName" causes a run
time error. I cannot save it however. Even opening a module in the current
app and clicking save doesn't save it.
John W. Colby
www.ColbyConsulting.com
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Shamil
Salakhetdinov
Sent: Friday, January 13, 2006 3:53 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Class builder
John,
Here is one of the methods how a new class module can be created and saved
using VBA:
Dim mdl As Access.Module
Dim objApp As Access.Application
Dim strTempMdlName As String
Dim strMdlName As String
Set objApp = Access.Application
strMdlName = "CTestClassModule"
With objApp.DoCmd
.RunCommand acCmdNewObjectClassModule
Set mdl = objApp.Modules.Item(objApp.Modules.Count - 1)
strTempMdlName = mdl.Name
mdl.InsertText "public TestProperty as integer"
.Close acModule, strTempMdlName, acSaveYes
.Rename strMdlName, acModule, strTempMdlName
End With
Make sure there is no class module with the name CTestClassModule in your
database...
Shamil
----- Original Message -----
From: "John Colby" <jwcolby at ColbyConsulting.com>
To: "'Access Developers discussion and problem solving'"
<accessd at databaseadvisors.com>
Sent: Friday, January 13, 2006 4:08 AM
Subject: [AccessD] Class builder
> I have just finished a little class builder. If anyone wants to play with
> it let me know.
>
> In the meantime, the one thing I can't figure out is how to save the newly
> created class. I can click the save button and it saves the new module,
but
> I can't make it happen from VBA. Anyone know what object saves unsaved
> modules?
>
> John W. Colby
> www.ColbyConsulting.com
>
>
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com