Users and Groups

B

BrettsNEWS

Hi, Can anyone help. (Access 2000)

I can detect the current user by

Person1 = CurrentUser
or If CurrentUser = "B Clark" Then etc etc.....


But how do I detect that a particular group is logged on?
i.e. if I have a group called Captain and I want Captains to be able to open
or not open a form, how do I detect that that group is one of the active
groups?
Bearing in mind that a particular Captain may be in a few groups and
therefore more than one group is active.

Thanks in anticipation
Brett.
 
A

Albert D. Kallal

Well of course you assign the forms to particular users groups, and then you
don't need any code...right?

Thus, you don't need to check if a user can open a form...simply don't give
certain groups access to those forms you don't want groups to use.

(you will save tons of code..and that is the whole idea of security anyway).

However, often things like deleting invoice, or certain other functions in
code do have to check for member ships in a particular group (you can't
really effectively secure code that runs to a particular group!).
..

So, for example to prevent users from deleting details in a invoice....I
will use something like this in the beforedelconfirm:

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

the general code module I use for IsInGroup is:

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

Albert D. Kallal

BrettsNEWS said:
Ah, got a problem with


VBA 6.3 doesn't like it, it says User defined type not defined.

Any ideas?

Brett.

You need a ref to dao 3.6 libary
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top