我正在尝试计算日期范围内的月份并将列表添加到表格中。以下是我的代码。它在下面用粗体加粗的线上分解。请帮我理解错误是什么。
Public Function MonthsDtRg() As Integer
Dim dbs As DAO.Database
Dim rs As DAO.Recordset
Dim MonDtRg As Variant
Dim i As Integer
Dim j As Integer
Dim FirstDay As Variant
StDate = Forms!PBCIncSum!StDate
EndDate = Forms!PBCIncSum!EndDate
MonDtRg = Month(StDate)
NMon = DateDiff("m", StDate, EndDate) + 1
FirstDay = DateSerial(Year(StDate), Month(StDate), 1)
i = 0
j = 0
Set dbs = CurrentDb
**Set rs = dbs.OpenRecordset("MonDtRg", OpenDynaset)**
Do While i < NMon
i = i + 1
rs.AddNew
rs(j).Value = MonDtRg
rs.Update
j = j + 1
FirstDay = DateAdd("m", 1, FirstDay)
MonDtRg = Month(FirstDay)
Loop
End Function