在命令按钮单击时取消选择连续表单选择

时间:2011-09-25 10:57:00

标签: ms-access vba ms-access-2003 continuous-forms

我有一个连续的访问表单,启用了记录选择器。这是btnPrintReceipt点击事件处理程序的代码。我希望它获取每个选定记录的ReceiptID并打开带有这些ID的报告。问题是,当你单击命令按钮时,它取消选择所有记录(我看到它发生)并且只保留最顶层记录。

Private Sub btnPrintReceipt_Click()
    'Build filter string containing all selected receipt ids
    Dim FilterString As String

    'Move to first record
    Dim rsReceipts As Recordset
    Set rsReceipts = Me.RecordsetClone
    rsReceipts.Move Me.SelTop - 1

    'Cycle through and record
    Dim i As Integer
    For i = 0 To Me.SelHeight
        FilterString = FilterString & "([ReceiptNumber]=" & rsReceipts![ReceiptNumber] & ") OR "
        rsReceipts.MoveNext
    Next

    'Remove trailing or
    Dim NewStringLenth As Integer
    NewStringLenth = Len(FilterString) - 4
    If NewStringLenth > 0 Then
        FilterString = Left(FilterString, NewStringLenth)
    Else
        FilterString = ""
    End If

    'Open the report
    DoCmd.OpenReport "rptReceipt", acViewPreview, "", FilterString
End Sub

1 个答案:

答案 0 :(得分:1)

Microsoft在How to enumerate selected form records in Access 2000上发表了一篇相当长的文章,该文章也适用于更高版本。本文包含在命令按钮上运行的代码。