Microsoft Access VBA Macro Programming

(Tina Sui) #1

Change_Err:
If Err = conPropNotFoundError Then
Set prp = dbs.CreateProperty(strPropName, varPropType, varPropValue)
dbs.Properties.Append prp
Resume Next
Else
ChangeProperty = False
Resume Change_Bye
End If
End Function


This code includes a function that will change the property value. If the property is not
found, it will be created.
When this code is run, it will set the properties shown in the code to False. This prevents,
for example, theBREAKkey and theBYPASSkey (SHIFT) being used to interrupt the database.
It also disables shortcut menus (right-click a form or report) and prevents the database
navigation window from appearing.
Run this code, but do not exit the database. The property changes have no effect until you
exit the database and then reload it.
Next, you need to design a simple ribbon that will remove the existing Access ribbon. To
do this, you must first create a table called USysRibbons. You do this by clicking Create in
the Access menu bar and then clicking the Table Design icon in the Tables group of the
ribbon.
You need to create two fields in the tables. The first is called RibbonName and is a text
field. The second is called RibbonXML and is a memo field. Save the table with the name
USysRibbons.
In the database navigation window, right-click the bar at the top of the navigation pane
and click Navigation Options. Check the box for Show System Objects. Because this is a
system table, you will not see it or be able to find it unless you do this.
Open the table and type in the valueMyRibbonin the RibbonName field. Enter the
following XML in the RibbonXML field for that record:


<customUI
xmlns="http://schemas.microsoft.com/office/2006/01/customui">





Because this uses startFromScratch, it will create a ribbon that displays only the File tab.
You can of course add ribbon commands into the XML to suit your application but for this
exercise it will just be a simple ribbon that is empty.
You now need to create an opening form for your application using Create on the Access
menu bar and clicking the Blank Form icon in the Forms group of the ribbon.
Save the form and give it a name such as Main. Click the File tab in the Access menu and
click Options. Click Current Database in the left-hand pane and then use the drop-down for


Chapter 24: Securing Your Database 285

Free download pdf