rs。3021运行时错误在子窗体中选择记录时移动

时间:2017-06-30 12:05:24

标签: ms-access

我参考How do I access the selected rows in Access?编辑了代码。但是即使m_SelNumRecs不为零,我的代码在RS.Move F.SelTop - 1得到了3021的运行时错误。我不确定是否必须在代码中添加其他代码。 我有一个包含frm_SubPerson子表单的表单。我在frm_SubPerson上选择记录,并希望将记录转换为pdf。

Public m_SelNumRecs As Long
Public m_SelTopRec As Long
Public m_CurrentRec As Long

Private Sub cmdConvert()
   Dim mSelTop As Long
   Dim mSelHeight As Long
   Dim F As Form
   Dim RS As Recordset
   Dim filePath As String
   Dim i As Integer

   ' Get the form and its recordset.
   Set F = Me.frm_SubPerson.Form
   Set RS = F.RecordsetClone

   If m_SelNumRecs = 0 Then
      MsgBox "no record is selected."
      Exit Sub
   End If

   ' Move to the first selected record.
   RS.Move F.SelTop - 1 '3021 error

   For i = 1 To m_SelNumRecs
       DoCmd.OpenReport "report_Person", acViewPreview, , "report_Person.chName=" & "'" & RS!chName.Value & "'"
       filePath = "D:\report_Person\" & "report_Person" & RS!chName & "_" & RS!chNum & "_" & RS!reYear.Value & "Year" & RS!reMonth & "Month" & ".pdf"
       DoCmd.OutputTo acOutputReport, "", acFormatPDF, filePath
       DoCmd.Close acReport, "report_Person"
       RS.MoveNext
   Next i

   RS.Close
   Set RS = Nothing
End Sub

Private Sub frm_SubPerson_Exit(Cancel As Integer)
   With frm_SubPerson.Form
   m_SelNumRecs = .SelHeight
   m_SelTopRec = .SelTop
   m_CurrentRec = .CurrentRecord
   End With
End Sub

0 个答案:

没有答案