设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

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

[Access本身] 求问!!!关于自动编号

[复制链接]
跳转到指定楼层
1#
发表于 2011-10-8 10:46:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
自己想要做个进销存,可是来料编号要写成LL1110-08-01,其中LL就是来料,中间的1110-08就是今天的系统日期,01就是自动编号,表示是今天的第一个来料,而今天的第二个来料是LL1110-08-02,怎么弄呀,我刚入门?请问关于进销存有没有什么比较好的书?
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2011-10-8 10:57:10 | 只看该作者
Public Function Autonum(Expr As String, Domain As String, Fcode As String, Optional Ln As Integer, Optional Ymd As String) As String
'Expr-必须,自动编号的字段名,Domain-必须,自动编号字段所在表或查询,Fcode-编号前的任意字符或代码,Ln-日期后的递增数字位数,默认1,Ymd-可选,日期格式,默认"yyyymmdd"
Dim a As Integer
Dim b As Integer
Dim c As String
Dim d As Variant
Dim e As String
Dim f As String

If Nz(Ln, 0) < 1 Then
b = 1
Else
b = Ln
End If
If Ymd = "" Then
e = Format(Date, "yyyymmdd")
Else
e = Format(Date, Ymd)
End If
f = "000000000000000000000"
a = DCount(Expr, Domain)
If a = 0 Then
Autonum = Fcode & e & Right(f, b - 1) & 1
Exit Function
Else
d = Val(Right(DMax(Expr, Domain), Len(e) + b))
c = Left(d, Len(e))
If c >= e Then
Autonum = Fcode & d + 1
Else
Autonum = Fcode & e & Right(f, b - 1) & 1
End If
End If
End Function
3#
 楼主| 发表于 2011-10-8 12:14:00 | 只看该作者
tzh16000 发表于 2011-10-8 10:57
Public Function Autonum(Expr As String, Domain As String, Fcode As String, Optional Ln As Integer, O ...

不太明白,这代码贴在哪?刚入门,有没有书推荐呀?
4#
发表于 2011-10-8 13:51:17 | 只看该作者
☆西鬼♂ 发表于 2011-10-8 12:14
不太明白,这代码贴在哪?刚入门,有没有书推荐呀?

建立模块,定义函数
窗体中调用此函数就可以
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-9-20 17:45 , Processed in 0.107640 second(s), 26 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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