本文介绍了Access2010中的数据宏:触发器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在小道消息中听说即将推出的Access2010具有数据宏功能,这将首次为Access数据引擎表添加类似触发器的功能.有人对此有进一步的细节吗?例如,它们可以用代码(ACEDAO,SQL DDL等)创建吗?如果从Access用户界面外部修改了数据,则Data Macro是否运行?通过ODBC,OLE DB等?

I've heard on the grapevine that the forthcoming Access2010 has a Data Macros feature which will for the first time add trigger-like functionality to Access data engine tables. Does anybody have an further details on this? For example, can they created in code (ACEDAO, SQL DDL, etc)? Does the Data Macro run if the data is modified from outside of the Access user interface e.g. via ODBC, OLE DB, etc?

推荐答案

确定,更多信息.

是的.

这些真正的触发器是在数据引擎级别上的.因此,使用ado,dao甚至在ms-access的表视图中编辑表都将触发触发器.这些触发器还包括您甚至没有在计算机上安装ms-access的情况.

These true triggers are at the data engine level. So, using ado, dao or even editing the tables in table view in ms-access means the triggers will fire. These triggers would also include the scenario where you don’t even have ms-access installed on your computer.

您当然需要安装JET(对于本文的其余部分,我将使用ACE).请记住,只有在Access 2007中,访问团队才获得JET的所有权.他们现在可以自由地增强此引擎以满足他们的需求.我们从2007年开始对ACE进行了一些更改,现在我们将在2010年看到很多更改.其中一些功能对我来说仍然是NDA ...但我会在这里尽可能多地进行宣传.

You will of course need JET installed (for the remainder of this article I will use the term ACE). Remember it was only in access 2007 that the access team received ownership of JET. They are now free to enhance this engine for their needs. We started to see some changes to ACE in 2007 and now we will see a LOT more changes for 2010. Some of these features are still NDA for me…but I will spill as much as I can here.

在代码中使用perahps,但不使用SQL ddl.触发器不是sql命令.请记住,对于市场上的Oracle,SQL Server或MOST系统,无论如何它们都倾向于使用其OWN自定义语言作为触发器.

In code, perahps, but not with SQL ddl. The triggers are not sql commands. Keep in mind that for Oracle, or Sql server or MOST systems in the marketplace they all tend to have their OWN custom language for their triggers anyway.

因此,在新的ACE中,您将编写所谓的数据宏.您在ms-access中使用宏编辑器.这些是老式的访问宏,但是编辑器已经完全重做.新的宏还具有子例程,循环(如果有的话),块和一种记录集.请记住,我们获得了在2007宏中创建临时变量的功能.在2010年,此功能扩展为还包括局部变量和新功能.

In the new ACE you thus will write what is called a data macro. You use the macro editor in ms-access. These are old fashioned access macros, but the editor has been completely re-done. The new macros also have subroutines, looping, if then else blocks and a type of recordset. Remember, we received the ability to create temp variables in 2007 macros. In 2010 this is extended to also include local variables and above new features.

现有宏命令的语法与以前的版本相同.但是,我们拥有一个新的精巧IDE以及上面添加的所有出色命令.因此,我们现在有两种类型的宏. UI宏(以前是常规的),现在是所谓的新数据宏.表级宏不能在屏幕上显示错误消息,这是没有意义的.因此,记录的所有错误都将放入表中.还有一些新的日志记录命令,可让您将自己的自定义错误写入该表.一个出色而简单的设计在这里.错误日志表如下所示:

The syntax for existing macro commands is the same as previous versions. However, we have a new slick IDE along with all those above cool commands added. We now thus have two types of macros. UI macros (regular as before) and now the new so called data macros. It would not make sense for a table level macro to be able to display error messages to the screen. So any error logged goes into a table. There also a few new logging commands that let you write your own custom errors to that table . A brilliant and simple design here. Here what that error log table looks like:



在一个拥有大量IDE的世界中,庞大的框架工作和可怕的巨大代码库需要返回来更新表中的简单行,我可以说数据宏是最令人耳目一新的功能.他们觉得很像原始dbaseII的工作方式.它们非常简单,但却充满了致命的力量,因为它们在表级别运行.

In a world of huge IDE’s, massive frame works and horrifying huge libraries of code requited to update a simple row in a table, I can say that data macros are most refreshing feature. They feel much like how the original dbaseII works. They are very simple, but deadly power full because they run at the table level.

例如,这是一个数据宏,它将维护一个表的库存总计.在此示例中,我将假定存在主库存记录.然后,我们有一个订单明细表.如果用户编辑了订单表中的任何值,我们希望主表自动更新库存水平.

For example, here is a data macro that will maintain inventorying totals a table. In this example I’m going to assume that master inventory records exist. And then we have an order details table. If a user edits any value in the orders table, we want the master table to automatic update the inventory levels.

因此,我们有:我有两个桌子

So we have:I have two tables

tblFruits:    main data fruit inventory table
id         (autonumber)
Fruit text
OnHand    (number value of fruit in inventory)

tblFruitsOrder
id       (autonumber)
Fruit_id (FK to tblFruts.ID)
QtyOrder (number of fruit to order)

这是简单的测试

因此,我们将在tblFruitsOrder中有一个触发器,该触发器将更新+当QtyOrder字段为时,在tblFruits中保持库存水平编辑或修改.

So, we going to have a trigger in the tblFruitsOrder that will update+ maintain inventory levels in tblFruits when the QtyOrder field isedited or modified.

这是宏的样子:



请注意上面的内容非常简单.请注意,如果在IDE中单击代码的一部分,则会获得旧样式的宏类型编辑,您可以在其中输入命令的值(这与2010年之前的版本类似,但是现在参数和编辑发生在代码,而不是以前版本的屏幕底部显示的面板.

Note how very simple the above is. Note that in the IDE if you click on a section of the code, then you get the old style macro type editing in which you can enter the values for the command (this is similar to pre 2010, but now the parameters and editing occurs in the code, not a panel that appears on the bottom of the screen in previous versions).

这是另一个屏幕快照,在其中我可以执行循环并调用子例程.

Here is another screen shot in which I playing with the ability to do a loop and call a subroutine.



在上面我们可以使用msgboxs等,因为这不是表级宏.因此,当您编写表级宏而不是常规宏时,将自动为您限制可用的命令.我们用来区分两种类型的宏的术语是UI宏和数据宏.

In the above we can use msgboxs etc. because this is not a table level macro. So the commands available are automatically restricted for you when you writing a table level macro as opposed to a regular macro. The terminology we adopted to distinguish the two types of macros are UI macros and data macros.

以上是我在公共场合可以谈论的所有内容.但是,关于这些宏的其他功能还很少,我根本无法在公共场合谈论,因为我仍在NDA上关注这些功能.但是,这里还有更多很酷的惊喜.

The above is about all I can speak about in pubic. However there is few more REALLY neat-o features about these macros that I simply can not yet talk about in public as I am still under NDA on those features. But there is more cool surprises to come here.

以下是我们拥有的表触发器类型的屏幕截图:

Here is a screen shot of the types of table triggers we have:



这篇关于Access2010中的数据宏:触发器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 07:13