设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

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

在adp的窗体中的流水号的实现

[复制链接]
跳转到指定楼层
1#
发表于 2008-6-5 10:43:41 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在ADP的窗体中实现自动流水号,如20080605-001,20080605-002
要先建一张单号表,create table t_dh(rq datetime,fhlsh int)
rq记录日期,fhlsh是流水号的最大值
必需在窗体的插入前和更新前写程序.
我这个是改进后的,那多人操作时,如流水号到了20080605-007,这时
t_dh表中的 fhlsh 的值为7如果两个天在同时录入,就会出现两个人的流水号为
20080605-008这是不行的其中一个要为20080605-009我就是对这个进行了改进
(请大家多多指教)
t_fhd的表结构为 create table t_fhd (id int,lsh varchar(50))

这是插入前的
Private Sub Form_BeforeInsert(Cancel As Integer)
On Error GoTo Err_Form_BeforeInsert
Dim rst1 As New ADODB.Recordset
Dim d As Variant

d = DLookup("fhlsh", "t_dh", "rq ='" & Format(Date, "yyyy-mm-dd") & "'")
If IsNull(d) Then  '若找不到
    rst1.Open "select * from t_dh", CurrentProject.Connection, adOpenDynamic, adLockOptimistic
    rst1.AddNew
    rst1("rq") = Format(Date, "yyyy-mm-dd")
    rst1("fhlsh") = 0
    rst1.Update
    rst1.Close
    Set rst1 = Nothing
   
    d = 0
End If
Me![lsh] = Format(Date, "yymmdd") & "-" & Format(Nz(d, 0) + 1, "000") '加1后显示
Exit_Form_BeforeInsert:
  Exit Sub
Err_Form_BeforeInsert:
  MsgBox Err.Description
  Resume Exit_Form_BeforeInsert
End Sub
更新前的
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Form_BeforeUpdate
Dim d As Variant
Dim x As Variant
Dim rst1 As New ADODB.Recordset
Dim d2 As Variant
Dim strLsh As String

If Me.NewRecord = True Then  '若为新记录
    rst1.Open "select * from t_dh where rq ='" & Format(Date, "yyyy-mm-dd") & "'", CurrentProject.Connection, adOpenDynamic, adLockOptimistic
   
    '判断一下这个流水号是在发货记录(t_fhd)中是否有了
    d = 0
    Do Until IsNull(d) = True  'd为空时才退出循环,说明流水号无重复
       d = DLookup("lsh", "t_fhd", "lsh='" & Me.lsh & "'")
       If Not IsNull(d) Then
           strLsh = Me.lsh
           Me.lsh = Format(Date, "yyyymmdd") & "-" & Format(CInt(Right(Me![lsh], 3)) + 1, "000")
           MsgBox strLsh & "已存在,改为" & Me.lsh
      
        End If
    Loop
    x = Right(Me![lsh], 3)
   
   
    rst1("fhlsh") = CInt(x)   '回存目前使用编号
    rst1.Update
    rst1.Close
    Set rst1 = Nothing
End If

Exit_Form_BeforeUpdate:
   Exit Sub
Err_Form_BeforeUpdate:
   MsgBox Err.Description
   Resume Exit_Form_BeforeUpdate
End Sub
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2008-6-5 11:55:07 | 只看该作者
谢谢分享,瞧一瞧
3#
发表于 2009-9-26 14:31:14 | 只看该作者
ddd
4#
发表于 2009-9-27 10:00:50 | 只看该作者
请指教,我是用列字段的默认值来处理这个流水号的,OR2009090901
标志+年+月+日+2位流水号

处理过程使用自自定义函数f_NewWork('OR')来自动生成.
5#
发表于 2009-10-27 22:40:00 | 只看该作者
听说在ADP中使用聚合函数不行
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-6 03:03 , Processed in 0.092246 second(s), 28 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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