接下来没有For compile错误

时间:2016-12-12 14:28:34

标签: vba access-vba

我是VBA的新手,正在开展一个项目,该项目将显示所有打开特定文件的当前用户(MS Access)。我试图用计算机名称信息填充列表框但是当我尝试运行按钮命令时出现错误。因为它是计算机名称,所以我需要唯一的字段。我只需要一个连接的所有计算机名称的列表。

Sub ShowUserRosterMultipleUsers()
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset

    Set cn = CurrentProject.Connection

    Set rs = cn.OpenSchema(adSchemaProviderSpecific, _
    , "{947bb102-5d43-11d1-bdbf-00c04fb92675}"

    'While Not rs.EOF
        'Debug.Print rs.Fields(0), rs.Fields(1), _
        'rs.Fields(2), rs.Fields(3)
        'rs.MoveNext
    'Wend

    Do While Not rs.EOF
        With List73
            .AddItem rs.Fields(0)
        End With
    Next
End Sub

1 个答案:

答案 0 :(得分:-1)

Sub ShowUserRosterMultipleUsers()
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset

    Set cn = CurrentProject.Connection

    Set rs = cn.OpenSchema(adSchemaProviderSpecific, _
    , "{947bb102-5d43-11d1-bdbf-00c04fb92675}"

    'While Not rs.EOF
        'Debug.Print rs.Fields(0), rs.Fields(1), _
        'rs.Fields(2), rs.Fields(3)
        'rs.MoveNext
    'Wend

    Do While Not rs.EOF
        With List73
            .AddItem rs.Fields(0)
        End With
    Loop
End Sub