?
Solved

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

Posted on 2011-09-23
5
Medium Priority
?
284 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 58
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 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 2000 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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
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…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

809 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