Access交流中心

北京 | 上海 | 天津 | 重庆 | 广州 | 深圳 | 珠海 | 汕头 | 佛山 | 中山 | 东莞 | 南京 | 苏州 | 无锡 | 常州 | 南通 | 扬州 | 徐州 | 杭州 | 温州 | 宁波 | 台州 | 福州 | 厦门 | 泉州 | 龙岩 | 合肥 | 芜湖 | 成都 | 遂宁 | 长沙 | 株洲 | 湘潭 | 武汉 | 南昌 | 济南 | 青岛 | 烟台 | 潍坊 | 淄博 | 济宁 | 太原 | 郑州 | 石家庄 | 保定 | 唐山 | 西安 | 大连 | 沈阳 | 长春 | 昆明 | 兰州 | 哈尔滨 | 佳木斯 | 南宁 | 桂林 | 海口 | 贵阳 | 西宁 | 乌鲁木齐 | 包头 |

[5分]自定义函数能不能作为默认值

benhum  发表于:2017-05-03 22:47:40  
复制

ACCESS自带的函数可以作为默认值,例如文本的默认值=date() 或 =format(date(),"yymmdd")

想问问ACCESS有什么办法可以使用自定义函数作为默认值?

例如现自定义函数getdatetime,如下:

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

那么,有什么办法可以用这个自定义函数getdatetime作为默认值?

请版主及各位大侠帮忙,谢谢!

 

Top
西出阳关无故人 发表于:2017-05-04 10:36:49
你在窗体中设置默认值为自定义函数的值就可以了。不能在表中设置默认值为自定义函数的值(至少没有找到现成的方法)。

benhum 发表于:2017-05-04 13:11:29
总记录:2篇  页次:1/1 9 1 :