command button to open form if user has permission

J

johnlute

I have a command button that closes its form and opens another (see
below). Is it possible to code the button to open the desired form
only if the user has write permissions?

Private Sub EditIDs_Click()
On Error GoTo Err_Exit_Click

DoCmd.Close
DoCmd.OpenForm "KEYSTONEeditids"

Exit_Click:
Exit Sub

Err_Exit_Click:
MsgBox Err.Description
Resume Exit_Click

End Sub

Thanks for your help!
 
D

Dirk Goldgar

johnlute said:
I have a command button that closes its form and opens another (see
below). Is it possible to code the button to open the desired form
only if the user has write permissions?

Private Sub EditIDs_Click()
On Error GoTo Err_Exit_Click

DoCmd.Close
DoCmd.OpenForm "KEYSTONEeditids"

Exit_Click:
Exit Sub

Err_Exit_Click:
MsgBox Err.Description
Resume Exit_Click

End Sub

Thanks for your help!


Write permissions on what, John? And are you talking about permissions
granted by workgroup (user-level) security, or Windows permissions?
 
J

johnlute

Hi, Dirk!
Write permissions on what, John?  And are you talking about permissions
granted by workgroup (user-level) security, or Windows permissions?

Permissions granted by workgroup.

I'm trying to limit what users can access. I've modified my main menu
for full permissions users (KEYSTONEeditids) and created another menu
for read-only users (KEYSTONEqryrpt). The database opens to the
KEYSTONEqryrpt form which has the comand button to close it and open
the KEYSTONEeditids form.
 
D

Dirk Goldgar

johnlute said:
Permissions granted by workgroup.

I'm trying to limit what users can access. I've modified my main menu for
full permissions users (KEYSTONEeditids) and created another menu for
read-only users (KEYSTONEqryrpt). The database opens to the KEYSTONEqryrpt
form which has the comand button to close it and open the KEYSTONEeditids
form.


One can check whether the user has permissions on a particular object, but
what I have done in the past is just check to see if the current user is a
member of a particular security group. To that end, I wrote this function:

'------ start of code ------
Function fncUserIsInGroup(GroupName As String) As Boolean

' Returns True if the current user is a member of the specified
' security group; False if not, or if the group doesn't exist, or
' if an error occurs reading the groups.

Dim ws As Workspace

Set ws = DBEngine.Workspaces(0)

On Error Resume Next
fncUserIsInGroup = _
(ws.Users(CurrentUser).Groups(GroupName).Name = GroupName)

Set ws = Nothing

End Function
'------ end of code ------

So, to see if the current user is a member of the group named "Read-Only
Users", you might write:

If fncUserIsInGroup("Read-Only Users") Then
' this is a read-only user
Else
' this user has write permissions.
End If

That's assuming that you assign permissions by group, not by individual
user, and also (for this example) that you have only one read-only group of
users. If you have more than one group of read-only users, you'd need to
check each group.

Does that get you where you want to go, John?
 
J

johnlute

Thanks, Dirk!

How cool is that! A very elegant and SIMPLE solution! I plugged it in
and BINGO! Is my MsgBox sufficiently polite? I don't want to offend
those "loely" read-only users. :)

THANKS!!!

Private Sub EditIDs_Click()
On Error GoTo Err_Exit_Click

If fncUserIsInGroup("Read-Only Users") Then
' this is a read-only user
Beep
MsgBox "Sorry! You don't have permission to edit ID's!"
Else
' this user has write permissions.
DoCmd.Close
DoCmd.OpenForm "KEYSTONEeditids"
End If

Exit_Click:
Exit Sub

Err_Exit_Click:
MsgBox Err.Description
Resume Exit_Click
 
D

Dirk Goldgar

johnlute said:
How cool is that! A very elegant and SIMPLE solution! I plugged it in and
BINGO!

Excellent! I'm almost disappointed.
Is my MsgBox sufficiently polite? I don't want to offend those "loely"
read-only users. :)

You could always display "Bad user! Bad! No biscuit!".

I suggest, on general principles, that you make your DoCmd.Close statement
more specific. To close the current form, instead of:
DoCmd.Close

.... I recommend this:

DoCmd.Close acForm, Me.Name, acSaveNo

That way you ensure that the right object gets closed in all circumstances,
and the user won't get any prompt about saving design changes.
 
J

johnlute

Dirk -
Excellent!  I'm almost disappointed.

Nothing worse than a challenge that isn't as challenging as one would
hope.
I suggest, on general principles, that you make your DoCmd.Close statement
more specific.  To close the current form, instead of:


... I recommend this:

        DoCmd.Close acForm, Me.Name, acSaveNo

That way you ensure that the right object gets closed in all circumstances,
and the user won't get any prompt about saving design changes.

I thought about that but the only open form *should* be the one being
closed. On second thought I'll need to run through this to make sure
about that now.
 
J

johnlute

You could always display "Bad user!  Bad!  No biscuit!".

That would be downright cruel :)
 

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