由于出错,列定价日期为空。 我跑到下面的VBA代码:
Sub ttm()
Dim db As Database, rs As DAO.Recordset, strsql As String
Dim startdate As Date, maturity As Date, maturity_month As Double
Dim maturity_year As Double
Set db = CurrentDb()
strsql = "SELECT * FROM dbo_PricingFutures ORDER BY PricingDate;"
Set rs = db.OpenRecordset(strsql, dbOpenDynaset)
rs.MoveFirst
While (Not rs.EOF())
rs.Edit
startdate = rs.Fields("PricingDate")
maturity_month = rs.Fields("PricingMonth")
maturity_year = rs.Fields("PricingYear")
maturity = DateSerial(maturity_year, maturity_month, 14)
rs.Fields("ttm") = DateDiff("d", startdate, maturity)
rs.Update
rs.MoveNext
Wend
rs.Close
db.Close
End Sub
然后,我在下面的行得到了一个错误:
startdate = rs.Fields("PricingDate")
结果表明,列PricingDate是空的。 然后,我从旧的备份数据中复制/粘贴到PricingDate列中,并且完美地工作。
SQL代码运行时未显示错误。
我认为你看到的查询将始终是空的选择。要真正看到查询是否已经生效,你需要检查你正在更新的表格。 – PaulFrancis
我检查了表,它仍然是空的 –
古玩。当您点击上面的消息框中的“是”时,它是否会出现警告或错误消息? – PaulFrancis