Microsoft Access VBA Macro Programming

(Tina Sui) #1

Chapter 13 Table Macros


Chapter 13 Table Macros


A


new feature of Access 2010 is the ability to create table macros. These perform
a similar function to triggers in databases such as Oracle and SQL Server. For
example, suppose that when a record is updated in a specific table, you wish to
create another record in a further table. This created record may not relate to the first record
but may just be an item held for memorandum purposes.
When you create a trigger on a heavy duty database, it will perform an update, delete, or
insert function on a specified table on the database. It is fired by an event happening on the
original table itself.
Access 2010 now gives you this functionality, but it is somewhat restrictive. The logical
way to have designed this would have been to allocate each table a VBA module with events
such as update, delete, and insert, similar to forms and reports. The developer would then be
able to attach VBA code to the event and would have the full flexibility to create the code
that they wanted.
Instead, the table macros use a pseudo-macro development screen, which greatly restricts
what the developer can achieve. However, it is a big step forward for Access and opens up
interesting possibilities.


Creating a Table Macro


Create a sample table in your current database that contains two numeric fields. To do this,
click Create on the Access menu and then click the Table Design icon in the tables group of
the ribbon. Create two numeric fields (Number1 and Number2). Your Table Design window
should now look like Figure 13-1.


165

Free download pdf