由於出錯,列定價日期爲空。 我跑到下面的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