|
Private Sub Command0_Click()
Dim Rs As New ADODB.Recordset
Dim Rst As New ADODB.Recordset
Dim Conn As New ADODB.Connection
Dim I As Integer
Set Conn = CurrentProject.Connection
Rs.Open "select [Co date] from co GROUP BY [Co date] order by [Co date]", Conn, adOpenDynamic, adLockOptimistic
Do While Not Rs.EOF
I = 1
Rst.Open "select * from co where [Co date]=#" & Rs.Fields(0) & "# order by [Co date]", Conn, adOpenDynamic, adLockOptimistic
Do While Not Rst.EOF
I = I + 110
Rst.Fields("coNO") = "AF-" & Format(I, "0000") & "-" & Format(Rs.Fields(0), "yymmdd")
Rst.MoveNext
Loop
Rst.Close
Rs.MoveNext
Loop
Set Rs = Nothing
Set Rst = Nothing
Set Conn = Nothing
End Sub
请教各位大大,
上面的代码哪里出错了,
为何第二次点击后和第一次点击的编号是一样的?
敬请指点,不胜感激。
Function AdNo() As String
Dim Rs As New ADODB.Recordset
Dim Conn As New ADODB.Connection
Dim I As Integer
Set Conn = CurrentProject.Connection
Rs.Open "select count(*) from co where mid(coNO,4,6)=format(date(),'yymmdd')", Conn, adOpenDynamic, adLockOptimistic
If Rs.EOF Then
I = 1
Else
I = Rs.Fields(0) + 110
End If
AdNo = "AF" & Format(I, "0000") & "-" & Format(Date, "yymmdd")
End Function
|
|