简体   繁体   English

如何导出Access 2010数据宏

[英]how to export Access 2010 data macros

I need to transfer Access data macros from my test db to my production db. 我需要将Access数据宏从我的测试数据库传输到我的生产数据库。 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. 我知道将表从一个accdb转移到另一个accdb也会传输数据宏,但在我的情况下这不是一个选项。 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. 我也知道我可以在生产accdb中手动重新创建它们,但这使我容易出错,并且需要将生产数据库关闭的时间比脚本传输方案要长。

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. 我已经尝试将表导出到xml,但不包括数据宏。

Please note that I'm asking about Access 2010 data macros here, not regular Access macros. 请注意,我在这里询问Access 2010 数据宏 ,而不是常规的Access宏。

You may want to try a pair of undocumented VBA functions 您可能想尝试一对未记录的VBA函数

To export: 出口:

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

To import: 要导入:

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

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. 为了扩展Martijn Pieters的/ Lanik的答案(感谢Martijn和Lanik),我需要在28个不同的表上创建几乎相同的数据宏,每个表都有AfterInsert,AfterUpdate,AfterDelete和命名数据宏。 So, I used the SaveAsText command 所以,我使用了SaveAsText命令

SaveAsText acTableDataMacro, "TableName", "C:\\PathToFile\\DataMacro.xml" 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. 创建一个模板,然后使用该模板通过一个小的vba代码创建28 xml文件,替换表名,主键等。我还创建了28个LoadFromText命令。 I could then use the LoadFromText commands to load all the macros at once, with a repeatable process. 然后,我可以使用LoadFromText命令一次加载所有宏,并使用可重复的过程。 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. 所以其他人都知道,LoadFromText会覆盖任何以前的宏,这非常棒,因为我第一次尝试时没有正确的模板。

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. 鉴于上述情况,下一步是让“updater”数据库应用程序使用DoCmd.TransferDatabase命令将带有函数/ sub的模块与所有LoadFromText命令一起传输到Data .accdb。 It should also transfer a macro to run the function/sub. 它还应该传输一个宏来运行函数/ 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. 如果我们可以直接编辑数据宏,那么这会更复杂,但确实提供了解决问题的解决方法。

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. 代码保存为XML。

For example, this after update table trigger looks like this in Access: 例如,此更新后的表触发器在Access中如下所示:

在此输入图像描述

If you cut out the above (ctrl-a, ctrl-cc),, then you can paste that into a note pad. 如果你剪掉上面的(ctrl-a,ctrl-cc),,那么你可以将它粘贴到记事本中。 In fact you can even paste/open it in visual studio or any xml editor, and you see this: 事实上你甚至可以在visual studio或任何xml编辑器中粘贴/打开它,你会看到:

在此输入图像描述

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. 因此,如果我在网站外工作,我修改了2个代码模块,4个表单和2个报告,那么我有一些变化记录。 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. 当我到达现场时,我快速浏览一下该表,我知道要导入3-5个对象,这样的导入仅需几分钟。

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. a)取消发布开发版本并将其带到您的工作现场。 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. b)当您对触发器进行更改时,然后剪切+粘贴到记事本文档中并将它们放在目录中。 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. 所以你真的可以选择是否要将宏代码作为xml剪切+粘贴到单独的小文档中,或者从开发中剪切+粘贴到生产中。

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). 我认为如果您在不同的位置工作,那么我认为最好取消发布开发版本,并随身携带(我假设您知道/重新确定您可以制作未发布的Web应用程序副本) 。

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. 编辑:顺便说一句,在上面我假设了一个Web服务数据库,但该建议仍然适用于非Web Access数据库。

I had the same issue with not being able to find the correct macro in order to export in xml format. 我有同样的问题,无法找到正确的宏,以便以xml格式导出。 However I was able to right click on my query and export to xml that way so I knew it was possible. 但是我能够右键单击我的查询并以这种方式导出到xml,所以我知道它是可能的。

However I wanted it to run from a button and I found a simple way of doing this without writing any vba code. 但是我希望它从按钮运行,我发现了一种简单的方法,无需编写任何vba代码。

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. 首先需要手动导出表或查询,方法是右键单击表或查询并选择export并选择xml作为文件类型。 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. 完成此操作后,您可以使用RunSavedImportExport操作通过宏运行导出步骤。 Simply select the name of the saved export that you created when you exported manually. 只需选择手动导出时创建的已保存导出的名称。 Job done. 任务完成。 Hope this helps others. 希望这有助于其他人。

右键单击宏并选择“ Export ,然后选择要接收宏的数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM