Office中国论坛/Access中国论坛

标题: 关于自动编号不能增加新纪录 [打印本页]

作者: t-back    时间: 2011-5-20 20:52
标题: 关于自动编号不能增加新纪录
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


作者: todaynew    时间: 2011-5-20 22:20
t-back 发表于 2011-5-20 20:52
Private Sub Command0_Click()
Dim Rs As New ADODB.Recordset
Dim Rst As New ADODB.Recordset

不知所云。
就是一个dlast或者dmax的事情,怎么会折腾出这么多行代码?




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3