如何导出 Access 2010 数据宏
我需要将 Access 数据宏从测试数据库传输到生产数据库。有人知道该怎么做吗?
我知道将表从一个 accdb 传输到另一个 accdb 也会传输数据宏,但在我的情况下这不是一个选项。我还知道我可以在生产 accdb 中手动重新创建它们,但这会让我容易出错,并且需要比脚本化传输场景更长时间地关闭生产数据库。
如果我只需要这样做一次,那就没什么大不了的,但在开发项目的过程中,我需要多次这样做。
我尝试将表导出到 xml,但不包含数据宏。
请注意,我在这里询问的是 Access 2010 数据宏,而不是常规 Access 宏。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可能想尝试一对未记录的 VBA 函数
导出:
导入:
You may want to try a pair of undocumented VBA functions
To export:
To import:
为了扩展 Martijn Pieters/Lanik 的答案(感谢 Martijn 和 Lanik),我需要在 28 个不同的表上创建几乎相同的数据宏,并在每个表上创建 AfterInsert、AfterUpdate、AfterDelete 和命名数据宏。所以,我使用了 SaveAsText 命令
创建一个模板,然后使用该模板通过一些 vba 代码创建 28 个 xml 文件,替换表名称、主键等。我还创建了 28 个 LoadFromText 命令。然后,我可以使用 LoadFromText 命令通过可重复的过程一次性加载所有宏。现在我已经完成了测试,我可以通过这种方式快速更新生产数据库,或者轻松地将相同的数据宏添加到其他表中。
所以其他人知道,LoadFromText 会覆盖以前的任何宏,这非常棒,因为我第一次尝试时模板不正确。
鉴于上述情况,下一步是让您的“更新程序”数据库应用程序使用 DoCmd.TransferDatabase 命令将具有函数/子的模块以及所有 LoadFromText 命令传输到 Data .accdb。它还应该传输一个宏来运行函数/子函数。我尝试让更新程序执行宏来加载数据宏,但访问安全性阻止了这一点。因此,您可能需要让用户打开数据库并启用它,然后运行宏。如果我们可以直接编辑数据宏,这会更加复杂,但确实提供了解决问题的解决方法。
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
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.
我在这里没有很好的答案。
然而,过去我经常对表格的更改制作一个“日志”,然后在现场简单地使用它。
请注意,您可以剪切+粘贴宏代码。并且代码保存为 XML。
例如,此更新后表触发器在 Access 中如下所示:
如果您删除上面的内容 (ctrl -a, ctrl-cc),,然后您可以将其粘贴到记事本中。事实上,您甚至可以在 Visual Studio 或任何 xml 编辑器中粘贴/打开它,您会看到以下内容:
因此您可以从这些宏中剪切+粘贴。
如前所述,因此过去我经常保留更改的“日志”。
因此,如果我在场外工作并修改了 2 个代码模块、4 个表单和 2 个报告,那么我就会有一些更改日志。我将在这张表中输入更改的对象。
当我到达现场时,我快速浏览了该工作表,我知道要导入 3-5 个对象,而这样的导入最多只需几分钟。
但是,使用表触发器和存储过程,您可以复制更多内容。
我会做以下两件事之一:
使用日志想法和
a) 取消发布开发版本并将其带到您的工作站点。然后您导入新的表格、报告等。
对于触发代码,您可以在两个应用程序之间剪切+粘贴。
b) 当您对触发器进行更改时,然后剪切+粘贴到记事本文档中并将它们放在目录中。在现场时,只需取出每个记事本,剪切+粘贴到生产中,然后将记事本项目移动或复制到“完成”文件夹中。
上述情况肯定不太理想。然后,在过去,我并不总是有代码来编写表更改的脚本,并且使用一个小日志表效果很好。
所以以前我经常只是写下某某表被修改了,我必须添加某某列。
因此,您可以选择是否要将宏代码作为 xml 剪切+粘贴到单独的小文档中,或者直接从开发中剪切+粘贴到生产中。
我确实认为,如果您在不同的位置工作,那么我认为最好取消发布开发版本,并将其随身携带(我假设您知道/意识到您可以制作 Web 应用程序的未发布副本) 。
因此,表单、代码模块、宏等可以相当容易地导入(您删除表单等,然后从未发布的副本导入)。
但是,对于表代码呢?您必须一次将未发布的副本剪切+粘贴到某个暂存区域,或者如上所述在应用程序之间剪切+粘贴。
另存为文本可能在这里起作用,但我还没有时间制定更好的解决方案。
编辑:
顺便说一句,在上面我假设了一个 Web 服务数据库,但该建议仍然适用于非 Web Access 数据库。
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:
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:
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.
我遇到了同样的问题,无法找到正确的宏以便以 xml 格式导出。然而,我能够右键单击我的查询并以这种方式导出到 xml,所以我知道这是可能的。
然而,我希望它通过按钮运行,并且我找到了一种简单的方法来执行此操作,而无需编写任何 vba 代码。
您首先需要手动导出表或查询,方法是右键单击表或查询并选择导出并选择 xml 作为文件类型。最后,您可以保存导出步骤,只需勾选该框即可保存步骤并为导出步骤指定适当的名称。完成此操作后,您可以使用 RunSavedImportExport 操作通过宏运行导出步骤。只需选择您手动导出时创建的已保存导出的名称即可。工作完成了。希望这对其他人有帮助。
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.
右键单击宏并选择
导出
,然后选择要接收宏的数据库。Right-click on the macro and choose
Export
and then pick the database that is to receive the macro.