Display Users Currently In Database?

missnhanley

New Member
Joined
Aug 17, 2005
Messages
37
I was wondering if any of you could advise a way to determine the users that are currently in a database?
When I need to make changes I need the database to have no users within it but determining who they are can be difficult as it the database is used building wide.

Any methods/solutions are appreciated.

Thanks,
Nicola
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Nicola

When a database is in use there is a file with the name of the database
and the extension .ldb open in the database's directory.

Perhaps you could look for/at that to determine if the database is in use.
 
Upvote 0
Thanks for your reply Norie,

I am looking to determine specific users i.e. exactly who is in the database as having to email everyone who could possibly use the database is not possible as this option is open ended and it could be more than one person.

I don't know if it's possible but though I'd ask nonetheless!

Thanks,
Nicola
 
Upvote 0
Nicola

Well like I said this ldb file will list everybody in the database.

You could look for it, if it exists you could parse it to determine who is
using the database and email as necessary.

Exactly how to do this would depend on your setup. Are you on a network?

By the way what changes will you be making to the database?
 
Upvote 0
This is some ancient Access 2.0 code which you can try. I expect that it still works; play with it in the VBE. If it doesn't have the magic function, it should brush closely. Unfortunately, I need to leave, but VBA experts here ought to pitch in on this.
Code:
Function GetSecurity()
On Error GoTo GetSecurity_Err
    Dim MyUser As User, MyGroup As Group
    Dim i As Integer, j As Integer

    Rem Following is code culled from Access 2.0 help.  It inanely creates
    Rem and then deletes a fictitious user and group, but serves the purpose
    Rem of effectively providing program visibility to MyUser.Groups(j).Name

    Rem Full code is from "example" link from Users Object, Users Collection:
    Rem "Group Object, Groups Collection; User Object, Users Collection Example"

    ' Create and append new user.
    Set NewWorkspace = DBEngine.Workspaces(0)
    Set MyUser = NewWorkspace.CreateUser("tempName", "abcd", "tmpPass")
    NewWorkspace.Users.Append MyUser
    ' Create and append new group.
    Set MyGroup = NewWorkspace.CreateGroup("tmpGroup", "tmpPassG")
    NewWorkspace.Groups.Append MyGroup
    ' Add new user to new group
    Set MyUser = NewWorkspace.CreateUser("tempName")
    NewWorkspace.Groups![tmpGroup].Users.Append MyUser
    'blow them away, because now we can see MyUser.Groups(j).Name
    NewWorkspace.Users.Delete "tempName"
    NewWorkspace.Groups.Delete "tmpGroup"

    For i = 0 To NewWorkspace.Users.Count - 1
        Set MyUser = NewWorkspace.Users(i)
        For j = 0 To MyUser.Groups.Count - 1
            If MyUser.Groups(j).Name <> "Users" And MyUser.Groups(j).Name <> "Guests" Then
                MsgBox (MyUser.Name)
            End If
        Next j
     Next i
GetSecurity_Exit:
    NewWorkspace.Close
Exit Function

GetSecurity_Err:
    MsgBox "Error: " + Error$
    'Resume Next 'developmental plug
    Resume GetSecurity_Exit
End Function

'don't forget to clean everything up - e.g. "= Nothing"
 
Upvote 0
I am trying to see if a database is in use or not, but only have Access 97 so the links posted by C T Witter are no use. I like Norie's suggestion of lookng for the .ldb file. This works fine when the access database is read-write, and I have implemented this idea.
However, I have several databases that are in a read-only folder (with me being the only read-write person). In this case the .ldb file is only created when I connect to the database: for others there is no file created.
Whilst the code I provide connects them to the database in read-only mode, I still get occasional errors if more than one user is reading the data at the same time. I would like to see if the database is being read, and if so, put a loop in the code that waits until it is not, thus avoiding simultaneous access by >1 person. Any ideas how to accomplish this with a read-only databse?
 
Upvote 0
How about creating your _own_ lock file - call it a "flag file" - at the start of the critical code, and deleting it as soon afterwards as possible.
 
Upvote 0
Thanks for reply GIA. I had posted this also on the Excel site and the same suggestion was made. I have now implemented exactly that -
- check to see if table is empty just before connection to DB
- if not, loop until it is empty
- if empty, write username to table and connect to DB
- when disconnect from DB, delete username from table

This works a treat. Thanks very much for your input
 
Upvote 0
Just some stuff to mentally munch on:

Of course, the table could contain names of people that ab-ended ... or (sigh) went home 4 hours ago ...

I'm just saying, you might keep a back-door override for that - for example, if you're not around, let their supervisors have a password. Maybe its functionality would be to force the database closed and clear the table...
 
Upvote 0

Forum statistics

Threads
1,215,014
Messages
6,122,697
Members
449,092
Latest member
snoom82

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top