Microsoft Access 2010 Bible

(Rick Simeone) #1

Chapter 26: Bulletproofing Access Applications


925


Note
Because AllowBypassKey is a developer-only property, it isn’t built into Access databases. You must create,
append, and set this property sometime during the development process. Once appended to the database’s
Properties collection, you can set and reset it as needed.


Here’s the code you need to implement the AllowBypassKey property:

Function SetBypass(BypassFlag As Boolean) As Boolean
‘Returns True if value of AllowBypassKey
‘is successfully set to BypassFlag.
On Error GoTo SetBypass_Error
Dim db As DAO.Database
Set db = CurrentDb
db.Properties!AllowBypassKey = BypassFlag
SetBypass_Exit:
Exit Function
SetBypass_Error:
If Err = 3270 Then
‘AllowBypassKey property does not exist
‘in this database, so add it now:
MsgBox “Appending AllowBypassKey property”
db.Properties.Append _
db.CreateProperty(“AllowBypassKey”, _
dbBoolean, BypassFlag)
SetBypass = True
Resume Next
Else
‘Some other error
MsgBox “Unexpected error: “ & Error$ _
& “ (“ & Err & “)”
SetBypass = False
Resume SetBypass_Exit
End If
End Function

This function first tries to set the AllowBypassKey property to whatever value is passed in as
BypassFlag. If the attempt to set the property generates an error, indicating that the
AllowBypassKey property doesn’t exist, the error trap checks to see if the error value is 3270. If
it is, the AllowBypassKey property is created and appended to the database’s Properties collec-
tion after being set to the BypassFlag value.

If the error is anything other than 3270, the function simply exits and doesn’t try to resolve the
problem. Refer to Chapter 23 for more information on trapping and handling errors.

On the CD-ROM
The AllowBypassKeyDemo objects (frmAllowBypassKeyDemo and basAllowBypassKey) in the
Chapter26.accdb sample file on this book’s companion CD-ROM demonstrate how to set and use the
AllowBypassKey property. The frmAllowBypassKeyDemo form contains two toggle buttons that alter-
nately enable or disable the bypass feature.

Free download pdf