473,702 Members | 2,381 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Generate a User List

ADezii
8,834 Recognized Expert Expert
For this Tip, we will show you an extremely handy, multi-user, feature of Jet that allows you to manage Users more effectively. You can create a special, provider-specific Recordset in ADO that supplies information about the current Users in the Database. This is accomplished by using the OpenSchema() Method of the Connection Object, which will fill a recordset with varied sets of different Database Schema information. The output of this OpenSchema() Method will be written to a List Box (lstUsers) with the pre-defined headings of Computer, UserName, Connected?, and Suspect?.

I intentionally decided to display this Tip at this specific point in time because it is intimately related to the prior Tip, Passive Shutdown. They are both extremely helpful, multi-user, features that Jet 4 exposes, and they will greatly assist in the implementation of certain administrative tasks such as: Updates, Backups, etc. There will be certain instances when you, as the administrator of a multi-user Database, will want to be 100% sure that no Users are currently logged on to your back end database. Through the use of Passive Shutdown, when no additional Users will be allowed to log on, and the User List, which will display any currently logged on Users, you will be 100% guaranteed that no currently logged on individual will interfere with a critical process.

The code segment below will demonstrate how you can display this User List in a List Box on a Form. There are ample comments scattered through the code, but if you need any further explanation on any specific area, please feel free to ask.
Expand|Select|Wrap|Line Numbers
  1. 'The User List Schema information requires this magic number. For anyone
  2. 'who may be interested, this number is called a GUID or Globally Unique
  3. 'Identifier - sorry for digressing
  4. Const conUsers = "{947bb102-5d43-11d1-bdbf-00c04fb92675}"
  5.  
  6. Dim cnn As ADODB.Connection, fld As ADODB.Field, strUser As String
  7. Dim rst As ADODB.Recordset, intUser As Integer, varValue As Variant
  8.  
  9. Set cnn = CurrentProject.Connection
  10. Set rst = cnn.OpenSchema(Schema:=adSchemaProviderSpecific, SchemaID:=conUsers)
  11.  
  12. 'Set List Box Heading
  13. strUser = "Computer;UserName;Connected?;Suspect?"
  14.  
  15. With rst    'fills Recordset (rst) with User List data
  16.   Do Until .EOF
  17.     intUser = intUser + 1
  18.       For Each fld In .Fields
  19.         varValue = fld.Value
  20.           'Some of the return values are Null-Terminated Strings, if
  21.           'so strip them off
  22.           If InStr(varValue, vbNullChar) > 0 Then
  23.             varValue = Left(varValue, InStr(varValue, vbNullChar) - 1)
  24.           End If
  25.           strUser = strUser & ";" & varValue
  26.       Next
  27.         .MoveNext
  28.   Loop
  29. End With
  30.  
  31. Me!txtTotalNumOfUsers = intUser        'Total # of Users
  32.  
  33. 'Set up List Box Parameters
  34. Me!lstUsers.ColumnCount = 4
  35. Me!lstUsers.RowSourceType = "Value List"
  36. Me!lstUsers.ColumnHeads = False
  37.   lstUsers.RowSource = strUser       'populate the List Box
  38.  
  39. 'Routine cleanup chores
  40. Set fld = Nothing
  41. Set rst = Nothing
  42. Set cnn = Nothing
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. Computer     UserName  Connected?  Suspect?
  2. DEZII          Admin       True
  3. IGUANA           Suzanne     True
  4. LIZARD           Paul         True
  5. FINANCE            Leonard     True
Jul 29 '07 #1
30 37062
kentgorrell
11 New Member
Does this only list users who are using the same front end MDB? Or will it list users who are using separate front end MDBs linked to the same backend MDB?
Jul 31 '07 #2
ADezii
8,834 Recognized Expert Expert
Does this only list users who are using the same front end MDB? Or will it list users who are using separate front end MDBs linked to the same backend MDB?
In a Multiuser Environment, it will generate a list of Current Users who are logged on to the Back End Database from separate Front End MDBs linked to the same backend. This would be the most practical application.
Jul 31 '07 #3
jqwert
1 New Member
For this Tip, we will show you an extremely handy, multi-user, feature of Jet that allows you to manage Users more effectively. You can create a special, provider-specific Recordset in ADO that supplies information about the current Users in the Database. This is accomplished by using the OpenSchema() Method of the Connection Object, which will fill a recordset with varied sets of different Database Schema information. The output of this OpenSchema() Method will be written to a List Box (lstUsers) with the pre-defined headings of Computer, UserName, Connected?, and Suspect?.

I intentionally decided to display this Tip at this specific point in time because it is intimately related to the prior Tip, Passive Shutdown. They are both extremely helpful, multi-user, features that Jet 4 exposes, and they will greatly assist in the implementation of certain administrative tasks such as: Updates, Backups, etc. There will be certain instances when you, as the administrator of a multi-user Database, will want to be 100% sure that no Users are currently logged on to your back end database. Through the use of Passive Shutdown, when no additional Users will be allowed to log on, and the User List, which will display any currently logged on Users, you will be 100% guaranteed that no currently logged on individual will interfere with a critical process.

The code segment below will demonstrate how you can display this User List in a List Box on a Form. There are ample comments scattered through the code, but if you need any further explanation on any specific area, please feel free to ask.
Expand|Select|Wrap|Line Numbers
  1. 'The User List Schema information requires this magic number. For anyone
  2. 'who may be interested, this number is called a GUID or Globally Unique
  3. 'Identifier - sorry for digressing
  4. Const conUsers = "{947bb102-5d43-11d1-bdbf-00c04fb92675}"
  5.  
  6. Dim cnn As ADODB.Connection, fld As ADODB.Field, strUser As String
  7. Dim rst As ADODB.Recordset, intUser As Integer, varValue As Variant
  8.  
  9. Set cnn = CurrentProject.Connection
  10. Set rst = cnn.OpenSchema(Schema:=adSchemaProviderSpecific, SchemaID:=conUsers)
  11.  
  12. 'Set List Box Heading
  13. strUser = "Computer;UserName;Connected?;Suspect?"
  14.  
  15. With rst    'fills Recordset (rst) with User List data
  16.   Do Until .EOF
  17.     intUser = intUser + 1
  18.       For Each fld In .Fields
  19.         varValue = fld.Value
  20.           'Some of the return values are Null-Terminated Strings, if
  21.           'so strip them off
  22.           If InStr(varValue, vbNullChar) > 0 Then
  23.             varValue = Left(varValue, InStr(varValue, vbNullChar) - 1)
  24.           End If
  25.           strUser = strUser & ";" & varValue
  26.       Next
  27.         .MoveNext
  28.   Loop
  29. End With
  30.  
  31. Me!txtTotalNumOfUsers = intUser        'Total # of Users
  32.  
  33. 'Set up List Box Parameters
  34. Me!lstUsers.ColumnCount = 4
  35. Me!lstUsers.RowSourceType = "Value List"
  36. Me!lstUsers.ColumnHeads = False
  37.   lstUsers.RowSource = strUser       'populate the List Box
  38.  
  39. 'Routine cleanup chores
  40. Set fld = Nothing
  41. Set rst = Nothing
  42. Set cnn = Nothing
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. Computer     UserName  Connected?  Suspect?
  2. DEZII          Admin       True
  3. IGUANA           Suzanne     True
  4. LIZARD           Paul         True
  5. FINANCE            Leonard     True
Thank you for supplying the code above, can you give me some more information regarding the basics of setting it up. Do you need to place the code into a module? from which a list box named "1stUsers" placed on a form displays data from another table with the pre-defined headings of Computer, UserName, Connected?, and Suspect? Thanks you for any assistance you may be able to provide.
Nov 3 '07 #4
ADezii
8,834 Recognized Expert Expert
Thank you for supplying the code above, can you give me some more information regarding the basics of setting it up. Do you need to place the code into a module? from which a list box named "1stUsers" placed on a form displays data from another table with the pre-defined headings of Computer, UserName, Connected?, and Suspect? Thanks you for any assistance you may be able to provide.
This is exactly how I would incorporate this functionality in my Database:
  1. Create a Form dedicated solely to the display of this User List. It should not serve any other function.
  2. Create a Private Sub Procedure in your Form and name it GenerateUserLis t. Copy and Paste the User List code to this Procedure as in:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub GenerateUserList()
    2. 'The User List Schema information requires this magic number. For anyone
    3. 'who may be interested, this number is called a GUID or Globally Unique
    4. 'Identifier - sorry for digressing
    5. Const conUsers = "{947bb102-5d43-11d1-bdbf-00c04fb92675}"
    6.  
    7. Dim cnn As ADODB.Connection, fld As ADODB.Field, strUser As String
    8. Dim rst As ADODB.Recordset, intUser As Integer, varValue As Variant
    9.  
    10. Set cnn = CurrentProject.Connection
    11. Set rst = cnn.OpenSchema(Schema:=adSchemaProviderSpecific, SchemaID:=conUsers)
    12.  
    13. 'Set List Box Heading
    14. strUser = "Computer;UserName;Connected?;Suspect?"
    15.  
    16. With rst    'fills Recordset (rst) with User List data
    17.   Do Until .EOF
    18.     intUser = intUser + 1
    19.       For Each fld In .Fields
    20.         varValue = fld.Value
    21.           'Some of the return values are Null-Terminated Strings, if
    22.           'so strip them off
    23.           If InStr(varValue, vbNullChar) > 0 Then
    24.             varValue = Left(varValue, InStr(varValue, vbNullChar) - 1)
    25.           End If
    26.           strUser = strUser & ";" & varValue
    27.       Next
    28.         .MoveNext
    29.   Loop
    30. End With
    31.  
    32. Me!txtTotalNumOfUsers = intUser        'Total # of Users
    33.  
    34. 'Set up List Box Parameters
    35. Me!lstUsers.ColumnCount = 4
    36. Me!lstUsers.RowSourceType = "Value List"
    37. Me!lstUsers.ColumnHeads = False
    38.   lstUsers.RowSource = strUser       'populate the List Box
    39.  
    40. 'Routine cleanup chores
    41. Set fld = Nothing
    42. Set rst = Nothing
    43. Set cnn = Nothing
    44. End Sub
  3. Create a List Box on this Form and name it lstUsers. Set no properties for this List Box, they will be set programmaticall y. It's Name, however, must be lstUsers.
  4. Create a Text Box on the Form and name it txtTotalNumOfUs ers.
  5. Set the Form's Timer Interval to 10000 (10 seconds). This can be readjusted later if you so desire.
  6. Place the following code in the Form's Timer() Event:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_Timer()
    2.   Call GenerateUserList
    3. End Sub
    4.  
  7. Place the following code in the Form's Open() Event:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_Open(Cancel As Integer)
    2.   Call GenerateUserList
    3. End Sub
  8. When you initially Open the Form the List Box will be populate with all the Users currently logged on to the Database and this List will be Refreshed every 10 seconds (Timer Interval = 10000 / Timer() Event call to GenerateUserLis t).
  9. If you have any further questions whatsoever on anything that I have outlined, please feel free to ask.
Nov 3 '07 #5
cford31
1 New Member
I was having trouble implementing this on my front end but then I figured it out! It has to be on the back end for this to work.

Thanks,
Chris
Dec 6 '07 #6
Randoz
27 New Member
This works great, thanks. But, why are all the UserNames "Admin"?
Dec 20 '07 #7
ADezii
8,834 Recognized Expert Expert
This works great, thanks. But, why are all the UserNames "Admin"?
If you do not have a Security System in place all Users are defined as Admin with no Password. I'm assuming that this is your case.
Dec 20 '07 #8
Randoz
27 New Member
If you do not have a Security System in place all Users are defined as Admin with no Password. I'm assuming that this is your case.
Yes, that is the case, thanks for the help. At least I can get the computer name.
Dec 21 '07 #9
patjones
931 Recognized Expert Contributor
This works great, except that in addition to getting "Admin" for all the UserNames, I get something like "C05-4235" under Computer.

We use Novell NetWare Services to log in to our computers. Is there anyway that I can get it to display the Novell user name in the list box?

Thanks!
Feb 14 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

5
6963
by: glin | last post by:
Hi there, does anyone know how to use smarty to generate a selection list without PHP assigning a array? eg. a list for selection minutes, but without php to assign a 1~60 array into smarty. Thanks in advance.
1
2926
by: The Blob | last post by:
Hi all, I have a problem trying to generate the u/m list of customer. I am trying to generate a list of customer whoes last commence date is jan 04 to current. It is part of a billing system which the customer come in and pay for their season parking in carpark. They can pay for various period shortest being 1 week.
2
1810
by: one | last post by:
greetings i am just wondering if some expert here can either show me how to do this or point me to the right direction (url... i want to use c# to generate a list of alphabet e.g A B C ... AA AB AC AD ... AAB ... ZZZZY ... ZZZZ any suggestion will be greatly appreciated thank you
2
4018
by: Joe User | last post by:
QUESTION for the experts out there :) Is it possible to write a query that would list the datafields by each table in a database? How would I do that?!?! TIA Joe
6
1718
by: Dustin Wilson | last post by:
I'm looking for a way with Visual Basic to generate a list of all the forms, reports and modules within a database. I can currently generate a list of tables and queries with the following code snipets see below. Anyone know a simple way to do this? Thanks Dustin Wilson Dim tbl As TableDef
12
14610
by: one | last post by:
greetings i am just wondering if some expert here can either show me how to do this or point me to the right direction (url... i want to use c# to generate a list of alphabet e.g A B C ... AA AB AC AD ... AAB ... ZZZZY ... ZZZZ any suggestion will be greatly appreciated thank you
2
1216
by: Kim Bach Petersen | last post by:
Is it possible to generate a list of classes within a namespace? Fx as a function of the name of the namespace, returning an array or the like: Function GetClasses(strNamespace As String) As Arraylist ... End Function
8
3571
by: dohyohdohyoh | last post by:
I have a programming question to generate an ordered list of alphanumeric strings of length 4. two alphabets rest numberst, etc. EG 0000-9999 then A000-Z999 then AA00 to ZZ99 then AAA0 - ZZZ9 then AAAA - ZZZZ
10
1774
by: =?utf-8?B?5Lq66KiA6JC95pel5piv5aSp5rav77yM5pyb5p6B | last post by:
Is there a simple function to generate a list like ? The range() just can generate the numeric list.
0
8652
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8983
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8940
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6575
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5907
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4412
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3107
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2402
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.