Can't Disable Menu Properties in Access 2010 Without Multiple Logins

andigirlsc

Registered User.
Local time
Today, 17:47
Joined
Jun 4, 2014
Messages
59
Details:
I found some code for the main menu of my form online through a post on this very forum that allows me to disable almost all menu properties/bypass keys, etc. in Access. Here is the link:
iaccessworld . com / how-to-disable-properties

I have included the code below. There are three modules (1) SetProperties, (2) EnableProperties and (3) DisableProperties. When I call DisableProperties, it works, but not right away. When I call EnableProperties, it works also, but not right away.

Problem:
Once I call the DisableProperties function, VBA will disable almost everything in my function, but still shows the navigation menu. After I log in and out a few more times with the same privileges, then all menus are disabled except privacy options and printing. I would like the Privacy options disabled as well. I'm not sure what code will allow for this.

VBA also ignores the code that calls the EnableProperties function until I have logged back in and out a couple of times...just like with the DisableProperties function. I have not been able to find exactly what I need in the way of a solution.

Question:
How do I get my VBA code to immediately disable/enable all menu properties as soon as the form loads if a condition is met? Any help would be greatly appreciated!

SetProperties()
Code:
Public Function SetProperties(PropName As String, PropType As Variant, PropValue As Variant) As Integer
On Error GoTo Err_SetProperties
   Dim db As Database, prop As Property
   'Dim db As DAO.Database, prop As DAO.Property (use in the old version prior 2007)
   Set db = CurrentDb
   db.Properties(PropName) = PropValue
   SetProperties = True
   Set db = Nothing
Exit_SetProperties:
Exit Function
Err_SetProperties:
   If Err = 3270 Then 'case of property not found
       Set prop = db.CreateProperty(PropName, PropType, PropValue)
       db.Properties.Append prop
       Resume Next
   Else
       SetProperties = False
       MsgBox "Runtime Error # " & Err.Number & vbCrLf & vbLf & Err.Description
       Resume Exit_SetProperties
   End If
End Function
EnableProperties()
Code:
Public Function EnableProperties()
On Error GoTo ErrorHandler:
DoCmd.ShowToolbar "Ribbon", acToolbarYes
'Set all properties listed below back to normal by setting value to True
'Show Database window
SetProperties "StartUpShowDBWindow", dbBoolean, True
SetProperties "StartUpShowStatusBar", dbBoolean, True
'show Access Full Menus.
SetProperties "AllowFullMenus", dbBoolean, True
'enable F11, ALT F11, etc. for short key
SetProperties "AllowSpecialKeys", dbBoolean, True
'Shift Key Override on loading
SetProperties "AllowBypassKey", dbBoolean, True
'allow Access Shortcut Menus. May be too severe
SetProperties "AllowShortcutMenus", dbBoolean, True
SetProperties "AllowToolbarChanges", dbBoolean, True
SetProperties "AllowBreakIntoCode", dbBoolean, True
Exit Function
ErrorHandler:
MsgBox Err.Description
Exit Function
End Function
DisableProperties()
Code:
Public Function DisableProperties()
On Error GoTo TheError
 DoCmd.ShowToolbar "Ribbon", acToolbarNo
 'Disable properties listed below by setting the property value to False
SetProperties "StartUpShowDBWindow", dbBoolean, False
SetProperties "StartUpShowStatusBar", dbBoolean, False
SetProperties "AllowFullMenus", dbBoolean, False
SetProperties "AllowSpecialKeys", dbBoolean, False
SetProperties "AllowBypassKey", dbBoolean, False
SetProperties "AllowShortcutMenus", dbBoolean, False
SetProperties "AllowToolbarChanges", dbBoolean, False
SetProperties "AllowBreakIntoCode", dbBoolean, False
 Exit Function
TheError:
MsgBox Err.Description
Exit Function
 End Function
This code is on the main menu of my form. The main menu appears after a user has logged in so that the AccessID is set. The AccessID is used in the IF/THEN statement to determine if EnableProperties is called or if DisableProperties is called. Here is what I am using to call the DisableProperties and EnableProperties functions:
Code:
 Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open
     
    If User.AccessID = 1 Then
        Call EnableProperties
     Else
        Call DisableProperties
    End If
    
Exit_Form_Open:
    Exit Sub
 Err_Form_Open:
    MsgBox Err.Description
    Me.Visible = True
    Resume Exit_Form_Open
          
End Sub
I have also tried the following code:
Code:
 Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open
     
    If User.AccessID <> 1 Then
        Call DisableProperties
     Else
        Call EnableProperties
    End If
    
Exit_Form_Open:
    Exit Sub
 Err_Form_Open:
    MsgBox Err.Description
    Me.Visible = True
    Resume Exit_Form_Open
          
End Sub
 
Try putting it in the On_Load event of the first Form that opens.
 
Thanks, but that doesn't fix the problem. I did try it, but that made it worse. Now I can't get back into the program to make changes at all because the condition I set for the login type isn't met before the function is called. Fortunately, I made a backup of the file before I moved the code into the On Load Event of the first form.

Any other ideas are greatly appreciated!
 
Last edited:
Hmm, where does...

Code:
User.AccessID <> 1
...come from?
 
The following code:
Code:
User.AccessID <> 1
is the test that I want to run for each user that logs into the database. If the user's AcessID is not equal to 1 (i.e. not an administrator) then VBA should call DisableProperties. If the User's AccessID is equal to 1, then VBA should call EnableProperties.
 
Hmm, I see I didn't phrase that question properly.

Can I assume then that AccessID is on the Form? And what is User? a Table? I see nothing that tells Access where to find the AccessID, that is what I am getting at.
 
Hmm, I see I didn't phrase that question properly.

Can I assume then that AccessID is on the Form? And what is User? a Table? I see nothing that tells Access where to find the AccessID, that is what I am getting at.

To be honest, I borrowed this code from another post on this forum and tweaked it for my needs. I changed the names of tables and updated the code to match. I don't know what User is, but
Code:
User.AccessID = 1
works for controlling access to one of the other buttons on one of my forms, so I haven't changed it. AccessID is a field name that represents the level of access that a user has. I will try removing the
Code:
User.
portion and see what happens.
 
If, AccessID is on the Form then try...

Code:
Me.AccessID

Side note, you wouldn't to have the link to where you got the code? It would help to it in its original state.
 
I found where User is defined. Here is what I found in one of the modules of VBA code:
Code:
Public Type UserInfo
 
ViewID As Integer
AccessID As Integer
Active As Boolean
Password As String
UserID As String
SecurityID As String

End Type
[B]Public User As UserInfo[/B]
 
I tried Me.AccessID, but it doesn't work. Here is the link, but I do not have enough posts for it to be active. I copied the code exactly like it is listed on this link. I just chose not to the use the password protection offered because I have my own password management system for that.

Link:
iaccessworld . com / how-to-disable-properties /
 
Okay, put the User back I get it now. As for the opening and reopening issue, read the comments, looks like someone had the same issue and it was answered. The post also indicates this should go in the On_Load of the Form not the On-Open event.
 
I was the user that posted the question about Enable properties not working on that other site before I realized it would take several logins to make the function work. This problem was not solved in that thread most recent thread on
Link: iaccessworld . com / how-to-disable-properties /

What the response explained was how to re-enable the menus once they are disabled by commenting out the 'Call DisableProperties' code once a user is logged in with certain privileges. I'm still looking for a way to rewrite the DisableProperties code so that it doesn't require multiple logins.

If I use the code the way it is, anyone that logs in after me will have access to manipulate objects in the database if they log in after me (I'm the administrator). The only other solution I can think of is for me to have two logins myself. One as administrator and one as a regular user so that DisableProperties will be called and lock all the menus down before the next user attempts to login. I am trying to avoid this as it is inefficient.

Thank you for the time you have spent on this issue so far. Please let me know if you have any more ideas. Thanks!
 
Wait... are you sharing a Front end? That would explain why I don't have that problem using similar code. (Sorry, didn't notice that was you!)
 
I assume that you mean that the database is not split? If so, then yes I am sharing a Front End. I am not familiar with splitting databases and am not certain how that would affect my ability to develop the database further.
 
Also, I work in a non-IT department, so I'm not sure how that would affect where the "back end/front end" would be stored.
 
Then it is always going to be a problem with an unsplit database. Here are some links with information about spliting and updating Front ends...

http://www.kallal.ca/Articles/split/index.htm

http://allenbrowne.com/ser-01.html

http://www.utteraccess.com/wiki/index.php/Sharing


You may also want to take a look at MVP Tom Wickerath's article…

http://www.accessmvp.com:80/Twickerath/articles/multiuser.htm


To handle the update of multiple front ends see…

http://www.autofeupdater.com/
http://regina-whipp.com/blog/?p=184
http://www.btabdevelopment.com/ts/freetools


If each user needs Access you can install the Runtime…

Access 2010
http://www.microsoft.com/downloads/...cd-5250-4df6-bfd1-6ced700a6715&displaylang=en
 
Thank you for your help! I will look into this and see if it solves the problem.
 
After much research, I made a backup of the database and split it. Then I activated (uncommented) the code that calls for the Disable/Enable functions. I am still having to log in multiple times to see the menus lock and unlock. Thanks for the helpful articles, by the way.

Any new thoughts would be greatly appreciated!
 
Hmm, let's try this... put code to Disable Functions, unless AccessID = 1 on the On_Unload event of the Form.
 

Users who are viewing this thread

Back
Top Bottom