Microsoft Access 2010 Bible

(Rick Simeone) #1

Chapter 26: Bulletproofing Access Applications


923


A prototype of using LogError() is shown in the following subroutine. Notice that the
LogError() function is triggered by the subroutine’s error handler. After the error is logged, you
handle the error by other code that may be needed.


Sub MySubroutine
On Error GoTo MyErrorHandler
<Your code goes here>
Exit Sub
MyErrorHandler:
LogError(“MySubroutine”, Err.Number, Err.Description)
<Handle error here>
Resume
End Sub

The most critical items in the error log are the date and time, the error number, and the error
description. The procedure name is useful, but it has to be hard-coded for each procedure (sub-
routine or function) you log with LogError().


Securing the environment


Obviously a serious Access application must be secured from unauthorized users. The built-in
user-level security system (enforced by the Jet database engine, not by Access) provides multiple
levels of security. You can, for example, secure a single database object (form, table, report) from
individuals, groups, or individuals within groups. A user can even have multiple levels of security
(provided the user has been assigned multiple login names). All the Access security objects, their
properties, and methods are accessible throughout Access Visual Basic code.


User-level security is only available in the .mdb database format. The .accdb format provides
other types of data protection, such as password-protected strong encryption, that is not available
in the .mdb format. As a developer, you’ll have to decide whether user-level security or strong
encryption is needed to protect the data in your Access applications.


Setting start-up options in code


The options you set on the Current Database tab of the Access Options dialog box (refer to Figure
26.7) apply globally to every user who logs into the database. There are times when you want to
control these options through start-up code instead of allowing the global settings to control the
application. For example, a database administrator should have access to more of the database con-
trols (menus, the Navigation pane) than a data-entry clerk has.


Almost every option you see in the Options screen can be set through code. As you’ll see in the
“Setting property values” section, you can use Access VBA to control the settings of the
Application object properties listed in Table 26.4.

Free download pdf