Solved

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

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do you delete the header in a text file with VBA 5 30
Insert Into syntax error 10 28
Access 2010 change CurrentUser 5 32
Problem with vba code 4 37
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

790 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