HowTo: Change a new modules name in MS Access with VBA Code
I am trying to build a wizard for automating the creation of new Access programs. My client has a very specific style that they require. So I wanted to create this wizard to build a starter app with all of the standard forms and tables, ect.. I found how to create a new module using RunCommand, but it does not return what module name it used and once I figure out which one it is I need to be able to rename it. When I tried to set the Name property I got a read only property error.
Any help is much appreciated! :D
[524 byte] By [
Ron Weller] at [2007-11-11 10:21:48]

# 1 Re: HowTo: Change a new modules name in MS Access with VBA Code
Well what do you know, I finally figured it out. I used the Modules() collection to get the name of the last opened module, which is the new one. Now you must save it, which also closes it. So if you create any references to the open module then the save will fail. After the save is complete you can now use the DoCmd.Rename routine to rename the module. If you don't do things in the correct order then you will get an error. Here is the code I used to test this out: Public Sub NewModule(Optional mdlName As String = "modTestIt")
Dim newMod As String
'Create new module.
DoCmd.RunCommand acCmdNewObjectModule
'Get name from the last opened module, which is the new one
newMod = Modules(Modules.Count - 1).Name
'Save the module which closes it and allows renaming
DoCmd.Save acModule, newMod
'Now finally rename it so code can then be added
DoCmd.Rename mdlName, acModule, newMod
End Sub