The Devil is in the details—and in the case of Access, it’s in the technical appendix. Here you’ll find behind-the-scenes particulars about maintaining your Access installation; tips on Access newsgroups that you can turn to for help; dozens of tables detailing Access functions, controls, actions, events; and more.
When casual users install Access, they generally run the installer and when it’s done, they assume that’s that. But Access power users and professional developers know that keeping Access healthy means going beyond what comes out of the box. With some simple preventive maintenance—installing service packs, re-registering DLLs, and so on—you can avoid headaches and mysterious failures too numerous to list. Here are the essentials to keeping Access healthy.
Whatever version of Windows you’re running, make sure that you have applied the latest security patches and updates. The easiest way to do this is by pointing Internet Explorer at http://windowsupdate.microsoft.com
.
Same deal for Microsoft Office. Office updates can be found at http://office.microsoft.com/officeupdate
.
Jet is the database engine under Access’s hood, and to minimize bugs, it’s essential you apply the latest Jet service packs. (See MSKB 239114 for detailed instructions.) To find out what version of Jet you have, locate the Msjet40.dll file; it’s usually in the WindowsSystem32 or WindowsSystem folder. Right-click it, choose Properties, and look on the Version tab. If your version is earlier than 4.0.8618.0, it is not up-to-date. Even if you have just purchased and installed the latest version of Access, you can’t assume that Jet is up-to-date. (On the other hand, if you have applied the latest service packs, and then upgraded to a new version of Access, you should be fine.)
By default, Setup leaves out some Access and Office features you might want later—such as some Wizards or certain Visual Basic Help files. The idea is that you can install them the first time you need them, but that’s kind of a pain, having to fetch the install CD over and over. To see what you’re missing, run the Add or Remove Programs control panel, click the Microsoft Office entry, then the Change button. This brings up the Maintenance Mode screen. Click the “Add or Remove Features” button, open the Microsoft Access for Windows item, and look for features with a “1” on them. These are features that are installed on “first use.” Save yourself time—click each feature’s icon and select “Run from My Computer.” When you’re done, click the Update Now button and you’ll install everything you’ve selected.
In addition to keeping your software up-to-date, you may occasionally need to re-register DLLs. A DLL file is an external library of functions that Access needs to work properly. DLLs can be shared among different programs, and it’s all too easy for one version of a DLL to be inadvertently replaced by another, or for a DLL’s listing in the Windows Registry to become corrupted. If this happens, you’ll lose the functionality provided by that DLL (for example, importing and exporting text depends on Mstext40.dll). Throughout this book we’ve pointed out how to recognize this situation; here we’ll just explain how to fix it.
To re-register a DLL (in this example, Mstext40.dll):
Find the regsvr32.exe utility. It should be on your system, typically in Windowssystem32. If not, do a file search for it. If you can’t find it, download it from Microsoft (see MSKB 267279 for the details).
Click Start → Run, and type something like:
C:Windowssystem32 egsvr32.exe C:Windowssystem32Mstext40.dll
and press Enter (see Figure A-1).
If you’re using Access as a frontend to another database (such as SQL Server, Oracle, or MySQL), you’ll need ODBC drivers specific to that database. (If you’re connecting to SQL Server, you can also connect via OLEDB.) ODBC drivers for Oracle and SQL Server come standard with Access, but it’s a good idea to update those drivers by getting the latest version of MDAC (Microsoft Data Access Components) for your version of Windows. Point your browser to http://www.microsoft.com/downloads
and search for MDAC. For more info about MDAC, see MSKB 190463. For ODBC drivers for other databases, consult the database vendor.
As you can see in Table A-1, there are quite a few newsgroups devoted to various aspects of Microsoft Access. You’ll generally get better results if you search or post questions in the appropriate group. Comp.databases.msaccess is the only general-purpose group, although microsoft.public.access.gettingstarted is also a great place to post newbie or non-specific questions. The most popular groups are those devoted to forms and form coding (i.e., VB code for forms), queries, and reports. To find these newsgroups, go to http://www.google.com
, click the Groups link, and type the newsgroup name in the box and click the Search Groups button.
comp.databases.ms-access |
microsoft.public.access.3rdpartyusrgrp |
microsoft.public.access.activexcontrol |
microsoft.public.access.commandbarsui |
microsoft.public.access.conversion |
microsoft.public.access.developers.toolkitode |
microsoft.public.access.devtoolkits |
microsoft.public.access.externaldata |
microsoft.public.access.forms |
microsoft.public.access.formscoding |
microsoft.public.access.gettingstarted |
comp.databases.ms-access |
microsoft.public.access.internet |
microsoft.public.access.interopoledde |
microsoft.public.access.macros |
microsoft.public.access.modulesdaovba |
microsoft.public.access.multiuser |
microsoft.public.access.odbcclientsvr |
microsoft.public.access.queries |
microsoft.public.access.reports |
microsoft.public.access.security |
microsoft.public.access.setupconfig |
microsoft.public.access.tablesdbdesign |
Programmers use functions and statements the way carpenters use hammers and nails. Visual Basic has nearly 150 functions that you can use in expressions or code. It behooves you to become familiar with these off-the-shelf power tools. If you’re writing code, you should also familiarize yourself with Visual Basic statements, which are listed in Access Help. (Click the Help button, then the Contents tab, then open Visual Basic Language Reference → Statements.) Statements can’t be used in expressions because they don’t return a value, but they do useful stuff, such as writing to a file or changing the current directory.
In addition to these built-in functions, every menu and toolbar command can be run from VB code using the
RunCommand
method. For example, you can perform the equivalent of View → Zoom → Zoom 100% by calling
RunCommand
with the acCmdZoom100
constant, like this: DoCmd.RunCommand acCmdZoom100
. (To find the constant you need, search for “RunCommand” in VB Help and click the acCommand link or the RunCommand Method Constants item. )
In the following tables (Table A-2, A-3, A-4, A-5, A-6, A-7, A-8, A-9, A-10, through A-11) VB functions are grouped by category. The lists are mostly alphabetical, but occasionally we group related functions. Once you find the function you need, look it up in VB Help for details about its arguments and usage. The 10 categories that we use are:
String manipulation and character functions
Math functions
Date and time functions
Files, directories, and environment functions
Tests and conditional expressions
Domain aggregate functions (those that operate on sets of records)
Interactive and process control functions
Accounting and financial functions
Other functions for use in Visual Basic code
Function |
Description |
Returns average of values. | |
Returns number of records. | |
Returns value of first record that meets criteria. | |
Despite the names, not very useful: returns the first (or last) record based on the order in which the records are stored, which is usually meaningless. According to Help, they should be used when you want a “random” record. | |
Returns minimum and maximum values. | |
Returns standard deviation (sample) and estimated standard deviation (population). | |
Returns sum of values. | |
Returns variance (sample) and estimated variance (population). |
Function |
Description |
Yields process control, allowing Windows to process events such as key presses or mouse clicks in the middle of a long computation. Does not return until all events in the queue are processed. | |
Displays a prompt that accepts user input in a text box. | |
Displays a message prompt with various button options (Okay/Cancel, Yes/No/Cancel, etc.). | |
Runs an executable program from code. | |
Returns elapsed time. |
Function |
Description |
Returns depreciation (double-declining balance) | |
Returns future value of an annuity | |
Returns interest payment of an annuity | |
Returns number of periods for an annuity | |
Returns payment for an annuity | |
Returns principal payment for an annuity | |
Returns present value of an annuity | |
|
Returns interest rate per period for an annuity |
Returns depreciation (straight-line) | |
Returns depreciation (sum-of-year’s digits) |
Access has over 50 different actions that can be specified in a macro. (In addition to these built-in actions, every menu and toolbar command can be run from a macro using the
RunCommand
action.) In the following tables (Tables A-12, A-13, A-14, A-15, A-16, through A-17), the actions are grouped by category. The lists are mostly alphabetical, but occasionally we group related actions. Once you find the action you need, look it up in Access Help for details about its arguments and usage. (An easy way to do this is to select the action in the macro design window and press F1.)
The six categories are:
Work with database objects
Work with data
Import, export, and linking
User interface
Printing, email, and external applications
Macro programming
Action |
Description |
Copies an object (query, form, and so on) from one MDB to another. | |
Exports data in table, query, and so on, to specified format (HTML, text, RTF, ASP, DAP, IIS, Excel ’98). You can autostart an appropriate application for the output file. Note: Use | |
Imports, exports, or links database objects between two databases. | |
Imports, exports, or links an Excel or 1-2-3 worksheet. | |
Imports, exports, or links a text file. |
Action |
Description |
Prints a report, datasheet, and so on, specifying page range, number of copies, etc. | |
Runs an external application, such as Word or FTP. | |
Sends database object (form, report, and so on) in the body of an email message. You can specify various output formats for objects (XLS, TXT, HTML, RTF), subject line, message, and so on. |
Action |
Description |
Cancels the event that triggered the macro. | |
Calls a Visual Basic function. Note: You must include parentheses, even if there are no arguments, like this: | |
Runs a built-in Microsoft Access command (e.g., from a menu or toolbar). | |
Runs a macro. You can specify the number of times to repeat, or that it repeats until a condition is satisfied. | |
Types keystrokes as if input by user (e.g., to fill in a dialog box or send to an external application). Maximum of 256 characters. Timing is unreliable. | |
Sets value of a field, control, or property of a form, report, or control. Note: You must not begin your expression with an equals sign. | |
Stops all macros currently running. | |
Stops this macro. |
There are over 15 events that are specific to PivotTables and PivotCharts. Technically, these are not Access events; they’re part of the Office Web Components library. But you will see them listed at the bottom of the Event tab of a form or report. To get more info on these pivot events, place the cursor in that event field and press F1.
Forms include about 45 different event hooks (Open, Close, AfterUpdate
, and so on), each of which allows you to run your own code or macro at a certain point in Access’s program flow. For example, every time a form is opened, Access sees if any code has been added to the form’s Open
event, and if it has, it runs it. Writing code in event procedures is a powerful way to customize the way Access behaves.
In the following tables (Tables A-18, A-19, A-20, A-21, through A-22), events are grouped by category. The lists are mostly alphabetical, but occasionally we’ll group related events. Note that only forms allow you to use control events; there are no events for controls on reports. The tables also indicate whether an event can be canceled (usually by setting a Cancel parameter equal to True), returning control to the user.
Once you find the event you need, look it up in Access Help for details about its usage. If you need precise information about the order of events, search for “order of events” or look under Programming in Access. The five categories that we use are:
Window and focus events
Data events
Keyboard and mouse events
Report layout and printing events
Other events
Event |
Applies to |
Description |
Cancel? |
form, report |
Y | ||
form, report | |||
form | |||
form |
Y | ||
form | |||
form, report |
Form/report window is about to become the active window. | ||
form, report |
A different Access window is about to become active. This event doesn’t fire if some other application becomes active. | ||
controls |
Control is about to receive focus from another control on the same form. | ||
controls |
Control is about to lose focus to another control on the same form. |
Y | |
form, controls |
Control is about to receive focus. A form can get focus only if it does not contain any visible, enabled controls. | ||
form, controls |
Control is about to lose focus. A form can lose focus only if it does not contain any visible, enabled controls. |
Event |
Applies to |
Description |
Cancel? |
Timer |
form |
Fires at regular intervals specified by the form’s TimerInterval property (on the Event tab). The interval is specified in milliseconds. If TimerInterval is 0, the event does not fire. | |
Error |
form, report |
Fires when a runtime error occurs. This event includes Access and Jet errors, but not Visual Basic errors. | |
BeforeDelConfirm |
form |
Fires when the delete confirm dialog box is about to be displayed. |
Y |
AfterDelConfirm |
form |
Fires when the delete confirm dialog box has just been responded to. | |
ApplyFilter |
form |
Fires when the user applies or removes a filter using Apply Filter, Remove Filter, or Filter By Selection. |
Y |
Filter |
form |
Fires when the user begins to create a filter using Filter By Form or Advanced Filter/Sort. |
Y |