Here's some code that I've perfected for myself. It's a little modified from code I found in Access Advisor. Best thing I've found so far.
It's for anyone who likes to use MDE files for their frontends. Basically what it does is test whether or not the file is mde or mdb. Also works on adp or ade. Then it will set all properties the way you want set depending on what type. I have it keep everything available for the mdb file which is where I do the development. Then when I create the MDE file it will lock everything down. You have to create a form to open on startup to run all the procedures and then it can be closed. But it's great because I don't have to worry whether I've set the bypass to enabled or not. Have a look.
Private Function AddAppProperty( _
strName As String, _
varType As Variant, _
varValue As Variant) As Boolean
Dim dbs As Object
Dim prp As Variant
Const DB_Text As Long = 10
Const DB_Boolean As Long = 1
Const conPropNotFoundError = 3270
If varType = DB_Text Then
If IsNull(varValue) Or varValue = vbNullString Then
On Error Resume Next
Set dbs = CurrentDb
dbs.Properties.Delete (strName)
Set dbs = Nothing
AddAppProperty = True
Exit Function
End If
End If
Set dbs = CurrentDb
On Error GoTo AddProp_Err
dbs.Properties(strName) = varValue
AddAppProperty = True
AddProp_Bye:
Set dbs = Nothing
Set prp = Nothing
Exit Function
AddProp_Err:
If Err = conPropNotFoundError Then
Set prp = dbs.CreateProperty(strName, varType, varValue)
dbs.Properties.Append prp
Resume
Else
AddAppProperty = False
Resume AddProp_Bye
End If
End Function
Private Function IsCompiledFile() As Boolean
'Returns True if MDE or ADE this function
'Returns False if MDB or ADP
On Error GoTo Err
Dim strMDEADE As String
On Error Resume Next
'The ProjectType property is used to determine
'if the database is an MDB or ADP
If CurrentProject.ProjectType = acMDB Then
strMDEADE = CurrentDb.Properties("MDE").Value
Else
strMDEADE = CurrentProject.Properties("MDE").Value
End If
'The next line is the original Microsoft code.
'I have expanded it for readability.
'IsCompiledFile =
'(Err.Number = 0 And strMDEADE = "T")
If Err.Number = 0 And strMDEADE = "T" Then
IsCompiledFile = True
Else
IsCompiledFile = False
End If
Exit Function
Err:
MsgBox Err.Description
End Function
Public Function SetDbProperties()
'Uses the IsCompiledFile function to determine what kind of database this is.
'Sets the database startup properties accordingly
On Error GoTo Err
DoCmd.Hourglass (True)
Dim strProjectName As String
Dim strStartupMenuBar As String
Dim strAppIcon As String
Dim strStartupShortcutMenubar As String
On Error Resume Next
'The following variables will need to be customized for each db
strProjectName = "Cash Processor"
strStartupMenuBar = vbNullString
strAppIcon = "C:\Documents and Settings\All Users\Documents\Money.bmp"
strStartupShortcutMenubar = vbNullString
'The Select Case will setup the properties depending
'on whether the db is a development or a user file
Select Case IsCompiledFile
Case True 'User file
Call AddAppProperty("AppTitle", DB_Text, strProjectName)
Call AddAppProperty("StartupForm", DB_Text, "frmSplash")
Call AddAppProperty("StartupShowDBWindow", DB_Boolean, False)
Call AddAppProperty("StartupShowStatusbar", DB_Boolean, True)
Call AddAppProperty("StartupMenuBar", DB_Text, strStartupMenuBar)
Call AddAppProperty("AllowShortcutMenus", DB_Boolean, False)
Call AddAppProperty("AllowFullMenus", DB_Boolean, False)
Call AddAppProperty("AllowBuiltInToolbars", DB_Boolean, False)
Call AddAppProperty("AllowToolbarChanges", DB_Boolean, False)
Call AddAppProperty("AllowBreakIntoCode", DB_Boolean, False)
Call AddAppProperty("AllowSpecialKeys", DB_Boolean, False)
Call AddAppProperty("AllowBypassKey", DB_Boolean, False)
Call AddAppProperty("AppIcon", DB_Text, strAppIcon)
Call AddAppProperty("StartupShortcutMenubar", DB_Text, strStartupShortcutMenubar)
Call AddAppProperty("UseAppIconForFrmRpt", DB_Boolean, True)
Call Application.SetOption("ShowWindowsInTaskbar", False)
CommandBars("Print Preview").Enabled = False
Case False 'Developer's file
Call AddAppProperty("AppTitle", DB_Text, "Development - " & strProjectName)
Call AddAppProperty("StartupForm", DB_Text, "frmSplash")
Call AddAppProperty("StartupShowDBWindow", DB_Boolean, True)
Call AddAppProperty("StartupShowStatusbar", DB_Boolean, True)
Call AddAppProperty("StartupMenuBar", DB_Text, strStartupMenuBar)
Call AddAppProperty("AllowShortcutMenus", DB_Boolean, True)
Call AddAppProperty("AllowFullMenus", DB_Boolean, True)
Call AddAppProperty("AllowBuiltInToolbars", DB_Boolean, True)
Call AddAppProperty("AllowToolbarChanges", DB_Boolean, True)
Call AddAppProperty("AllowBreakIntoCode", DB_Boolean, True)
Call AddAppProperty("AllowSpecialKeys", DB_Boolean, True)
Call AddAppProperty("AllowBypassKey", DB_Boolean, True)
Call AddAppProperty("AppIcon", DB_Text, strAppIcon)
Call AddAppProperty("StartupShortcutMenubar", DB_Text, strStartupShortcutMenubar)
Call AddAppProperty("UseAppIconForFrmRpt", DB_Boolean, True)
Call Application.SetOption("ShowWindowsInTaskbar", True)
CommandBars("Print Preview").Enabled = True
End Select
Exit Function
Err:
MsgBox Err.Description
End Function