Custom properties

A

Art

You can declare "custom properties" by choosing
file>database properties>custom and create & assign a
value to a custom property. But can I (and how) reference
these properties within my applicastion?
 
T

TC

(snip)
The *only way* to get it back is to click the Full Button.

Not really. Any member of the Admins group of the relevant workgroup file,
can execute code to open the database & amend the property settings as
required to get back in.

I'm not criticizing your suggestion, just pointing out that it >is< possible
to get back in, if you are a member of the Admins group of the relevant
workgroup file.

TC
 
J

Joe Fallon

Here is some sample code. Towars the end you see:
Set prp = db.CreateProperty(stPropName, _
PropType, vPropVal, True)


============================================

Only do this on a backup copy of your mdb.
It is very easy to "lock yourself out forever."

Create two buttons on the Startup form: one to call SetFullStartUpProperties
and another to callSetLimitedStartupProperties.

Change their visible property so that only you can see them.
If CurrrentUser() = "joe" Then
Me![btn1].Visible=True
Me![btn2].Visible=True
Else
Me![btn1].Visible=False
Me![btn2].Visible=False
End If

Click the Limited button, close the mdb and re-open.

Code behind the Limited button:
DoCmd.Hourglass True
SetLimitedStartupProperties
DoCmd.Hourglass False
MsgBox ("Limited start up options set.")

You will be locked out of the database window.

The *only way* to get it back is to click the Full Button.
This is why you have to practice on a copy!!!

Put this code in a module:

Sub SetFullStartupProperties()
ChangeProperty "StartupForm", dbText, "Startup",True
ChangeProperty "StartupShowDBWindow", dbBoolean, False,True
ChangeProperty "StartupShowStatusBar", dbBoolean, True,True
ChangeProperty "AllowBuiltinToolbars", dbBoolean, True,True
ChangeProperty "AllowToolbarChanges", dbBoolean, True,True
ChangeProperty "AllowFullMenus", dbBoolean, True,True
ChangeProperty "AllowShortcutMenus", dbBoolean, True,True
ChangeProperty "AllowBreakIntoCode", dbBoolean, True,True
ChangeProperty "AllowSpecialKeys", dbBoolean, True,True
ChangeProperty "AllowBypassKey", dbBoolean, True,True
End Sub

Sub SetLimitedStartupProperties()
ChangeProperty "StartupForm", dbText, "Startup",True
ChangeProperty "StartupShowDBWindow", dbBoolean, False,True
ChangeProperty "StartupShowStatusBar", dbBoolean, True,True
ChangeProperty "AllowBuiltinToolbars", dbBoolean, False,True
ChangeProperty "AllowToolbarChanges", dbBoolean, False,True
ChangeProperty "AllowFullMenus", dbBoolean, False,True
ChangeProperty "AllowShortcutMenus", dbBoolean, False,True
ChangeProperty "AllowBreakIntoCode", dbBoolean, False,True
ChangeProperty "AllowSpecialKeys", dbBoolean, False,True
ChangeProperty "AllowBypassKey", dbBoolean, False,True
End Sub

Function ChangeProperty(stPropName As String, _
PropType As DAO.DataTypeEnum, vPropVal As Variant) _
As Boolean
' Uses the DDL argument to create a property
' that only Admins can change.
'
' Current CreateProperty listing in Access help
' is flawed in that anyone who can open the db
' can reset properties, such as AllowBypassKey
'
On Error GoTo ChangeProperty_Err

Dim db As DAO.Database
Dim prp As DAO.Property

Const conPropNotFoundError = 3270

Set db = CurrentDb
' Assuming the current property was created without
' using the DDL argument. Delete it so we can
' recreate it properly
db.Properties.Delete stPropName
Set prp = db.CreateProperty(stPropName, _
PropType, vPropVal, True)
db.Properties.Append prp

' If we made it this far, it worked!
ChangeProperty = True

ChangeProperty_Exit:
Set prp = Nothing
Set db = Nothing
Exit Function

ChangeProperty_Err:
If Err.Number = conPropNotFoundError Then
' We can ignore when the prop does not exist
Resume Next
End If
Resume ChangeProperty_Exit
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top