Users and Groups

  • Thread starter Thread starter BrettsNEWS
  • Start date Start date
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.
 
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
 
Hi, OK thanks for that, it looks like the very thing I need. I'll try and
work out how it works and paste it in.

Get the point about assigning forms to particular groups, can't quite
remember why I don't want to do that in this particular case, I think it's
because it's something that one must be able to do and I've got lost down
the trail of "Why am I writing that bit of code anyway!!!"

Best Regards
Brett.
 
Ah, (Second reply to this question.

I remember now, the reason I wanted it was to remove buttons on my main menu
when certain Groups logged on.

So that for instance, if a Captain Logged on, the fuel calculations button
doesn't appear, but if Engineers Log on then it does.

Thanks again

Brett.
 
BrettsNEWS said:
Ah, (Second reply to this question.

I remember now, the reason I wanted it was to remove buttons on my main menu
when certain Groups logged on.

So that for instance, if a Captain Logged on, the fuel calculations button
doesn't appear, but if Engineers Log on then it does.

Thanks again

Brett.

The above is just fine. However, just remember to ALWAYS drive all security
rights by member ship in a group..never attached a form to an actual
individual. If you following this simple advice..THEN NO USERS PERMISSIONS
will exist in the database..but ONLY exists in the shared workgroup file.
This approach this means you are free to send your clients new updates to
their software...but NOT loose any current security settings the
client/users may have set...
 
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
 
Back
Top