可以在[区别]文体框的更新事件中写入下面代码,本代码默认值为0001,有号码时自动递增
Private Sub 区别_BeforeUpdate(Cancel As Integer)
If IsNull(DLookup("[号码]", "区别表", "[区别]=" & "'" & 区别 & "'")) Then '查询表中是否有该区别有号码
'没有时增加一个区别号+号码
If Me.区别 = "中区" Then
Me.号码 = "010001"
ElseIf Me.区别 = "东区" Then
Me.号码 = "020001"
ElseIf Me.区别 = "南区" Then
Me.号码 = "030001"
ElseIf Me.区别 = "西区" Then
Me.号码 = "040001"
ElseIf Me.区别 = "北区" Then
Me.号码 = "050001"
Else '如果不在区别范围内发出提示
MsgBox "输入的区别有误,请重输入", , "系统提示"
End If
Else '如果表中有该区别,在原号码基础上+1
Me.号码 = DMax("[号码]", "区别表", "[区别]=" & "'" & 区别 & "'") + 1
End If
End Sub
[此贴子已经被作者于2005-10-13 14:31:16编辑过]
|