Results 1 to 11 of 11
  1. #1
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Importing Modules (Access 2002)

    I need to delete all modules from a database in Access 2000 then import all modules from an Access 2002 database.

    I need to find out how to loop thru a modules collection (or an alternative) and use the DoCmd.TransferDatabase function to import the modules.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Importing Modules (Access 2002)

    Hi Pat,

    Deleting all modules from the current database in code would be problematic, since you would delete the module containing the code you are running. Do you really need to do this in code?

    To loop through the modules in the current database, you can loop through the items of CurrentProject.AllModules, or of the DAO Modules container of a database object:

    Sub ListModules1()
    Dim i As Integer
    Dim n As Integer
    n = CurrentProject.AllModules.Count
    For i = n - 1 To 0 Step -1
    Debug.Print CurrentProject.AllModules(i).Name
    Next i
    End Sub

    Sub ListModules2()
    Dim i As Integer
    Dim n As Integer
    Dim dbs As DAO.Database
    Dim ctr As DAO.Container
    Set dbs = CurrentDb
    Set ctr = dbs.Containers!Modules
    n = ctr.Documents.Count
    For i = n - 1 To 0 Step -1
    Debug.Print ctr.Documents(i).Name
    Next i
    Set ctr = Nothing
    Set dbs = Nothing
    End Sub

  3. #3
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Importing Modules (Access 2002)

    I would second Hans comment about doing all this in code. If you have 500 databases to do this to, it's obviously an idea to tinker with, but it's seldom that you want to do many databases at once in my experience, and when you do one at a time, the import function works very well.
    Wendell

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Importing Modules (Access 2002)

    I hope you mean you're importing from a 2000-formatted 2002 database. Otherwise, it isn't going to happen. Is this another way of trying to get around the references issue you had? If it is, why not export from the 2002 database instead of trying to import into the 2000 database? That would allow you to find and delete the module in the 2000 database before exporting from the current database. There definitely are ways to do this, but you need to explain your purpose.
    Charlotte

  5. #5
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Importing Modules (Access 2002)

    Yes I am importing from a 2000-formatted 2002 database. Yes again, it is a way of getting around the references problem.
    I had not thought about exporting from the 2002 to the 2000 database.

    What are the ways of doing this.

    Thanks for your input guys.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Importing Modules (Access 2002)

    DoCmd.TransferDatabase again, but with acExport instead of acImport. You can use one of the methods from my previous reply to loop through the modules.

  7. #7
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Importing Modules (Access 2002)

    Thanks Hans, although I knew this already.

    I thought Charlotte had other ways of doing this.

  8. #8
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Importing Modules (Access 2002)

    I have done it in tools I've built, but that involved finding and replacing code in modules, which was fairly complex in that situation. You could also use automation to open the other database and use <code>appObject.DoCmd.DeleteObject objName</code> to remove each specified document in the other Access app. Then <code>DoCmd.CopyObject strDestFile, objName, acModule, objName</code> will copy an object (in this case a module) from the current database to another.
    Charlotte

  9. #9
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Importing Modules (Access 2002)

    Thank you Charlotte.
    It's always good to know the alternative ways to do things.
    When you say delete a Document do you mean Module?
    Can this way of deleting be used to delete Queries, Forms, Reports as well as Modules?

    Is appObject defined as an Object?

    So I guess you could use CopyObject to copy Queries, Forms, Reports as well as Modules.

  10. #10
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Importing Modules (Access 2002)

    That's air code, Pat. I assumed you were talking about replacing modules, so that's what I focused on. Each container (Modules, Tables, Queries, Reports, Forms, Macros) has a documents collection which contains the objects themselves. We're talking DAO here, of course. It would be quite different with ADO.

    appObj would be an instance of an Access application opened using automation (i.e. CreateObject("Access.Application"), since DoCmd is a method of the Application object and you don't way to delete the object in your *current* db. Yes, you could use CopyObject to copy those object. However, if an object with that name already exists, you'll get a message asking if you want to overwrite, which is why I suggested deleting the remote object before copying it over.
    Charlotte

  11. #11
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Importing Modules (Access 2002)

    Thanks again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •