What type of user is connected

  • Thread starter Thread starter 3ddy
  • Start date Start date
3

3ddy

What type of user is connected


I am looking for the code in MS-Access 2000 or 2002 that
would allow me to find out what type of user just logged
on.

Example
I have admins
users
verifiers
all created via the security wizard.

Once they log in I would like to find out (with code) what
usergroup or user just logged on and do something from
there.

Any help would be greatly appreciated.
 
You can the name of the currently logged on user with:

currentUser()


I then use the following function often to check if the user is a member of
a particular group:


If (IsInGroup(CurrentUser(), "InvDelete") = False) _
And (IsInGroup(CurrentUser(), "Admins") = False) Then
Beep
MsgBox "You cannot delete payments", vbCritical, "Payments can not be
deleted"
Cancel = True
End If

In above example, I have a group called "InvDelete", and only users who are
a member of this group can delete invoice payments. If you look closely, I
also allow ALL members of the Admins group to delete payments. That above
code is actually in the before del confirm of the forms event.

The code fort "InIGroup" is reproduced below.


--
Albert D. Kallal (MVP)
Edmonton, Alberta Canada
(e-mail address removed)
http://www.attcanada.net/~kallal.msn

Public Function IsInGroup(UsrName As String, GrpName As String) As Boolean
'Determines whether UsrName is a member of GrpName

Dim grp As Group
Dim IIG As Boolean
Dim usr As user

IIG = False

For Each usr In DBEngine.Workspaces(0).Users
If usr.Name = UsrName Then GoTo FoundUser
Next

GoTo IIG_Exit

FoundUser:
For Each grp In usr.Groups
If grp.Name = GrpName Then IIG = True
Next

IIG_Exit:
IsInGroup = IIG


End Function
 
A user can be a member of many groups - not just one.

This code says what groups the current user is a member of.

(untested)

dim g as group
for each g in dbengine(0).users(currentuser).groups
msgbox g.name
next

HTH,
TC
 
Albert, I ran your code and I keep getting a Runtime
error '13' - Type mismatch on this line

For Each usr In DBEngine.Workspaces(0).Users


Any ideas?



-----Original Message-----
You can the name of the currently logged on user with:

currentUser()


I then use the following function often to check if the user is a member of
a particular group:


If (IsInGroup(CurrentUser(), "InvDelete") = False) _
And (IsInGroup(CurrentUser(), "Admins") = False) Then
Beep
MsgBox "You cannot delete payments",
vbCritical, "Payments can not be
 
Back
Top