Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hiding and Unhiding Toolbars

Status
Not open for further replies.

moolie

Programmer
May 7, 2002
193
CA
Merry Holidays everyone!

I have an issue with the app I'm working on. We have built a custom toolbar for the users to have access to from within Access. Unfortunately, this lockdown eliminates the standard toolbars and makes Supporting the app more difficult because we have to SHIFT-Open the app to have access to everything. We then build a Support Form that we can log into to gain access to tables etc, but I would like to have the standard development toolbars as well.

Is there an easy way through code to enable the toolbars during the Form.open event and remove the toolbars during the Form.close event?

 
Changing startup options programmatically requires a restart for them to take effect, but if you're just talking about support, that shouldn't be a problem.

What I do is create a shortcut that has the /cmd argument and then check for it when the splash screen loads:
Code:
"C:\Program Files\Microsoft Office\Office\msaccess.exe" "\\kirk\apps\acctng.mdb" /cmd "DevAccess"
If the right argument is passed in via /cmd, the splash screen turns all the startup options back to default, and notifies the user that Access is shutting down for the changes to take effect.

When you use the shortcut with the /cmd argument again the program starts normally. When you remove the /cmd argument from the shortcut, the lockdown options are reset by the splash screen, and the program shuts down again for them to take effect.

I use this method as insurance against users who like to poke around with things. Unless they find out what the /cmd argument is, they're locked out.

Here's a portion of the code I developed to accomplish this (altered for public viewing):
Code:
Private Sub Form_Open(Cancel As Integer)
On Error GoTo ErrHandler
  Dim X As Integer
  Dim blnEnabled As Boolean
  Dim intDirty As Integer
  Dim strArgs As String
  Dim udtProps(5) As StartupProperties
  
  Const conPropertyNotFound = 3270
  
  ' If /runtime mode - don't bother checking startup
  ' properties since app will be locked down anyway.
  If Not SysCmd(acSysCmdRuntime) Then
    ' Check command line argument for developer args
    strArgs = Command()
    If InStr(strArgs, "DevAccess") > 0 Then
      blnEnabled = True
      gbDebug = True
    Else
      blnEnabled = False
      gbDebug = False
    End If
    ' These properties are for Startup Options only.
    ' User options must be changed using: 'SetOption "ShowHidden", False'
    With udtProps(0)
      .Name = "AllowFullMenus"
      .Type = DAO.dbBoolean
      .Value = blnEnabled
    End With
    With udtProps(1)
      .Name = "AllowBuiltInToolbars"
      .Type = DAO.dbBoolean
      .Value = blnEnabled
    End With
    With udtProps(2)
      .Name = "AllowSpecialKeys"
      .Type = DAO.dbBoolean
      .Value = blnEnabled
    End With
    With udtProps(3)
      .Name = "AllowBypassKey"
      .Type = DAO.dbBoolean
      .Value = blnEnabled
    End With
    With udtProps(4)
      .Name = "StartupShowDBWindow"
      .Type = DAO.dbBoolean
      .Value = blnEnabled
    End With
    With udtProps(5)
      .Name = "StartupMenuBar"
      .Type = DAO.dbText
      .Value = IIf(blnEnabled, "(Default)", "MyCustom Menu")
    End With
    
    ' Some properties may not exist, so they must be
    ' created dynamically when error 3270 occurs.
    With Application.CurrentDb
      For X = 0 To UBound(udtProps)
        If .Properties(udtProps(X).Name).Value <> udtProps(X).Value Then
          .Properties(udtProps(X).Name).Value = udtProps(X).Value
NewPropertyAdded:
          intDirty = intDirty + 1
        End If
      Next X
    End With
    
    If intDirty > 0 Then
      MsgBox "Startup properties (" & intDirty & ") for this database have changed!" & _
              vbCr & vbCr & "The " & APP_NAME & " program will now terminate so " & _
             "changes can take effect.", , IIf(blnEnabled, "Developer Mode", "User Mode")
      Application.Quit
    End If
  End If
  
ExitHere:
  Exit Sub
ErrHandler:
  
  ' Create the non-existent properties and resume.
  If Err.Number = conPropertyNotFound Then
      Dim prp As DAO.Property
      Set prp = CurrentDb.CreateProperty(udtProps(X).Name, _
                        udtProps(X).Type, udtProps(X).Value)
      CurrentDb.Properties.Append prp
      ' Since the DB has to restart to make these properties effective,
      ' we can't reference them now so we'll skip any code references.
      ' Note: It's not necessary anyway since we know the property didn't exist.
      Resume NewPropertyAdded
  End If
  Resume ExitHere
End Sub

VBSlammer
redinvader3walking.gif

[sleeping]Unemployed in Houston, Texas
 
DoCmd.ShowToolbar "ToolbarName", acToolbarYes
DoCmd.ShowToolbar "ToolbarName", acToolbarNo

however I always just use shift+double click in all my databases. It's a habit. I don't find it more difficult.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top