MS Access DB不一致地产生运行时错误2473

时间:2016-12-07 10:24:03

标签: ms-access access-vba ms-access-2010

我设计的Access DB产生运行时错误2473,指出“对象或类不支持事件集”。错误产生不一致,这使我很难追踪它。

调试器在出现以下代码行时停止:

'Open report containing code to create TOC with list of ISINs from above
DoCmd.OpenReport rptName, acViewPreview, , strWhere

即使发生错误,此代码也适用于某些报告,但会为其他报告生成运行时错误。在设计模式下打开报表和基础查询后,运行时错误有时会消失,即使我在代码,表单中没有任何更改,甚至更新了基础数据。

为了解决这个问题,我将我的数据库恢复到我知道问题仍然存在的早期版本,但打开恢复的版本后,它不再也有运行时错误!

可能导致此行为的原因是什么?

更新: 表格中包含的完整代码

Sub cmdFundSelectionReport_Click()
'Gather selected ISIN and pass it to Fund Selection Report
Dim var As Variant
Dim sFund As String
Dim strWhere As String
Dim lst As Access.ListBox
Dim i As Integer
Dim rptType As Integer

'Create list of isin to send to report
Set lst = Me.libFilterSelection
rptType = Me.cmbReportType

Dim dict As Object
Set dict = CreateObject("Scripting.Dictionary")

For i = 0 To lst.ListCount - 1
    If Not dict.Exists(lst.Column(1, i)) Then
        dict.Add lst.Column(1, i), i
    End If
Next i

Dim a As Variant
a = dict.keys

strWhere = "[ISIN] IN("
For i = 0 To dict.Count - 1
    strWhere = strWhere & """" & a(i) & ""","
Next i
strWhere = Left(strWhere, Len(strWhere) - 1)
strWhere = strWhere & ")"

'Set dictionary back
Set dict = Nothing

Dim rptName As String
Select Case rptType
Case 2
    rptName = "rptRDRSelectionList" '2 is the RDR List
    'strWhere = strWhere & " AND Fund_Selection=2"
Case 3
    rptName = "rptAsiaSelectionList" '3 Asia
    'strWhere = strWhere & " AND Fund_Selection=3"
Case Else
    rptName = "rptFundSelectionList" '0 = Fund Selection
    'strWhere = strWhere & " AND Fund_Selection=0"
End Select

'Open Report for view
OpenReport rptName, strWhere

'Write Log
WritelogMessage Now & " | User: " & fncUserName & " | Report Created | ReportName: " & rptName

End Sub

Sub OpenReport(rptName As String, strWhere As String)

'Open report containing code to create TOC with list of ISINs from above
DoCmd.OpenReport rptName, acViewPreview, , strWhere

'Click through report so that TOC code is executed
Dim rptCurReport As Report
Set rptCurReport = Screen.ActiveReport

With rptCurReport
    Application.DoCmd.SelectObject acReport, .Name
    .Visible = True 'switch to false once code is ok
    'Go through all pages
    SendKeys "{End}", True
    DoEvents
    Application.DoCmd.SelectObject acReport, .Name
    DoCmd.Close acReport, .Name, acSaveNo
End With

rptName = rptName & "TOC" 'Add TOC to get Table of Contents Report

''Check whether "Internal Use Only Flag" is set to true or false
'Dim bInternalUse As Boolean
'bInternalUse = Me.ckbInternalUse.Value
'Call modProcess.ChangeReportPicture("rptFundSelectionListTOC", "picInternalUse", bInternalUse)

'Open final report that includes the TOC as a subreport with same string of ISIN
DoCmd.OpenReport rptName, acViewPreview, , strWhere
SendKeys "{Home}", True
DoEvents

End Sub

0 个答案:

没有答案