DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: HowTo: Change a new modules name in MS Access with VBA Code

  1. #1
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,263

    Question 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!

  2. #2
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,263
    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:
    Code:
    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

Similar Threads

  1. Microsoft's C++ bigotry
    By Phil Weber in forum .NET
    Replies: 632
    Last Post: 10-01-2003, 12:00 AM
  2. Code Access Security
    By awhaley in forum .NET
    Replies: 1
    Last Post: 09-26-2002, 08:48 PM
  3. Replies: 60
    Last Post: 09-13-2002, 05:41 PM
  4. Adding Access Modules from VB
    By Craig in forum VB Classic
    Replies: 1
    Last Post: 06-25-2002, 10:45 PM
  5. Replies: 90
    Last Post: 04-17-2001, 12:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center