Went to the link - don't understand your remark re user defined property. You're trying to set a database property if it's in the collection, or add it then set it if it's not. I wouldn't call that user defined, but then, I don't claim to know everything. You can lock yourself out of a db with this property, so I'd provide a means of cycling it to prevent that. Here's what I do. Some form label (I use an About form) has a double click event known to the power users or developers of the db. I think this routine is a bit more powerful and maybe even simpler to follow than what you posted:
Code:
Sub setDisableMode() 'called by dbl click event on the 'about' form
Dim mode As Boolean
Dim db As DAO.Database
Dim prop As DAO.Property
On Error GoTo errHandler
Set db = CurrentDb
Set prop = db.Properties("AllowByPassKey") 'if prop does not exist, error 3270 is raised.
If dbUser.Level = "admin" Then 'dbUser is a user defined object, not property or function
If prop = True Then 'bypass enabled; change it to false
mode = False 'switch the mode to False
prop = apDisableShift(mode) 'pass the mode to the function
DoCmd.SelectObject acForm, "frmAbout", False 'select frmAbout, which is still open
Forms!frmAbout.lblVersion.BackColor = 16777215 set the label background to white
Else: 'assume prop is false
mode = True 'pass this mode to the function
prop = apDisableShift(mode) 'pass mode to the function
DoCmd.SelectObject acForm, "frmAbout", False
Forms!frmAbout.lblVersion.BackColor = 255 'set label background to red as visual clue
End If
MsgBox "Enable bypass is now " & prop 'let user know the new value was set
Set db = Nothing
Set prop = Nothing
Exit Sub
End If
MsgBox "You must be an administrator to change settings."
exitHere:
Set db = Nothing
Set prop = Nothing
Exit Sub
errHandler:
If Err.Number = 3270 Then 'bypass property doesn't exist so create it
Set prop = db.CreateProperty("AllowByPassKey", dbBoolean, False)
db.Properties.Append prop
Resume
End If
MsgBox Err.Number & ": " & Err.Description
Resume exitHere
End Sub
This piece takes the argument from the sub and cycles the property
Code:
Function apDisableShift(mode) As Boolean
CurrentDb.Properties("AllowByPassKey") = mode
apDisableShift = mode
End Function