Solved

How do I set edit permissions on a form without opening it?

Posted on 2011-09-23
5
238 Views
Last Modified: 2012-08-13
Hi all,

I am trying to implement a user-level type edit restrictions on a (test) form.  I have got it working but only when the form is already open. If it is closed when I log in, it can't find the form to set the properties.

Any ideas as to a better way of doing it?

Thanks in advance...
0
Comment
Question by:JohnSaint
  • 3
  • 2
5 Comments
 
LVL 57
ID: 36587843
<<I am trying to implement a user-level type edit restrictions on a (test) form. >>

  in what way?

<<Any ideas as to a better way of doing it? >>

  Do it in the forms OnOpen event, which is cancelable.  However you will need to do a Me.Repaint to ensure that all the controls are created if your controlling security on those as well. Normally, they are not available until the OnLoad event, but that event is not cancelable.

Jim.

0
 

Author Comment

by:JohnSaint
ID: 36587996
Hi Jim,

At the moment I am just doing it through a simple log-on form. That side of things I will deveop later but if you have any great ideas on that front then I'm all ears. Will set you with a separate question if that's what it takes.

I am not planning to apply security to indiviual controls. I'll just set the allowedits, additions etc to false if they are a 'View only' user. I was planning on doing a blanket sweep across all the forms setting the permissions but I guess doing it if and when the form opens is a better way. I could just set up a public proc (or whatever) and send the form name to it on open.

Whatever level my users are they will have access to all forms. Some will have full edit permision, some will only be able to view so I should never have to lock a user out of the form completely.

Am i heading in the right direction?
0
 

Author Comment

by:JohnSaint
ID: 36588042
And this doesn't work...

    Fname = "FrmAllAccess"
   
    Forms!Fname.AllowAdditions = True

How do I pass a form name in this case?
0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 36588292
<<I'll just set the allowedits, additions etc to false if they are a 'View only' user. I was planning on doing a blanket sweep across all the forms setting the permissions but I guess doing it if and when the form opens is a better way.>>

 You'll be better off to do it when the form opens.  There are any number of ways to structure that.  I have a tendency to try and keep things centralized, so I would do one routine:

Sub SetFormPermissions(frm as Form)

   If <some check> = True then
     frm.AllowAdditions = True
     frm.AllowEdits = True
     frm.AllowDeletions = True
Else
     frm.AllowAdditions = False
     frm.AllowEdits = False
     frm.AllowDeletions = False
End If

End Sub

  Call would be:

   SetFormPermissions([Form])

  you might also want to pass as a string:


Sub SetFormPermissions(strFormName as String)

   If <some check> = True then
     Forms(strFormName).AllowAdditions = True
     Forms(strFormName).AllowEdits = True
     Forms(strFormName).AllowDeletions = True
Else
     Forms(strFormName).AllowAdditions = False
     Forms(strFormName).AllowEdits = False
     Forms(strFormName).AllowDeletions = False
End If

  Call would be:

   SetFormPermissions("myForm")

 it could also be done like this:

Sub SetFormPermissions(strFormName as String)
  Dim frm as Form

  Set frm = Forms(strFormName)

   If <some check> = True then
     frm.AllowAdditions = True
     frm.AllowEdits = True
     frm.AllowDeletions = True
Else
     frm.AllowAdditions = False
     frm.AllowEdits = False
     frm.AllowDeletions = False
End If

   set frm = nothing

End Sub

Or a little more concise:

Sub SetFormPermissions(strFormName as String)
  Dim frm as Form

  Set frm = Forms(strFormName)

  With frm

   If <some check> = True then
     .AllowAdditions = True
     .AllowEdits = True
     .AllowDeletions = True
Else
     .AllowAdditions = False
     .AllowEdits = False
     .AllowDeletions = False
End If

  End With

   set frm = nothing

End Sub


   
0
 

Author Closing Comment

by:JohnSaint
ID: 36598791
Cheers Fella. Great work...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now