DAO/链接表/ADO/ADP
使用Jet UserRoster判断谁登陆了Access2002/2003数据库
2005-02-06 02:02:32

Procedure

To determine who is logged onto a database, follow these steps:
1. CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.
2. Open the sample database, Northwind.mdb.
3. On the View menu, point to Database Objects, and then click Modules.
4. Click New.
5. Type or paste the following code:

Sub ShowUserRosterMultipleUsers() 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) rs.MoveNext Wend End Sub

6. Save the module as ShowUsers.
7. Close and then reopen the database.
8. Press CTRL+G to open the Immediate Window.
9. Type the following line in the Immediate window, and then press ENTER:

ShowUserRosterMultipleUsers

Note that the Immediate window returns a list of users who are logged onto the database.
back to the top

APPLIES TO
Microsoft Office access 2003
Microsoft access 2002 Standard Edition
Microsoft Visual Basic for Applications 6.0
Keywords: 
kbhowtomaster KB285822
首页