RE: Access 2003
Current setup is: Front end .mdb (Interface, queries, macros, etc) /Back
end .mdb (Database Tables)
I'm trying to write some code that will prevent users from getting into
the code (ie. right clicking for form design mode, F11 for the
container, etc.)
I'm testing this with two buttons on a form in a very simple app
containing one table with 3 columns, 2 rows of data and one form based
on the table I just described.
This form has two buttons:
"Set Access App Properties for User"
"Set Access App Properties for Developer"
(A word about ".mde's: I know you might suggest making an .mde and
saving off the .mdb as source to the developer. I have way too much
code in my production app at this point, and I'm nervous about making
the .mde for fear it won't run properly and will generate loads of more
errors that frankly, I don't have time to fix at this point. Deployment
is about 5 days away and I can't risk a setback that the .mde might
bring to my project. To that end, I'm trying to set these properties
with code to better secure my applicaiton.
Basically in my test app here when I click
"Set Access Properties for User" I need these removed:
-right-click capability
-ability to press f11 to get to the DB.
-menus to be removed that would allow them to go into design mode and
create or modify objects.
...then when I click "Set Access Properties for Developer"
I need the above restored.
Here is what I have so far but it is not working right:
<begin code>
Public Function SetAccessAppProperties()
'This is run when "Set Access Properties for User" is clicked
'This sets the properties at the Microsoft Access Development Tool
level normally done via Tools/Options.
Dim db As Database
On Error Resume Next
Set db = CurrentDb()
'hide the main menu bar from users
Application.CommandBars("Menu Bar").Enabled = False
'these toolbars have the DatabaseWindow icon on them by default
DoCmd.ShowToolbar "Form View", acToolbarNo
DoCmd.ShowToolbar "Print Preview", acToolbarNo
ChangeProperty "AllowShortCutMenus", dbBoolean, False
ChangeProperty "StartupShowDBWindow", dbBoolean, False
ChangeProperty "AllowBuiltinToolbars", dbBoolean, False
ChangeProperty "AllowFullMenus", dbBoolean, False
ChangeProperty "AllowToolbarChanges", dbBoolean, False
ChangeProperty "AllowBreakIntoCode", dbBoolean, False
ChangeProperty "AllowSpecialKeys", dbBoolean, False
ChangeProperty "AllowBypassKey", dbBoolean, False
Set db = Nothing
On Error GoTo 0
End Function
Public Function ResetAccessAppProperties()
'This is run when "Set Access Properties for Developer" is clicked
'This sets the properties back at the Microsoft Access Development
Tool level normally done via Tools/Options.
Dim db As Database
MsgBox "Begin ResetAccessAppProperties"
On Error Resume Next
Set db = CurrentDb()
db.Properties("StartupShowDBWindow") = True
DoCmd.ShowToolbar "Form View", acToolbarYes
DoCmd.ShowToolbar "Print Preview", acToolbarYes
ChangeProperty "AllowShortCutMenus", dbBoolean, True
ChangeProperty "StartupShowDBWindow", dbBoolean, True
ChangeProperty "AllowBuiltinToolbars", dbBoolean, True
ChangeProperty "AllowFullMenus", dbBoolean, True
ChangeProperty "AllowToolbarChanges", dbBoolean, True
ChangeProperty "AllowBreakIntoCode", dbBoolean, True
ChangeProperty "AllowSpecialKeys", dbBoolean, True
'set MenuBar back to default with
'Application.MenuBar = ""
'hide the main menu bar from users
Application.CommandBars("Menu Bar").Enabled = True
Set db = Nothing
On Error GoTo 0
End Function
Public Function ChangeProperty(strPropName As String, varPropType As
Variant, varPropValue As Variant) As Integer
Dim dbs As Database
Dim prp As Property
Const conPropNotFoundError = 3270
Set dbs = CurrentDb
On Error GoTo Change_Err
MsgBox "Changing property for: " & " & strpropname & " - " &
varproptype & " - " & varpropvalue"
dbs.Properties(strPropName) = varPropValue
ChangeProperty = True
Change_Bye:
Exit Function
Change_Err:
If Err = conPropNotFoundError Then ' Property not found.
Set prp = dbs.CreateProperty(strPropName, varPropType, varPropValue)
dbs.Properties.Append prp
Resume Next
Else
' Unknown error.
ChangeProperty = False
Resume Change_Bye
End If
End Function
<end code>
*** Sent via Developersdex http://www.developersdex.com ***