使您的PK成为自动编号并将其用于任何关系。对于您的序列号,请使用两个长整型字段(SN1,SN2)。在表单的before_update事件中,对于新记录,调用公共函数以生成新的“序列号”。
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim lngSN1 AS Long
Dim lngSN2 as Long
If Me.NewRecord Then
'if SN1 is not to be incremented, set it here to whatever you want
If GetSerials(SN1, SN2) Then
Me!SN1 = lngSN1
Me!SN2 = lngSN2
Else
Cancel = True
End If
End If
End Sub
Public Function GetSerials(ByRef SN1 as Long, ByRef SN2 as Long) AS Boolean
If SN1 = 0 Then
SN1 = Nz(DMax("SN1","<yourTable>"), 0) + 1
SN2 = 1
Else
SN2 = DMax("SN2", "<yourtable>","SN1=" & SN1) + 1
End IF
GetSerials = True
End Function
使用计算字段构建查询以创建组合'SerialNumber'。
SELECT *, "M" & SN1 & "-" & SN2 as SerialNumber FROM <yourtable>
无论您想要显示SerialNumber,都使用该查询。
来源
2016-10-31 12:42:51
AVG
所以第一张表我得到了一个主要的自动编号和一个外国编号。然后第二个表我怎么用pubilc函数生成序列号?当你提到“锁定”时,如何锁定号码? – KokJoo89