|
3#
楼主 |
发表于 2015-5-14 08:21:52
|
只看该作者
因为这个字段是主键且自动生成,格式又要求固定,所以用补0的方式可能会导致重复。
我用API解决了,但是这段API在Access里使用时有点问题,yyyymmdd会变成“年月和本周第几天”这种格式,大家自己调试一下,等上完班我再来补充正确用法。
Option Compare Database
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Declare PtrSafe Sub GetLocalTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
Public Function getdatetime() As String
Dim LCT As SYSTEMTIME
Dim ymd As String, hms As String
GetLocalTime LCT
ymd = Format(LCT.wYear & "-" & LCT.wMonth & "-" & LCT.wDay, "yyyyMMdd")
hms = Format(LCT.wHour, "00") & Format(LCT.wMinute, "00") & Format(LCT.wSecond, "00") & Format(LCT.wMilliseconds, "000")
getdatetime = ymd & hms
End Function
|
|