Link to home
Start Free TrialLog in
Avatar of rye004
rye004Flag for United States of America

asked on

Adding queries and macros to many Microsoft Access Databases.

I have 50 Microsoft Access databases.  Each of these databases are in the same structure.

I have 20 queries and 5 macros that I want to add to each of these.  I wanted to know if there is an automated way to add these 20 queries and 5 macros to each of the 50 access databases.

I was going to look into using COM Automation and .NET, but thought I would check her first to see if there was another way to do this.

Thanks in advance!
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

test this codes,
- create a db (db1) and place these codes in  a module
   the code should copy the Query and Macro from db3 (source db of query and macro)
   db2 will be destination db (you need to create a list of the 50 db, path and db names. you can place the names of the dbs in a table in db1)

Sub CopyObjects()
    Dim acc As Object

    Set acc = CreateObject("Access.Application")
    acc.OpenCurrentDatabase CurrentProject.Path & "\db2.mdb"

'    acc.DoCmd.TransferDatabase acImport, "Microsoft Access", CurrentProject.Path & "\db3.mdb", acQuery, "Query1", "Query1"

    acc.DoCmd.TransferDatabase acImport, "Microsoft Access", CurrentProject.Path & "\db3.mdb", acMacro, "Macro1", "Macro1"
    acc.CloseCurrentDatabase
    Set acc = Nothing

End Sub
If you have split (FE/BE) databases, just push out a new FrontEnd database, replacing the target databases.
Sounds like you have 50 spreadsheets rather than 50 databases.  Why is the data not all in the same database?  Even if you kept 50 separate BE's, you could still use a single FE and simply relink to the BE you need.

Create a loop that populates strFileName and either hard-code the list of objects or create another loop that picks them out and formats the export statement based on object type.

DoCmd.TransferDatabase acExport, "Microsoft Access", strFilename, acMacro, "mOpenAuditOverviewReport", "AutoExec", False
DoCmd.TransferDatabase acExport, "Microsoft Access", strFilename, acQuery, "qOtherComments", "qOtherComments", False
DoCmd.TransferDatabase acExport, "Microsoft Access", strFilename, acReport, "srptOtherComments", "srptOtherComments", False

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Hamed Nasr
Hamed Nasr
Flag of Oman image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try this:
source database dbs.accdb contains Queries and macros to be copied to destination databases.
Destination databases: d1.accdb, d2.accdb, ...
run copyObjects.accdb database and run form1, and click button.
copyObjects.zip
Avatar of rye004

ASKER

This is impressive, thank you.  The VBA Macro in it is awesome.
Welcome!