Microsoft Access VBA Macro Programming

(Tina Sui) #1
I have never seen an application that did not come into this category. One of the
difficulties is that until several users start ardently working with your application, various
problems may never surface, and so you will find yourself constantly correcting and
responding to user requirements.
If the users are building up data in your application and no changes can be made to forms,
reports, and VBA, then when a change must be made you will need to use the original
ACCDB file that created the ACCDE file. However, it will not be up to date in terms of data
and this will need to be imported back in to the original ACCDB tables.
A danger exists of the whole process becoming messy and errors creeping in.

Using VBA to Lock Your Application Down


You can use the database properties to lock your database so users can only do what your
user interface lets them do and nothing more. You can also put a custom ribbon on the
opening form and subsequent forms (see Chapter 11 for more information on creating
ribbons).
For the following example, use a blank database with no data in it. Insert a module into the
VBE window using Insert | Module from the menu.
Enter the following code into the module:
Sub DisableStartupProperties()
ChangeProperty "StartupShowDBWindow", dbBoolean, False
ChangeProperty "StartupShowStatusBar", dbBoolean, False
ChangeProperty "AllowBuiltinToolbars", dbBoolean, False
ChangeProperty "AllowFullMenus", dbBoolean, False
ChangeProperty "AllowBreakIntoCode", dbBoolean, False
ChangeProperty "AllowSpecialKeys", dbBoolean, False
ChangeProperty "AllowBypassKey", dbBoolean, False
ChangeProperty "AllowShortcutMenus", dbBoolean, False
End Sub

Function ChangeProperty(strPropName As String, _
varPropType As Variant, varPropValue As Variant) As Integer
Dim dbs As Database, prp As Property
Const conPropNotFoundError = 3270

Set dbs = CurrentDb
On Error GoTo Change_Err
dbs.Properties(strPropName) = varPropValue
ChangeProperty = True

Change_Bye:
Exit Function

284 Microsoft Access 2010 VBA Macro Programming

Free download pdf