设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1411|回复: 1
打印 上一主题 下一主题

[其它] 关于自动编号不能增加新纪录

[复制链接]
跳转到指定楼层
1#
发表于 2011-5-20 20:52:35 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2011-5-20 22:20:01 | 只看该作者
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的事情,怎么会折腾出这么多行代码?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-7 02:28 , Processed in 0.071755 second(s), 25 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表