我想在ms-access中有条件地为自动编号或数字加前缀

问题描述 投票:-1回答:1

字段

[Group] (values are ARTS , PRE-MED , PRE-ENG, ICS )

我想要关于名为RollNo的新领域的数据,如18AR01“

only 2 last digits of current year + iif([group]=ARTS,AR,iif([group]=PRE-MED,PM,iif([group]=PRE-ENG,PE,iif([group]=ICS,NULL,))))这怎么可能?

ms-access-2016
1个回答
0
投票

您可以使用表单的BeforeInsert事件:

Dim Code As String
Dim Number As Integer    

Code = Nz(Format(Date, "yy") & Switch(Me![Group] = "ARTS", "AR", Me![Group]= "PRE-MED", "PM", Me![Group] = "PRE-ENG", "PE"))
Number = Val(Nz(DMax("Right([RollNo], 2)", "YourTable", "[RollNo] Like '" & Code & "??'"))) + 1

Me!RollNo.Value = Format(Date, "yy") & Code & Format(Number, "00")
© www.soinside.com 2019 - 2024. All rights reserved.