我正在尝试做一些基本的事情: 从accdb文件中获取两个日期[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
答案 0 :(得分:0)
将日期隐式转换为字符串时,将使用您的区域设置,但在SQL字符串中,日期必须为美国格式。
为避免这种情况,我建议仅在一个查询中进行更新:
Dim strSql As String
strSql = "UPDATE Accounts " & _
"INNER JOIN tblfrequency ON Accounts.freqid = tblfrequency.FrequencyID SET " & _
"AccStart = Date(), " & _
"AccEND = DateAdd(""w"", tblfrequency.freqvalue, Accounts.Accend), " & _
"AccCurValue = 0.00 WHERE ID = " & Me.ID
MsgBox strSql
DoCmd.RunSQL strSql