How to Export Access 2010 Data Macros

I need to transfer data access macros from my test db to my production db. Does anyone know how to do this?

I know that moving tables from one accdb to another also transfers data macros, but this is not an option in my case. I also know that I can recreate them manually in accdb production, but this leaves me open to errors and requires the production database to run for a longer time than the transfer script script.

If I only had to do this, it would not be so important, but I will need to do this many times during the development project.

I tried to export tables in xml, but data macros are not included.

Please note that I am asking about Access 2010 data macros here, and not in regular Access macros.

+7
source share
5 answers

I have no great answer.

However, in the past I often did a โ€œlogbookโ€ of changes to the tables, and then just used it on the site.

Notice that you can cut + paste a macro. And the code is saved as XML.

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

enter image description here

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

enter image description here

So you can cut + paste from these macros.

As already noted, in the past I often kept a โ€œjournalโ€ of changes.

So, if I worked from the site, and I modified 2 modules of code, 4 forms and 2 reports, then I had a small change log. I would print on this sheet which object was modified.

When I am on the site, I quickly look through this sheet, and I know to import 3-5 objects, and such import takes only a few minutes.

However, with table triggers and storage procedures, you can have more than a few copies.

I would either do one of two things:

Use the idea of โ€‹โ€‹a magazine and

a) Unpublish the development version and bring it to me on your working site. Then you import new forms, reports, etc. For startup code, you cut + paste between two applications.

b) When you make changes to the trigger, then cut + paste into the notebook document and place them in the directory. When in place, just take each notebook, cut + paste into production, and then move or copy the notebook to the "done" folder.

The above, of course, is less than ideal. Then in the past, I did not always have script code outside the table, and using a small log list worked quite well.

So in the past, I often just wrote that the same table was changed, and I need to add such and such a column.

So, this is really your choice if you want to cut + paste macro code as xml into separate small documents or cut + paste directly from development to production.

I really think that if you work elsewhere, then I think that it is probably better to refuse to publish the development version and bring it to you (I suppose you know / know that you can make a non-public copy of the web application )

Thus, forms, code modules, macros, etc. you can just import quite easily (you delete forms, etc. and just import from this unsealed copy).

However, for table code? You need to cut + paste from this unsealed copy one at a time into some intermediate area or, as indicated, cut + paste between applications.

There is a possibility of saving, because the text can work here, but I have not yet had time to prepare the best solution.

Edit: By the way, in the above example, I assumed a web services database, but the tip still applies to non-web access databases.

+3
source

You might want to try a couple of undocumented VBA functions.

Export:

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

For import:

 LoadFromText acTableDataMacro, "TableName", "C:\PathToFile\DataMacro.xml" 
+7
source

To extend Martijn Pieters' / Lanik's answer (thanks to Martijn and Lanik), I had to create almost the same data macros on 28 different tables, each of which had AfterInsert, AfterUpdate, AfterDelete and the data macro named. So, I used the SaveAsText command

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

to create a template, then used this template to create 28 xml files through a small vba code, replacing table names, primary keys, etc. I also created 28 LoadFromText commands. Then I could use the LoadFromText commands to load all the macros at the same time as the repeating process. Now that Iโ€™ve finished testing, I can quickly update the production database or easily add the same data macros to other tables.

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

Based on the above, the next step is for your updater database application to use the DoCmd.TransferDatabase command to transfer the module using the / sub function with all LoadFromText commands in Data.accdb. It must also pass a macro to run the / sub function. I tried my updater to execute a macro to load data macros, but access security prevented this. therefore, you may need your user to open the database and enable it, then run the macro. This is more confusing if we could directly edit data macros, but it provides a workaround that solves the problem.

+5
source

I had the same problem because I could not find the correct macro to export in xml format. However, I was able to right-click on my query and export to xml so that I knew it was possible.

However, I wanted it to start from a button, and I found an easy way to do this without writing vba code.

First you need to export the table or query manually by right-clicking on the table or query and choosing export and select xml as the file type. At the end, you can save the export steps, just check the box to save the steps, and give the export steps an appropriate name. After that, you can follow the export steps through the macro using the RunSavedImportExport action. Just select the name of the saved export that you created when exporting manually. Work is done. Hope this helps others.

0
source

Right-click the macro and select Export , and then select the database that you want to receive the macro.

0
source

All Articles