form tab visibility based on security group

B

B. Meincke

I have a secured database with a switchboard with three tabs. The third tab
is named Administration. I understand how to use the User and Group
Permissions dialogue box to limit which groups have what access to what whole
objects, but how can I code the switchboard form so that the third tab is
visible if the user logging on is in the admin group but not if they are in
any of the other security groups?

Thank you in advance for any suggestions.
 
G

Graham Mandeno

The following function will test if a given user is in a given group:

Public Function IsUserInGroup(sGroup As String, _
Optional ByVal sUser As String) As Boolean
Dim grp As Group
On Error Resume Next
If Len(sUser) = 0 Then sUser = CurrentUser
Set grp = DBEngine(0).Users(sUser).Groups(sGroup)
If Err Then
Err.Clear
Else
Set grp = Nothing
IsUserInGroup = True
End If
End Function

In your Form_Load procedure, you can show or hide the tab page as
appropriate:
tpgAdministration.Visible = IsUserInGroup( "MyAdmins" )

Remember that group membership is not mutually exclusive - a user can be in
several groups.
 
B

B. Meincke

Thank you for your reply Graham.

I'm afraid I must still be missing something, however.

I put the public function in the general declarations section for the form
and put the call to it in the load event...with the proper changes to reflect
my naming conventions, of course...and the tab on the switchboard remains
visible no matter who is logged into the database.

--
BJM
ACE Assistant
Gary Allan High School


Graham Mandeno said:
The following function will test if a given user is in a given group:

Public Function IsUserInGroup(sGroup As String, _
Optional ByVal sUser As String) As Boolean
Dim grp As Group
On Error Resume Next
If Len(sUser) = 0 Then sUser = CurrentUser
Set grp = DBEngine(0).Users(sUser).Groups(sGroup)
If Err Then
Err.Clear
Else
Set grp = Nothing
IsUserInGroup = True
End If
End Function

In your Form_Load procedure, you can show or hide the tab page as
appropriate:
tpgAdministration.Visible = IsUserInGroup( "MyAdmins" )

Remember that group membership is not mutually exclusive - a user can be in
several groups.
 
G

Graham Mandeno

Hi BJ

I would put the function in a standard module, so that you can call it from
anywhere in your app.

However, that is not what is causing the problem.

Are you sure the code is being executed? Try changing the line to:
tpgAdministration.Visible = False
to see if the tab page gets hidden.

You could also try:
tpgAdministration.Visible = IsUserInGroup( "nonexistent group" )
This should ALWAYS hide the page, while:
tpgAdministration.Visible = IsUserInGroup( "Users" )
should always show it.
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

B. Meincke said:
Thank you for your reply Graham.

I'm afraid I must still be missing something, however.

I put the public function in the general declarations section for the form
and put the call to it in the load event...with the proper changes to
reflect
my naming conventions, of course...and the tab on the switchboard remains
visible no matter who is logged into the database.

--
BJM
ACE Assistant
Gary Allan High School


Graham Mandeno said:
The following function will test if a given user is in a given group:

Public Function IsUserInGroup(sGroup As String, _
Optional ByVal sUser As String) As Boolean
Dim grp As Group
On Error Resume Next
If Len(sUser) = 0 Then sUser = CurrentUser
Set grp = DBEngine(0).Users(sUser).Groups(sGroup)
If Err Then
Err.Clear
Else
Set grp = Nothing
IsUserInGroup = True
End If
End Function

In your Form_Load procedure, you can show or hide the tab page as
appropriate:
tpgAdministration.Visible = IsUserInGroup( "MyAdmins" )

Remember that group membership is not mutually exclusive - a user can be
in
several groups.
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

B. Meincke said:
I have a secured database with a switchboard with three tabs. The third
tab
is named Administration. I understand how to use the User and Group
Permissions dialogue box to limit which groups have what access to what
whole
objects, but how can I code the switchboard form so that the third tab
is
visible if the user logging on is in the admin group but not if they
are
in
any of the other security groups?

Thank you in advance for any suggestions.
 
B

B. Meincke

Again, Graham,
Thank you for your help. I will put your suggestions to the test in the
morning.
--
BJM
ACE Assistant
Gary Allan High School


Graham Mandeno said:
Hi BJ

I would put the function in a standard module, so that you can call it from
anywhere in your app.

However, that is not what is causing the problem.

Are you sure the code is being executed? Try changing the line to:
tpgAdministration.Visible = False
to see if the tab page gets hidden.

You could also try:
tpgAdministration.Visible = IsUserInGroup( "nonexistent group" )
This should ALWAYS hide the page, while:
tpgAdministration.Visible = IsUserInGroup( "Users" )
should always show it.
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

B. Meincke said:
Thank you for your reply Graham.

I'm afraid I must still be missing something, however.

I put the public function in the general declarations section for the form
and put the call to it in the load event...with the proper changes to
reflect
my naming conventions, of course...and the tab on the switchboard remains
visible no matter who is logged into the database.

--
BJM
ACE Assistant
Gary Allan High School


Graham Mandeno said:
The following function will test if a given user is in a given group:

Public Function IsUserInGroup(sGroup As String, _
Optional ByVal sUser As String) As Boolean
Dim grp As Group
On Error Resume Next
If Len(sUser) = 0 Then sUser = CurrentUser
Set grp = DBEngine(0).Users(sUser).Groups(sGroup)
If Err Then
Err.Clear
Else
Set grp = Nothing
IsUserInGroup = True
End If
End Function

In your Form_Load procedure, you can show or hide the tab page as
appropriate:
tpgAdministration.Visible = IsUserInGroup( "MyAdmins" )

Remember that group membership is not mutually exclusive - a user can be
in
several groups.
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

I have a secured database with a switchboard with three tabs. The third
tab
is named Administration. I understand how to use the User and Group
Permissions dialogue box to limit which groups have what access to what
whole
objects, but how can I code the switchboard form so that the third tab
is
visible if the user logging on is in the admin group but not if they
are
in
any of the other security groups?

Thank you in advance for any suggestions.
 

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