Catch the ability to NOT edit a form..suggestons?

  • Thread starter Thread starter Albert D. Kallal
  • Start date Start date
A

Albert D. Kallal

I have a form, and of course I am using security to restrict some users to
edit the data (they can view..but not edit).

Of course, if these "read only" users try and edit a text box on this form,
ms-access simply goes "beep" for each keypress.

If you hit keys a few times..it sounds like the cute little Road
Runner....beep beep..!

Anyone have a suggestion on how trap the fact that the user can't edit the
form? I would like to show/display a user friendly message when they try
and edit something....
 
Dear Albert:

I'm feel a bit silly offering *you* a suggestion, Albert, but could you pop
up a messagebox in the "OnActivate" event of the form, to remind the user
that it is an edit only form? I realize this isn't quite what you are asking
for, since it isn't tied to a control event...

Also, I have a "read-only" form, and I indicate this by using a "grayed-out"
looking font, rather than the standard "black" font. Users are used to the
concept that a "grayed-out" menu item isn't actually usable...

HTH
Fred Boer
 
Could you determine this by checking if CurrentUser() belongs to anyof the
groups that do have write permissions?

Function IsUserInGroup(strUser As String, strGroup As String) As Boolean
'Returns True if the user is in the group.
'Example: IsUserInGroup(CurrentUser(), "Admins")
Dim wk As Workspace
Dim grx As Groups
Dim grp As Group
Dim usx As Users
Dim usr As User

Set grx = DBEngine(0).Groups
For Each grp In grx
If grp.Name = strGroup Then
Set usx = grp.Users
For Each usr In usx
If usr.Name = strUser Then
IsUserInGroup = True
Exit For
End If
Next
End If
Next

Set usr = Nothing
Set usx = Nothing
Set grp = Nothing
Set grx = Nothing
End Function
 
Albert D. Kallal said:
I have a form, and of course I am using security to restrict some
users to edit the data (they can view..but not edit).

Of course, if these "read only" users try and edit a text box on this
form, ms-access simply goes "beep" for each keypress.

If you hit keys a few times..it sounds like the cute little Road
Runner....beep beep..!

Anyone have a suggestion on how trap the fact that the user can't
edit the form? I would like to show/display a user friendly message
when they try and edit something....

The Security FAQ has a section on "How can I retrieve the 'most
restrictive' permissions for attached tables?" You may be able to adapt
that for your purpose, if it's not enough just to check whether the user
is in the "read only" group(s).
 
could you pop
up a messagebox in the "OnActivate" event of the form, to remind the user
that it is an edit only form?

Actually...your suggestion is not a bad idea at all. In fact, right now...it
likey will be what I wind up doing.

I Appreciate the suggestion.

I am using security to control the ability to edit. If a user tries to open
the form ...and does not have permissions, then it is easy to trap the
error. My typical code to open a form due to a button clicked on looks
like:

Private Sub cmdDataConfig_Click()

On Error GoTo gerror

If IsNull(Me.ID) = False Then
DoCmd.OpenForm "frmTourProfile", , , "id = " & Me.ID
End If

Exit Sub

gerror:

Call GlobalError

End Sub

So, the above code is quite simple. It opens up a form when a button is
clicked on. However, some users don't have permissions in security to
open/view the form. So, I simply trap the error that occurs when this
happens. If you look at the above..all my click code simply has a call to
GlobalError.

My global error code can handle a number of things..and one error is
permissions (or lack of) to open the form. However, here is a code snip of
this global error code that is in a standard module::

Public Sub GlobalError()

Dim strEmsg As String
' global error...
Select Case Err.Number

Case 2603

strEmsg = "You do not have permissions to view this form"

Case etc. etc. etc...

end select

MsgBox strEmsg, vbExclamation, AppName

End Sub

So, you can see, now all forms instantly give a nice user friendly message,
and very little code is needed to be added here. If a user does not have
rights to use the form..they get my friendly message.

To be honest....the fact that I am quite lazy makes me search for solutions
that requite the least effort on my part!!

I would love to add just a bit of code to each form..and then let security
and some errors do the rest of the work for me!!
 
Thanks for the suggestion.

I can code in behavior into the code, but I would prefer not having to. When
trying to open a form that a user don't have permissions causes a
error. Thus, it simply generates a error which I can trap. Thus, adding new
security groups (does not happen much) would not requite any code changes. I
have only 4 different security groups here...so not too bad. Also, I am
trying to avoid running a bunch of code on the forms "load" event to
enable, or disable controls. To be honest, having all controls grayed out
likely is the best solution from a UI point of view....but I don't want to
write that much code!!! ;-)

Anyway...some good food for thought here....I shall think a bit more, but as
we speak..I am going to use the IsInGroup Function.

Thanks again...
 
As I was replying to Allen's suggestions...an idea popped up...

I could also try and "edit" the reocrdset of the form, or even set the value
of a "lastEdit" field. This would cause a trap-able error due to lack of
edit ability.

Since there is so few security groups (4), then I can code this...but I will
take a look at the Security FAQ......

as always....thanks...
 
Back
Top