0

我在复制数据时遇到问题。我有一个显示为数据表的子表单,有 8 列和动态行数。我有一个代码,如果您在数据表中选择一个单元格并按下按钮,它将将该行复制到 ListBox。但我不知道如何制作一个循环,将所有行(或选定的几行)复制到列表框中。如果选择了多行,则仅复制第一行。

Private Sub Command_Click()
 Dim item(1 To 8) As String
  With frmPresentationList

    item(1) = ![Col1]
    item(2) = ![Col2]
    item(3) = ![Col3]
    item(4) = ![Col4]
    item(5) = ![Col5]
    item(6) = ![Col6]
    item(7) = ![Co87]
    item(8) = ![Col1]
 End With

 With Me.selectedItems
    .AddItem Join(item, ";")
 End With
End Sub

谢谢!

4

1 回答 1

0

示例代码。我总是将子表单/子报表容器控件命名为与其所拥有的对象不同的名称。子窗体容器控件名为 ctrRates。

Option Compare Database
Option Explicit

Dim intHeight As Integer    'stores value for number of records selected
Dim intTop As Integer   'stores value for position of first selected record

Private Sub ctrRates_Exit(Cancel As Integer)
    intHeight = Me.ctrRates.Form.SelHeight
    intTop = Me.ctrRates.Form.SelTop
End Sub

Private Sub btnFillListbox_Click()
    Dim N As Integer
    If intHeight > 0 Then
        Me.SelectedItems.RowSource = ""
        With Me.ctrRates.Form.RecordsetClone
            .MoveFirst
            'AbsolutePosition property is 0 based counter so must -1 to set RecordsetClone position
            .AbsolutePosition = intTop - 1
            For N = 1 To intHeight
                Me.SelectedItems.AddItem (!RateID)
                .MoveNext
            Next
        End With
    End If
End Sub
于 2018-05-23T20:45:58.167 回答