title: Accurate control of navigation and menus in Microsoft Access 2013 using VBA
body: <p>I've created an admin window in a security level driven MS Access database.  This admin tab is presented to the user when determined that their security is either 1, admin or 2, user. </p>
  
  <p>To cut to the chase, I've created a 'toggle button' (doesn't quite work the way I intended, but it does the trick - well sort of) It's in beta mode for me until I can understand the quirks.</p>
  
  <p>The toggle button says "Hide Menus" which pertains to the navigation, tables, queries... essentially everything that a user can do to accidentally get into the VBA, design, or queries and unravel anything.</p>
  
  <p>When the toggle button is clicked again, it restores all of the above.</p>
  
  <p>However, even though it works, I'm not certain what factors come into play because one setting happens immediately (The Ribbon) and then I don't see the other settings take place until I restart Access.</p>
  
  <p>Here's my code for the button:</p>
  
  <pre><code>Private Sub cmdToggleHide_Click()
      Select Case Me.cmdToggleHide.Caption
  
      Case "Show Menus"
          Call EnableSetProperty(True)
          Me.cmdToggleHide.Caption = "Hide Menus"
      Case "Hide Menus"
          Call EnableSetProperty(False)
          Me.cmdToggleHide.Caption = "Show Menus"
      End Select
  End Sub
  
  Public Function EnableSetProperty(bTrueFalse As Boolean)
  On Error GoTo ThisError
  
  'True means show all of access
  
  If bTrueFalse = True Then
       DoCmd.ShowToolbar "Ribbon", acToolbarYes
  
  
  Else
       DoCmd.ShowToolbar "Ribbon", acToolbarNo
  
  End If
  
      SetProperties "StartUpShowDBWindow", dbBoolean, bTrueFalse ' Display Database Window
      SetProperties "StartUpShowStatusBar", dbBoolean, bTrueFalse 'Status Bar
      SetProperties "AllowFullMenus", dbBoolean, bTrueFalse 'Access Full Menus
      SetProperties "AllowSpecialKeys", dbBoolean, bTrueFalse 'F11, ALT F11, etc.
      SetProperties "AllowBypassKey", dbBoolean, bTrueFalse 'Shift Key Override on loading
      SetProperties "AllowShortcutMenus", dbBoolean, bTrueFalse 'Access Shortcut Menus. May be too severe
      SetProperties "AllowToolbarChanges", dbBoolean, bTrueFalse 'Prevent Changes
      SetProperties "AllowBreakIntoCode", dbBoolean, bTrueFalse 'Code Access'
  
  Exit Function
  
  
  
  
  ThisError:
  
  MsgBox Err.Description
  
  Exit Function
  
  End Function
  
  
  
  Public Function SetProperties(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer
  
  On Error GoTo Err_SetProperties
  
  Dim db As Database, prop As Property
  Set db = CurrentDb
  db.Properties(strPropName) = varPropValue
  SetProperties = True
  
  Set db = Nothing
  
  Exit_SetProperties:
  
       Exit Function
  
  Err_SetProperties:
  
       If Err = 3270 Then 'Property not found'
  
           Set prop = db.CreateProperty(strPropName, varPropType, varPropValue)
           db.Properties.Append prop
           Resume Next
  
       Else
           SetProperties = False
           MsgBox "Runtime Error # " &amp; Err.Number &amp; vbCrLf &amp; vbLf &amp; Err.Description
           Resume Exit_SetProperties
  
       End If
  
  End Function
  </code></pre>
  
  <p>The first quirky thing that happens when I click the "Hide Menus" button (intending to 'arm' it or secure it) is that the ribbon up top disappears immediately.  And I wouldn't mind if this setting actually took, but for the rest of the settings to 'take' I have to close the database and re-open it again.  </p>
  
  <p>When I reopen it, now the navigation pain is hidden and forms cannot be 'right-clicked' to access 'Design View' and holding down 'Shift' does not by-pass the start-up. However, the ribbon is now back. I don't think I'm missing anything.  This isn't so bad, because what is accessible on the ribbon is pretty harmless.  But I wonder why it comes back.</p>
  
  <p>In order to Un-Arm the system, of course you have to be logged in as an Admin, in which case you still have access to the 'Admin' Tab and the 'Hide/Show' Menus Toggle button. And since I didn't sync the toggle button with a value in a table, so that it reflects the current state, the button still says "Hide" even though it would be nice if it said "Show" at this point - so no biggie, I just click hide once and the button says "Show" so then I click show, shut Access down and voila, navigation and all settings are back to normal.  Why haven't I synced the button with a value in the table?  Because I can't nail down why these settings are out of sync.  It gets even more complicated when I try to have different settings for different users utilizing, say, a checkbox in a table.  </p>
  
  <p>So fine. It's workable. </p>
  
  <p>But I'd like to get it working so that it works the way the interface layout suggests it should work.  If I have to notify the user that the settings won't take place till it is restarted, fine.  But I definitely want to know what's going on with the ribbon.</p>