Solved

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

Posted on 2011-09-23
5
227 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

708 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

15 Experts available now in Live!

Get 1:1 Help Now