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()
EnableProperties()
DisableProperties()
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:
I have also tried the following code:
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
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
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
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
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