Generate a sequential number (per group) when adding a row to an Access table

前端 未结 3 1193
悲&欢浪女
悲&欢浪女 2021-01-07 10:45

I have an MS Access (.accdb) table with data like the following:

Location Number
-------- ------
ABC      1
DEF              


        
3条回答
  •  误落风尘
    2021-01-07 11:05

    For Access 2010 and newer, this is a better way to do it. It uses the table's Before Change Data Macro to derive the next sequential number and put it in the [Number] field of the new record:

    BeforeChange.png

    The advantages of this approach are:

    • The sequence number will be applied whenever a new record is added, regardless of how it is added.
    • The Excel VBA code does not have to worry about creating the sequence number; it "just happens".
    • Since this code resides at the table level it should be safe for a multi-user environment.

    For more information on Data Macros, see

    Create a data macro

提交回复
热议问题