设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
楼主: tmtony
打印 上一主题 下一主题

[Access本身] Access技巧接龙

[复制链接]
101#
发表于 2007-11-7 17:06:14 | 只看该作者
学习,学习
102#
发表于 2007-12-15 11:00:56 | 只看该作者
'===============================================================================
'-函数名称:         autoID
'-功能描述:         自动编号 ,
'-输入参数说明:     参数1:tblname 表名
'                   参数2:fldname 字段名
'                   参数3:intlength增长号的长度
'                   参数4:prefix 前缀(可选参数)
'                   参数5:dateformat时间前缀(可选参数)
'-返回参数说明:     可以按时间自增长编号, 如果没有时间就自增长编号
'-使用语法示例:     AutoID("型体编号表", "型体编号", 4, "GL")
'                   AutoID("型体编号表", "型体编号", 4)
'                   AutoID("型体编号表", "型体编号", 4, "GL","yyyymmdd")
'-参考:
'-使用注意:
'-兼容性:           2000,XP,2003
'-作者:             Victor Duane
'-更新日期:        2007-12-5 17:03
'===============================================================================
Function AutoID(tblName As String, fldName As String, intLength As Integer, Optional Prefix As String = "", Optional DateFormat As String = "") As String
'自动编号 , 可以按时间自增长编号, 如果没有时间就自增长编号
Dim rs As New ADODB.Recordset
Dim cn As New ADODB.Connection

Dim intDate As Integer
Dim intPrefix As Integer

Dim strDate As String
Dim strToday As String
Dim OldDate As String

'如果DateFormat为空,当天日期为空,否则为当天日期
If Len(DateFormat) = 0 Then
    strToday = ""
Else
    strToday = Format(Date, DateFormat)
End If

strDate = strToday
intDate = Len(strDate) '取得时间的长度
intPrefix = Len(Prefix) '取得前缀的长度

Set cn = CurrentProject.Connection
Dim strSQL As String
strSQL = "select * from " & tblName & " order by " & fldName
rs.Open tblName, cn, 1, 2

Debug.Print rs.RecordCount
If rs.RecordCount > 0 Then
    rs.MoveLast
    '取得最大值的时间前缀
    OldDate = Nz(Mid$(rs(fldName), intPrefix + 1, intDate), "")
    '判断新增的值是否跨时间
    If strToday = OldDate Then
        AutoID = Prefix & strDate & Format(Val(Right$(rs(fldName), intLength) + 1), String(intLength, "0"))
    Else
        AutoID = Prefix & strDate & String(intLength - 1, "0") & "1"
    End If
Else
    AutoID = Prefix & strDate & String(intLength - 1, "0") & "1"
End If

rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End Function
我的自动编号的函数
103#
发表于 2007-12-18 00:30:34 | 只看该作者
:lol :lol :lol :lol :lol :lol :lol :lol
104#
发表于 2007-12-27 11:42:34 | 只看该作者
不知道什么时候可以学成!!
105#
发表于 2007-12-27 11:43:58 | 只看该作者
楼上那抄的?不知道什么时候可以学成!!
106#
发表于 2008-1-9 21:52:32 | 只看该作者
认真学习中!!!!!!!!
107#
发表于 2008-1-10 23:10:30 | 只看该作者
多多学习,争取成长0
108#
发表于 2008-1-12 20:23:44 | 只看该作者
向各位前辈多多学习 :victory: :victory: :victory:
109#
发表于 2008-1-16 13:50:48 | 只看该作者
好東東就得頂
110#
发表于 2008-1-18 09:34:58 | 只看该作者
顶你。顶你。顶你。顶你。顶你。顶你。顶你。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-16 09:51 , Processed in 0.102893 second(s), 33 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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