给你个自动编码的:
Select Case e.DataCol.Name
Case "车系","车牌号"
Dim s1,s2 As String
Dim dr,dr1 As DataRow
dr = e.DataRow
s1 = dr("车牌号")
If dr("车系") ="" OrElse s1 = "" Then
dr("编号") = Nothing
Else
dr1=DataTables("编码").Find("车系='" & dr("车系") & "'")
If dr1 IsNot Nothing Then
s2= dr1("编码") & right(s1,1) & "-"
dr1 = DataTables("表A").Find("编号 Like '" & s2 & "*'" )
If DataTables("表A").DataRows.count =1 OrElse dr1 Is Nothing Then
dr("编号") = s2 & "001"
Else
Dim n,n1 As Integer
n1=Right(DataTables("表A").Compute("Max(编号)","编号 Like '" & s2 & "*'"),3)
For n = 1 To n1
If DataTables("表A").Find("编号 = '" & s2 & format(n,"000") & "'") Is Nothing Then
dr("编号") = s2 & format(n,"000")
Exit For
Else
dr("编号") = s2 & format(n1+1,"000")
End If
Next
End If
End If
End If
End Select