In Oracle,u can use
Create sequence test_sequence increment by 1
start with 1 maxvalue 999999 cycle order
later,u can use test_sequence.nextval to get the unique key.
every time u use it,it can automatically increase by 1.
for example,
insert into test_table(id,name) values(test_sequence.nextval,'Mike')
你用的数据库是?
象SQL SERVER ,ACCESS...等都有AutoNumber的类型
如果要生成特别的单号:
'Dim MyDB As Database, MYSET As Recordset
Dim CurrentTime As String
Dim CurrentTime1 As String
Dim TempCount As Integer
Dim Max As Variant
Dim AdoTemp As ADODB.Recordset
Dim comp_code As String
Dim Count As Integer
Dim n_month As Integer, w_month As String, w_day As String, w_year As String
Dim MaxCount As Integer
'笆穝糤腹
Set AdoTemp = MyAdo
Dim x As Variant, news As Variant, newstr
If MyAdo.State = 1 Then
MyAdo.Close
End If
MyAdo.Open
Count = Len(Class) + 4
MaxCount = MyAdo.RecordCount
TempCount = MyItem
'If MaxCount <> 0 Then
' Max = Left(Right(MyAdo.Fields.Item(TempCount), count), 4)
'End If
w_year = Year(MyDate)
w_month = Month(MyDate)
If w_month < 10 Then
w_month = "0" + w_month
End If
CurrentTime1 = CStr(w_year) + CStr(w_month)
'comp_code = DLookup("company_code", "dpif09", "") //そ嘿ぃ莉眔
'news = DMax(Myfield, Mytable, Myfield & " Like '" & Left(comp_code, 2) & w_month & w_day & "*'")
If MaxCount - 1 <> 0 Then
With AdoTemp
.MoveFirst
While Not .EOF
If (Not IsNull(.Fields(TempCount))) Then
CurrentTime = Mid(.Fields(TempCount), 2, 6)
Else
If IsNull(CurrentTime) Then
CurrentTime = 0
End If
End If
If CurrentTime1 = CurrentTime Then
If Max < Mid(.Fields.Item(TempCount), 8, 4) Then
Max = Mid(.Fields.Item(TempCount), 8, 4)
End If
End If
.MoveNext
Wend
End With
If IsNull(Max) Then
Max = 0
End If
news = Max
If IsNull(news) Or news <> "" Then
newstr = Format(CStr(Max + 1), "0000")
Else
newstr = "0001"
End If
Else: newstr = "0001"
End If
'If Language = "china" Then
NewNo2 = Factory & w_year & w_month & w_day & newstr & Class
'End If