同意用递归.这样编号全由用户自已定义.
我也刚学会.给你我程序中的代码!
Public Function checkBH(m_BH As String, m_BiaoMing As String) As Boolean ' 检测是否编号重复
Dim msgStr As String
tmpBiaoMing = m_BiaoMing
msgStr = ""
ReDim tmp(0)
GetChongFu m_BH, tmpBiaoMing '具体检测的过程
If UBound(tmp) > 0 Then '如果修改了数组的维数,则也就是说明有重号
For i = UBound(tmp) To 1 Step -1 '连接数组中的各维
msgStr = msgStr & "\" & tmp(i)
Next
MsgBox "此编号被:'" & msgStr & "'占用!", vbOKOnly + vbInformation, App.title
checkBH = False
Else '没变占用
checkBH = True
'MsgBox "OK"
End If
End Function
Private Sub GetChongFu(m_BH As String, m_BiaoMing As String) '检测是否有重号,有则保存名称
Dim Sqlstring As String
Dim Rst As ADODB.Recordset
Set Rst = New ADODB.Recordset
Dim m_ParentBH As String
Sqlstring = "select * from " & m_BiaoMing & " where BianHao='" & m_BH & "'"
Set Rst = ExecuteSQL(Sqlstring)
If Rst.EOF = False Then
ReDim Preserve tmp(UBound(tmp) + 1)
tmp(UBound(tmp)) = Rst!mingcheng
GetChongFu Rst!parentbh, tmpBiaoMing '递归调用
End If
Set Rst = Nothing
End Sub