【发布时间】:2019-06-23 06:13:38
【问题描述】:
我正在尝试做一些基本的事情: 从 accdb 文件中获取 2 个日期 [startD] 和 [endD]。 将它们各向前移动一个月 将新日期保存为相应记录中的短日期。
我都是用 VBA 做的
问题是它显示了正确的 SQL 字符串(如果我使用 msgbox sql)但是当它保存时,它保存为带有时间的一般日期并且是错误的值! *注意:我在澳大利亚,所以我有一个格式部分来确保正确保存日期。
我也尝试过使用 DateValue() 并格式化日期。
Dim frq As Integer
Dim wks As Integer
Dim CurAcc As Integer
Dim CurAccEnd As Date
Dim Days As Integer
Dim curaccvalue As Currency
Dim cardtype As Integer
Dim cardcharged As Integer
cardtype = 0
cardcharged = 0
CurAcc = Me.ID
curraccvalue = DLookup("Acccurvalue", "Accounts", "[ID] = " & CurAcc)
Curraccend = DLookup("Accend", "Accounts", "[ID] = " & CurAcc)
frq = DLookup("freqid", "Accounts", "[ID] = " & CurAcc)
wks = DLookup("freqvalue", "tblfrequency", "FrequencyID = " & frq)
Days = wks * 7
strsql = "UPDATE Accounts SET AccStart = " & Date & " , AccEND = " &
Curraccend + Days & " , AccCurValue = 0.00 WHERE ID = " & CurAcc
MsgBox strsql
DoCmd.RunSQL strsql
【问题讨论】:
-
日期是一个数字(长整数表示日期,双精度表示日期/时间)。今天是第 43495 天 (
? CLng(Date)),这个值没有对错之分。` Format(43495, "dddd")` 将显示 星期三。您可以将日期格式化为Format(Date, "dd/mm/yyyy")或任何其他格式,但请记住Format函数返回一个字符串。将日期存储为数字时,显示格式将采用字段格式。 -
照常将日期保存在日期/时间字段中,使用文本框中的格式显示为短日期。
-
如果您看到时间部分,则必须将 Format 属性设置为一般日期。不要在表格中指定任何格式,应默认为短日期。
标签: sql vba datetime ms-access