开发者

Continuous form selection deselected on command button click

开发者 https://www.devze.com 2023-04-08 10:46 出处:网络
I have a continuous access form with record开发者_运维知识库 selectors enabled.Here\'s the code for the btnPrintReceipt click event handler.I want it to get the ReceiptID of each selected record and o

I have a continuous access form with record开发者_运维知识库 selectors enabled. Here's the code for the btnPrintReceipt click event handler. I want it to get the ReceiptID of each selected record and open the report with those id's. The problem is, when you click the command button, it deselects all the records (I see it happen) and only keeps the top one available.

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


Microsoft has a fairly long article on How to enumerate selected form records in Access 2000, which will also work with later versions. The article includes code for running on a command button.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号