how to export Access 2010 data macros
Asked Answered
P

5

8

I need to transfer Access data macros from my test db to my production db. Anybody know how to do that?

I know that transferring tables from one accdb to another will also transfer the data macros, but that's not an option in my case. I also know I can recreate them manually in the production accdb, but that leaves me open to errors and requires taking the production database down for a longer time than would a scripted transfer scenario.

If I only had to do this once it wouldn't be such a big deal, but I'll need to do it many times over the course of a development project.

I've tried exporting the tables to xml, but the data macros are not included.

Please note that I'm asking about Access 2010 data macros here, not regular Access macros.

Picturesque answered 9/2, 2012 at 6:4 Comment(0)
B
3

I don't have a great answer here.

However, in the past I often made a "log book" of changes to tables and then simple used that on site.

Do note that you can cut + paste macro code. And the code saves as XML.

For example, this after update table trigger looks like this in Access:

enter image description here

If you cut out the above (ctrl-a, ctrl-cc),, then you can paste that into a note pad. In fact you can even paste/open it in visual studio or any xml editor, and you see this:

enter image description here

So you can cut + paste out of those macros.

As noted, thus in the past I often kept a "log" of changes.

So if I was working off site and I modified 2 code modules, 4 forms and 2 reports, then I had a little log of changes. I would type into this sheet what object was changed.

When I get on site, then I quick glance at that sheet and I know to import the 3-5 objects and such a import is only a few minutes tops.

However, with table triggers and store procedures, you could have more then just a few to copy.

I would either do one of two things:

Use the log idea and

a) Un-publish the development version and bring that with me to your working site. You then import new forms, reports etc. For trigger code, you cut + paste between the two applications.

b) When you make a change to a trigger, then cut + paste into a note pad doc and place them in a directory. When on site, simply take each notepad, cut + paste into production and then move or copy the notepad item into a "done" folder.

The above is certainly less than ideal. Then again in the past I not always had code to script out a table change, and using a little log sheet worked quite well.

So in the past I often just written down that such and such table was modified and I have to add such and such column.

So it really your choice as to if you want to cut + paste out the macro code as xml into separate little documents, or cut + paste right out of development into production.

I do think if you working in differnt location, then I think it likely best to un-publish the development version, and bring that with you (I assume you know/realaize that you can make a un-published copy of a web application).

So the forms, code modules, macro's etc can just be imported rather easy (you delete the forms etc, and just import from that un-published copy).

However, for the table code? You have to cut + paste from that un-published copy one at a time into some staging area, or as noted cut + paste between the applications.

There is the possibility that save-as text might work here, but I not yet had the time to cook up a better solution.

Edit: By the way, in above I assumed a web services database, but the advice still applies to non web Access databases.

Baboon answered 9/2, 2012 at 8:46 Comment(1)
Thanks for your time and for all the detail Albert. The XML info is really useful. Also Ctrl-C, Ctrl-V works really well too. Based on your reputation, I'm taking this as the gospel answer. Thanks againPicturesque
R
11

You may want to try a pair of undocumented VBA functions

To export:

SaveAsText acTableDataMacro, "TableName", "C:\PathToFile\DataMacro.xml"

To import:

LoadFromText acTableDataMacro, "TableName", "C:\PathToFile\DataMacro.xml"
Rodney answered 27/10, 2012 at 20:46 Comment(0)
F
6

To expand on Martijn Pieters' / Lanik's answer (thanks Martijn and Lanik), I had a need to create virtually the same data macros on 28 different tables, with an AfterInsert, AfterUpdate, AfterDelete, and named data macro on each. So, I used the SaveAsText command

SaveAsText acTableDataMacro, "TableName", "C:\PathToFile\DataMacro.xml"

to create a template, then used that template to create the 28 xml files via a little vba code, substituting the table names, primary keys, etc. I also created 28 LoadFromText commands. I could then use the LoadFromText commands to load all the macros at once, with a repeatable process. Now that I am done testing, I can quickly update the production database this way or add the same data macros to other tables easily.

So others know, LoadFromText overwrites any previous macros, which is terrific since I didn't have my template correct on the first try.

Given the above, the next step is to have your 'updater' database application use a DoCmd.TransferDatabase command to transfer the module with a function/sub with all the LoadFromText commands to the Data .accdb. It should also transfer a macro to run the function/sub. I tried having my updater then execute the macro to load the data macros, but Access security prevented that. so, you may need to get your user to open the database and Enable it, then run the macro. This is more convoluted then if we could edit the data macros directly, but does provide a workaround that solves the problem.

Forejudge answered 27/4, 2013 at 16:20 Comment(1)
Excellent answer. I'm running into a problem when using your SaveAsText acTableDataMacro code, and I've posted a question here.Adriaadriaens
B
3

I don't have a great answer here.

However, in the past I often made a "log book" of changes to tables and then simple used that on site.

Do note that you can cut + paste macro code. And the code saves as XML.

For example, this after update table trigger looks like this in Access:

enter image description here

If you cut out the above (ctrl-a, ctrl-cc),, then you can paste that into a note pad. In fact you can even paste/open it in visual studio or any xml editor, and you see this:

enter image description here

So you can cut + paste out of those macros.

As noted, thus in the past I often kept a "log" of changes.

So if I was working off site and I modified 2 code modules, 4 forms and 2 reports, then I had a little log of changes. I would type into this sheet what object was changed.

When I get on site, then I quick glance at that sheet and I know to import the 3-5 objects and such a import is only a few minutes tops.

However, with table triggers and store procedures, you could have more then just a few to copy.

I would either do one of two things:

Use the log idea and

a) Un-publish the development version and bring that with me to your working site. You then import new forms, reports etc. For trigger code, you cut + paste between the two applications.

b) When you make a change to a trigger, then cut + paste into a note pad doc and place them in a directory. When on site, simply take each notepad, cut + paste into production and then move or copy the notepad item into a "done" folder.

The above is certainly less than ideal. Then again in the past I not always had code to script out a table change, and using a little log sheet worked quite well.

So in the past I often just written down that such and such table was modified and I have to add such and such column.

So it really your choice as to if you want to cut + paste out the macro code as xml into separate little documents, or cut + paste right out of development into production.

I do think if you working in differnt location, then I think it likely best to un-publish the development version, and bring that with you (I assume you know/realaize that you can make a un-published copy of a web application).

So the forms, code modules, macro's etc can just be imported rather easy (you delete the forms etc, and just import from that un-published copy).

However, for the table code? You have to cut + paste from that un-published copy one at a time into some staging area, or as noted cut + paste between the applications.

There is the possibility that save-as text might work here, but I not yet had the time to cook up a better solution.

Edit: By the way, in above I assumed a web services database, but the advice still applies to non web Access databases.

Baboon answered 9/2, 2012 at 8:46 Comment(1)
Thanks for your time and for all the detail Albert. The XML info is really useful. Also Ctrl-C, Ctrl-V works really well too. Based on your reputation, I'm taking this as the gospel answer. Thanks againPicturesque
B
0

I had the same issue with not being able to find the correct macro in order to export in xml format. However I was able to right click on my query and export to xml that way so I knew it was possible.

However I wanted it to run from a button and I found a simple way of doing this without writing any vba code.

You first need to export your table or query manually by right clicking on your table or query and selecting export and choose xml as the file type. At the end you get to save the export steps, simply tick the box to save the steps and give the export steps an appropriate name. Once you have done this you can then run the export steps via a macro using the RunSavedImportExport action. Simply select the name of the saved export that you created when you exported manually. Job done. Hope this helps others.

Beam answered 7/7, 2015 at 14:17 Comment(1)
FYI: The data macros are not be included in the XML - I just tried it on Access 2013.Archibold
P
0

Right-click on the macro and choose Export and then pick the database that is to receive the macro.

Particulate answered 18/11, 2016 at 22:47 Comment(1)
I know that works with regular macros listed in the Navigation Pane, but does it also apply to Data Macros, e.g., Before Change, After Insert, ...? (I don't think it does.)Tips

© 2022 - 2024 — McMap. All rights reserved.