在 Access 数据库上显示用户

Show Users on Access Database

我正在尝试显示当前在我的 Access 数据库中的所有用户。我正在使用我在网上找到的 VBA 代码,并试图根据我的需要对其进行修改。我正在尝试获取所有可用用户并将其显示在名为 "ListUsers" 的表单的列表框中。

代码能够输出到调试 window 但我无法更新我的列表框。我收到以下错误:"Run-time error '6014': The RowSourceType property must be set to 'Value List' to use this method." 我查看了该列表框的 属性 window,但找不到与 RowSourceType 相关的任何内容。我在网上尝试了一些不同的建议,但我仍然无法更新列表框,所以我想看看这里是否有人有一些想法。我的代码在下面,我将 VBA 代码放在单击按钮上。

Option Compare Database
Option Explicit

Private Sub cmd_Users_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.recordset
Dim i, j As Long

Set cn = CurrentProject.Connection

' The user roster is exposed as a provider-specific schema rowset
' in the Jet 4.0 OLE DB provider.  You have to use a GUID to
' reference the schema, as provider-specific schemas are not
' listed in ADO's type library for schema rowsets

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

'Output the list of all users in the current database.

Debug.Print rs.Fields(0).Name, "", rs.Fields(1).Name, _
"", rs.Fields(2).Name, rs.Fields(3).Name

While Not rs.EOF
    Debug.Print rs.Fields(0), rs.Fields(1), _
    rs.Fields(2), rs.Fields(3)
    ListUsers.AddItem "'" & rs.Fields(0) & "-" & rs.Fields(1) & "'"
    rs.MoveNext
Wend

End Sub

我想通了...我必须在代码上设置 RowSourceType。我在按钮单击事件中添加了以下内容: Me.ListUsers.RowSourceType = "Value List"

这里还有一个不错的post: Ms Access AddItem with VBA