access 2007 bibledownload.e-bookshelf.de/download/0000/5692/04/l-g-0000569204... · access™ 2007...

30
Access 2007 Bible Michael R. Groh, Joseph C. Stockman, Gavin Powell, Cary N. Prague, Michael R. Irwin, and Jennifer Reardon

Upload: duongthien

Post on 03-May-2018

216 views

Category:

Documents


1 download

TRANSCRIPT

Access™ 2007 Bible

Michael R. Groh, Joseph C. Stockman,

Gavin Powell, Cary N. Prague,

Michael R. Irwin, and Jennifer Reardon

01_046732 ffirs.qxp 11/21/06 8:43 AM Page iii

01_046732 ffirs.qxp 11/21/06 8:43 AM Page ii

Access™ 2007 Bible

01_046732 ffirs.qxp 11/21/06 8:43 AM Page i

01_046732 ffirs.qxp 11/21/06 8:43 AM Page ii

Access™ 2007 Bible

Michael R. Groh, Joseph C. Stockman,

Gavin Powell, Cary N. Prague,

Michael R. Irwin, and Jennifer Reardon

01_046732 ffirs.qxp 11/21/06 8:43 AM Page iii

Access™ 2007 Bible

Published byWiley Publishing, Inc.10475 Crosspoint BoulevardIndianapolis, IN 46256www.wiley.com

Copyright © 2007 by Wiley Publishing, Inc., Indianapolis, Indiana

Published simultaneously in Canada

Library of Congress Control Number: 2006936763

ISBN-13: 978-0-470-04673-9ISBN-10: 0-470-04673-2

Manufactured in the United States of America

10 9 8 7 6 5 4 3 2 1

1B/RT/RS/QW/IN

No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means,electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 ofthe 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorizationthrough payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the LegalDepartment, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317)572-4355, or online at http://www.wiley.com/go/permissions.

LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NOREPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THECONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUTLIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATEDOR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINEDHEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDINGTHAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHERPROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENTPROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BELIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE ISREFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATIONDOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THEORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERSSHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED ORDISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ.

For general information on our other products and services or to obtain technical support, please contact our CustomerCare Department within the U.S. at (800) 762-2974, outside the U.S. at (317) 572-3993 or fax (317) 572-4002.

Trademarks: Wiley, the Wiley logo, and related trade dress are trademarks or registered trademarks of John Wiley & Sons,Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. Accessis a trademark of Microsoft Corporation in the United States and/or other countries. All other trademarks are the propertyof their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book.

Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available inelectronic books.

01_046732 ffirs.qxp 11/21/06 8:43 AM Page iv

About the AuthorsMichael R. Groh is a well-known author, writer, and consultant specializing in Windows databasesystems. His company, PC Productivity Solutions, provides information-management applicationsto companies across the country. Over the last 25 years, Mike has worked with a wide variety ofprogramming languages, operating systems, and computer hardware, ranging from programming aDEC PDP-8A using the Focal interpreted language to building distributed applications underVisual Studio .NET and Microsoft SharePoint.

Mike was one of the first people outside of Microsoft to see Access in action. He was among a selectgroup of journalists and publishers invited to preview the Access 1.0 beta (then called Cirrus) atthe 1992 Windows World Conference in Chicago. Since then, Mike has been involved in everyMicrosoft Access beta program, as an insider and as a journalist and reporter documenting the evo-lution of this fascinating product.

Mike has authored parts of more than 20 different computer books and is a frequent contributor tocomputer magazines and journals. Mike has written more than 200 articles and editorials over thelast 15 years, mostly for Advisor Media (San Diego, CA). He frequently speaks at computer confer-ences virtually everywhere in the world, and is technical editor and contributor to periodicals andpublications produced by Advisor Media.

Mike holds a master’s degree in Clinical Chemistry from the University of Iowa (Iowa City, IA) andan MBA from Northeastern University (Boston, MA).

Mike can be reached at [email protected]. Please prefix the e-mail subject linewith “AccessBible:” to get past the spam blocker on this account.

Joseph C. Stockman is an independent consultant, software designer, and author who has beenusing Microsoft Access since its initial release. He has also developed courseware and taught classesin Access and VBA. Joe developed his first application in Access, and then migrated into VisualBasic and Visual Basic .NET, where he specializes in creating applications for the Windows Mobileplatform. He worked for several software companies before forming his consulting business in2002, where he deals with all types of clients including healthcare, financial, government, manu-facturing, and small business. His ability to turn his customers’ wishes into working applicationskeeps them satisfied. Joe is also writing the fundamentals column for the Advisor Guide to MicrosoftAccess magazine.

Gavin Powell is a computer consultant and a writer, with over 20 years of IT experience and over10 titles to his credit. He has worked as a programmer, analyst, data modeler, database administra-tor, and Unix administrator. Gavin is also a semiprofessional musician, songwriter, and recordingengineer, playing multiple instruments and writing prolifically. Gavin can be reached by e-mail [email protected] or [email protected].

Cary N. Prague is an internationally best-selling author and lecturer in the database industry. Heowns Database Creations, Inc., the world’s largest Microsoft Access add-on company. Their products

01_046732 ffirs.qxp 11/21/06 8:43 AM Page v

include a line of financial software; Business! for Microsoft Office, a mid-range accounting system,POSitively Business! Point of Sale software, the Inventory Barcode manager for mobile data collec-tion, and the Check Writer and General Ledger. Database Creations also produces a line of devel-oper tools including the appBuilder, an application generator for Microsoft Access, the EZ AccessDeveloper Tools for building great user interfaces, appWatcher for maintaining code bases amongseveral developers, and Surgical Strike, the only Patch Manager for Microsoft Access.

Cary also owns Database Creations Consulting, LLC., a successful consulting firm specializing inMicrosoft Access and SQL Server applications. Local and national clients include many Fortune100 companies including manufacturers, defense contractors, insurance, health-care, and softwareindustry companies. His client list includes Microsoft, United Technologies, ABB, Smith & WessonFirearms, Pratt and Whitney Aircraft, ProHealth, OfficeMax, Continental Airlines, and otherFortune 500 companies.

Formerly, he has held numerous management positions in corporate information systems, includ-ing Director of Managed Care Reporting for MetraHealth, Director of Corporate Finance andSoftware Productivity at Travelers Insurance where he was responsible for software support for35,000 end users, and Manager of Information Systems support for Northeast Utilities.

He is one of the top best-selling authors in the computer database management market, havingwritten over 40 books that have sold over one million copies on software including MicrosoftAccess, Borland (Ashton-Tate) dBASE, Paradox, R:Base, Framework, and graphics. Cary’s booksinclude 11 books in the Access Bible series (recently number one on the Ingram BestsellingDatabase Titles list and in the Amazon.com top 100), Access 97 Secrets, dBASE for WindowsHandbook, dBASE IV Programming (winner of the Computer Press Association’s Book of the Yearaward for Best Software Specific Book), and Everyman’s Database Primer Featuring dBASE IV. Herecently completed several books for Access 2003 including Weekend Crash Course in Office Access2003 Programming. Cary recently sold a product line named eTools for Microsoft Access toMightyWords, a division of FatBrain.com and Barnes and Noble.

Cary is certified in Access as a Microsoft Certified Professional and has passed the MOUS test inAccess and Word. He is a frequent speaker at seminars and conferences around the country. He ison the exclusive Microsoft Access Insider Advisory Board and makes frequent trips to Microsoftheadquarters in Redmond, WA. He has been voted the best speaker by the attendees of severalnational conferences. Recently, he was a speaker for Microsoft sponsored conferences in NewOrleans, Hawaii, Phoenix, Chicago, Toronto, Palm Springs, Boston, and Orlando. He has also spo-ken at Borland’s Database Conference, Digital Consulting’s Database World, Microsoft’s DeveloperDays, Computerland’s Technomics Conference, COMDEX, and COMPAQ Computer’s Innovate. Hewas a contributing editor to Access Advisor magazine and has written for the Microsoft OfficeDeveloper’s journal.

He is active in local town politics serving on the South Windsor, Connecticut Board of Education,Parks and Recreation Commission, and the Board of Assessment Appeals.

Cary holds a master’s degree in computer science from Rensselaer Polytechnic Institute, and anM.B.A and Bachelor of Accounting from the University of Connecticut. He is also a Certified DataProcessor.

vi

About the Authors

01_046732 ffirs.qxp 11/21/06 8:43 AM Page vi

Michael R. Irwin is considered one of the leading authorities on automated database and Internetmanagement systems today. He is a noted worldwide lecturer, a winner of national and interna-tional awards, best-selling author, and developer of client/server, Internet, Intranet, and PC-baseddatabase management systems.

Michael has extensive database knowledge, gained by working with the Metropolitan PoliceDepartment in Washington, D.C. as a developer and analyst for the Information Systems Divisionfor over 20 years and assorted Federal Agencies of the United States Government. Since retiring inJune 1992, he runs his own consulting firm, named The Irwin Group, and is principal partner inthe company - IT in Asia, LLC, specializing in Internet database integration and emphasizingClient/Server and net solutions. With consulting offices in Cincinnati, Ohio, Bangkok, Thailand,and Manila, Philippines, his companies offer training and development of Internet and databaseapplications. His company has the distinction of being one of the first Microsoft Solution’sProviders (in 1992). His local, national, and international clients include many software compa-nies, manufacturers, government agencies, and international companies.

His range of expertise includes database processing and integration between mainframe, minicom-puter, and PC-based database systems, as well as B-2-B and B-2-C integration between back-enddatabases; he is a leading authority on PC-based databases.

He is one of the top best-selling authors in the computer database management market, havingauthored numerous database books, with several of them consistently on the best-sellers lists. Hisbooks, combined, have sold nearly a million copies worldwide. His most recent works include TheOOPs Primer (Borland Press), dBASE 5.5 for Windows Programming (Prentice Hall), Microsoft Access2002 Bible, Microsoft Access 2002 Bible Gold Edition (co-authored), and Working with the Internet. TheAccess Bible series have constantly been number one on the Ingram Best-selling Database Titles listand is consistently in the Amazon.com and Buy.com top 10. He has also written several books oncustoms and cultures of the countries of Asia (including China, Japan, Thailand, and India). Two ofhis books have won international acclaim. His books are published in over 24 languages world-wide. He has been a contributing editor and author to many well-known magazines and journals.

He is a frequent speaker at seminars and conferences around the world and has been voted the bestspeaker by the attendees of several international conferences.

Michael has developed and markets several add-on software products for the Internet and produc-tivity related applications. Many of his productivity applications can be obtained from several of hisInternet sites or on many common download sites. Many of his application and systems are dis-tributed as freeware and careware. He has also developed and distributes several development toolsand add-ins for a wide range of developer applications.

Jennifer Reardon is considered a leading developer of custom database applications. She has overten years’ experience developing client/server and PC-based applications. She has accumulatedmuch of her application development experience working as lead developer for DatabaseCreations. She has partnered with Cary Prague developing applications for many Fortune 500companies.

vii

About the Authors

01_046732 ffirs.qxp 11/21/06 8:43 AM Page vii

Her most significant projects include a spare parts inventory control system for Pratt & Whitney’sF22 program, an engineering specifications system for ABB-Combustion Engineering, and anemergency event tracking system for the State of Connecticut. She was also the lead developer ofmany of the Database Creations add-on software products including Business, Yes! I Can Run MyBusiness, Check Writer, and the User Interface Construction Kit.

She has co-authored Access 2003 Bible, Access 2002 Bible, and Access 2000 Weekend Crash Course.She has also written chapters in other books on subjects including Data Access Pages, the MicrosoftDatabase Engine, the VBA programming environment, creating help systems, and using MicrosoftOffice 2000 Developer. She has authored chapters in Microsoft Access 97 Bible and Access 97 Secrets.

Jennifer owns her own consulting firm, Advanced Software Concepts, providing custom applica-tions to both the public and private sectors. She specializes in developing client information sys-tems for state-managed and privately-held healthcare organizations. She has also developed a jobcosting and project management system for an international construction company. Her corporateexperience includes seven years with The Travelers where she was an Associate Software Engineerserving on numerous mission-critical client/server software development projects using Easel, C,SQL Server, and DB2. She has contributed several chapters for books on dBase and MicrosoftAccess.

Jennifer holds a Bachelor of Science degree from the University of Massachusetts.

viii

About the Authors

01_046732 ffirs.qxp 11/21/06 8:43 AM Page viii

ix

CreditsAcquisitions ManagerGreg Croy

Project EditorElizabeth Kuball

Technical EditorVincent McCune

Copy EditorElizabeth Kuball

Editorial ManagerJodi Jensen

Vice President & Executive Group PublisherRichard Swadley

Vice President and PublisherAndy Cummings

Editorial DirectorMary C. Corder

Project CoordinatorHeather Kolter

Graphics and Production SpecialistsCarrie A. FosterBrooke GraczykDenny HagerJoyce HaugheyJennifer Mayberry

Quality Control TechniciansLaura AlbertJessica KramerChristine Pingleton

Media Development Project SupervisorLaura Moss

Media Development SpecialistKit Malone

Proofreading and IndexingTechbooks

01_046732 ffirs.qxp 11/21/06 8:43 AM Page ix

Acknowledgments ....................................................................................................................xxxixForeword ......................................................................................................................................xli

Part I: Access Building Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Chapter 1: An Introduction to Database Development ....................................................................3Chapter 2: Creating Access Tables ................................................................................................23Chapter 3: Designing Bulletproof Databases..................................................................................87Chapter 4: Selecting Data with Queries ......................................................................................123Chapter 5: Using Operators and Expressions in Access ..............................................................161Chapter 6: Working with Datasheet View....................................................................................203Chapter 7: Creating Basic Access Forms......................................................................................237Chapter 8: Working with Data on Access Forms ........................................................................269Chapter 9: Presenting Data with Access Reports..........................................................................297

Part II: Programming Microsoft Access . . . . . . . . . . . . . . . . . . . 345Chapter 10: VBA Programming Fundamentals ............................................................................347Chapter 11: Mastering VBA Data Types and Procedures ..............................................................385Chapter 12: Understanding the Access Event Model ..................................................................417Chapter 13: Using Expressions in Queries and VBA Code ..........................................................443Chapter 14: Accessing Data with VBA Code................................................................................471Chapter 15: Using the VBA Debugging Tools ..............................................................................497

Part III: More Advanced Access Techniques . . . . . . . . . . . . . . . 523Chapter 16: Working with External Data ....................................................................................525Chapter 17: Importing and Exporting Data ................................................................................555Chapter 18: Advanced Access Query Techniques ........................................................................581Chapter 19: Advanced Access Form Techniques ........................................................................617Chapter 20: Advanced Access Report Techniques ......................................................................647Chapter 21: Building Multiuser Applications ..............................................................................685Chapter 22: Integrating Access with Other Applications ............................................................723Chapter 23: Integrating Access with SharePoint ..........................................................................749Chapter 24: Using ActiveX Controls............................................................................................769Chapter 25: Handling Errors and Exceptions ..............................................................................801

x

02_046732 ftoc.qxp 11/21/06 8:43 AM Page x

Part IV: Professional Database Development . . . . . . . . . . . . . . 821Chapter 26: Optimizing Access Applications ..............................................................................823Chapter 27: Advanced Data Access with VBA..............................................................................863Chapter 28: Bulletproofing Access Applications ..........................................................................877Chapter 29: Securing Access Applications ..................................................................................909Chapter 30: Using the Windows API ..........................................................................................951Chapter 31: Using the Access Replication Features ....................................................................987Chapter 32: Object-Oriented Programming with VBA ..............................................................1037Chapter 33: Reusing VBA Code with Libraries ..........................................................................1079Chapter 34: Customizing Access Ribbons ................................................................................1089Chapter 35: Distributing Access Applications............................................................................1117Chapter 36: Using Access Macros..............................................................................................1133

Part V: Access as an Enterprise Platform . . . . . . . . . . . . . . . . . 1163Chapter 37: Using XML in Access 2007 ....................................................................................1165Chapter 38: SharePoint as a Data Source ..................................................................................1191Chapter 39: Client/Server Concepts ..........................................................................................1209Chapter 40: SQL Server as an Access Companion ....................................................................1223Chapter 41: Upsizing Access Databases to SQL Server ..............................................................1249

Part VI: Appendixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1265Appendix A: Access 2007 Specifications ..................................................................................1267Appendix B: What’s on the CD-ROM ........................................................................................1275Appendix C: What’s New in Access 2007..................................................................................1279

Index ........................................................................................................................................1291Wiley Publishing, Inc. End-User License Agreement ................................................................1362

xi

02_046732 ftoc.qxp 11/21/06 8:43 AM Page xi

02_046732 ftoc.qxp 11/21/06 8:43 AM Page xii

Acknowledgments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxix

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xli

Part I: Access Building Blocks 1

Chapter 1: An Introduction to Database Development . . . . . . . . . . . . . 3The Database Terminology of Access ....................................................................................4

Databases ....................................................................................................................4Tables ..........................................................................................................................5Records and fields ......................................................................................................6Values ..........................................................................................................................6

Relational Databases ..............................................................................................................7Working with multiple tables ......................................................................................7Knowing why you should create multiple tables..........................................................7

Access Database Objects and Views ......................................................................................8Datasheets ..................................................................................................................8Queries........................................................................................................................9Data-entry and display forms ......................................................................................9Reports ......................................................................................................................10Designing the system’s objects ..................................................................................10

A Five-Step Design Method ................................................................................................10Step 1: The overall design — from concept to reality ................................................11Step 2: Report design ................................................................................................13Step 3: Data design: What fields are required? ..........................................................14Step 4: Table design ..................................................................................................17Step 5: Form design: Input ........................................................................................21

Summary ............................................................................................................................22

Chapter 2: Creating Access Tables . . . . . . . . . . . . . . . . . . . . . . . 23Getting Started with Access 2007 ........................................................................................23

The Templates section ..............................................................................................24The File menu ..........................................................................................................25

Creating a Database ............................................................................................................26

xiii

02_046732 ftoc.qxp 11/21/06 8:43 AM Page xiii

The Access 2007 Environment ............................................................................................29The Navigation Pane..................................................................................................30The ribbon ................................................................................................................32Other relevant features of the Access environment ....................................................33

Creating a New Table ..........................................................................................................35The importance of naming conventions ....................................................................36The table design process ............................................................................................37Using the Design ribbon tab ......................................................................................42Working with fields ..................................................................................................43

Creating tblContacts............................................................................................................51AutoNumber fields and Access ..................................................................................51Completing tblContacts ............................................................................................52

Changing a Table Design ....................................................................................................52Inserting a new field ..................................................................................................52Deleting a field ..........................................................................................................53Changing a field location ..........................................................................................53Changing a field name ..............................................................................................53Changing a field size..................................................................................................54Data conversion issues ..............................................................................................54Assigning field properties ..........................................................................................55

Understanding tblContacts Field Properties ........................................................................71Understanding the Lookup Property window ............................................................71

Setting the Primary Key ......................................................................................................72Understanding unique values ....................................................................................73Choosing a primary key ............................................................................................73Creating the primary key ..........................................................................................74Creating composite primary keys ..............................................................................74

Indexing Access Tables ........................................................................................................75The importance of indexes ........................................................................................76Multiple-field indexes................................................................................................78When to index tables ................................................................................................80Indexing tblContacts ................................................................................................80

Printing a Table Design........................................................................................................81Saving the Completed Table ................................................................................................82Manipulating Tables in a Database Window ........................................................................82

Renaming tables ........................................................................................................82Deleting tables ..........................................................................................................83Copying tables in a database......................................................................................83Copying a table to another database ..........................................................................84

Adding Records to a Database Table ....................................................................................85Understanding the Attachment Data Type ..........................................................................85Summary ............................................................................................................................86

xiv

Contents

02_046732 ftoc.qxp 11/21/06 8:43 AM Page xiv

Chapter 3: Designing Bulletproof Databases . . . . . . . . . . . . . . . . . . 87Data Normalization ............................................................................................................89

First normal form ......................................................................................................90Second normal form..................................................................................................92Third normal form ....................................................................................................96More on anomalies ....................................................................................................96Denormalization........................................................................................................97

Table Relationships..............................................................................................................98Connecting the data ..................................................................................................99One-to-one..............................................................................................................101One-to-many ..........................................................................................................102Many-to-many ........................................................................................................104Pass-through............................................................................................................105

Integrity Rules ..................................................................................................................106Understanding Keys ..........................................................................................................110

Deciding on a primary key ......................................................................................110Recognizing the benefits of a primary key................................................................112Designating a primary key ......................................................................................113Creating relationships and enforcing referential integrity ........................................115Viewing all relationships..........................................................................................120Deleting relationships ..............................................................................................121Application-specific integrity rules ..........................................................................121

Summary ..........................................................................................................................122

Chapter 4: Selecting Data with Queries . . . . . . . . . . . . . . . . . . . 123Understanding Queries ....................................................................................................123

What is a query?......................................................................................................124Types of queries ......................................................................................................126Query capabilities....................................................................................................127How recordsets work ..............................................................................................128

Creating a Query ..............................................................................................................128Using the Query window ........................................................................................130Navigating the Query Design window ....................................................................130Using the Query Design ribbon ..............................................................................130Using the QBE grid of the Query Design window....................................................131

Selecting Fields ................................................................................................................131Adding a single field ................................................................................................131Adding multiple fields ............................................................................................132

Displaying the Recordset ..................................................................................................134Working with Fields..........................................................................................................135

Selecting a field in the QBE grid ..............................................................................135Changing field order................................................................................................136Resizing columns in the QBE grid ..........................................................................136Removing a field......................................................................................................137

xv

Contents

02_046732 ftoc.qxp 11/21/06 8:43 AM Page xv

Inserting a field........................................................................................................137Providing an alias for the field name........................................................................137Showing a field........................................................................................................138

Changing the Sort Order ..................................................................................................139Displaying Only Selected Records ....................................................................................141

Understanding selection criteria ..............................................................................141Entering simple string criteria..................................................................................141Entering other simple criteria ..................................................................................143

Printing a Query’s Recordset ..............................................................................................144Saving a Query ..................................................................................................................145Adding More Than One Table to a Query..........................................................................145Working with the Table/Query Pane..................................................................................146

The join line ............................................................................................................146Manipulating the Field List window ........................................................................147Moving a table ........................................................................................................147Removing a table ....................................................................................................147Adding more tables ................................................................................................147

Adding Fields from More Than One Table ........................................................................148Viewing the table names ..........................................................................................148Adding multiple fields ............................................................................................149

Understanding Multi-Table Query Limitations ..................................................................149Updating limitations................................................................................................150Overcoming query limitations ................................................................................151

Creating and Working with Query Joins............................................................................151Joining tables ..........................................................................................................153Specify the type of join ............................................................................................153Deleting joins ..........................................................................................................155

Understanding Table Join Types ........................................................................................156Inner joins (equi-joins) ............................................................................................156Changing join properties ........................................................................................157Inner and outer joins ..............................................................................................158Creating a Cartesian product ..................................................................................159

Summary ..........................................................................................................................160

Chapter 5: Using Operators and Expressions in Access . . . . . . . . . . . 161What Are Operators? ........................................................................................................161

Types of operators....................................................................................................162Operator precedence ..............................................................................................173

Moving beyond Simple Queries ........................................................................................175Using query comparison operators ..........................................................................176Understanding complex criteria selection ................................................................177Using functions in select queries..............................................................................181Referencing fields in select queries ..........................................................................181

Entering Single-Value Field Criteria ..................................................................................181Entering character (Text or Memo) criteria ..............................................................182The Like operator and wildcards ............................................................................183

xvi

Contents

02_046732 ftoc.qxp 11/21/06 8:43 AM Page xvi

Specifying non-matching values ..............................................................................187Entering numeric (Number, Currency, or Counter) criteria......................................188Entering Yes/No (logic) criteria ................................................................................189Entering a criterion for an OLE object ....................................................................190

Entering Multiple Criteria in One Field ............................................................................190Understanding an Or operation ..............................................................................190Specifying multiple values for a field using the Or operator ....................................191Using the Or: cell of the QBE pane ..........................................................................192Using a list of values with the In operator................................................................192Understanding an And query ..................................................................................193Specifying a range using the And operator ..............................................................193Using the Between...And operator ..........................................................................194Searching for Null data ............................................................................................195

Entering Criteria in Multiple Fields ..................................................................................196Using And and Or across fields in a query ..............................................................196Specifying And criteria across fields of a query ........................................................197Specifying Or criteria across fields of a query ..........................................................198Using And and Or together in different fields ..........................................................199A complex query on different lines ..........................................................................199

Creating a New Calculated Field in a Query......................................................................200Summary ..........................................................................................................................201

Chapter 6: Working with Datasheet View. . . . . . . . . . . . . . . . . . . 203Understanding Datasheets ................................................................................................203The Datasheet Window ....................................................................................................205

Moving within a datasheet ......................................................................................206The Navigation buttons ..........................................................................................206The Datasheet ribbon ..............................................................................................207

Opening a Datasheet ........................................................................................................208Entering New Data ............................................................................................................208

Saving the record ....................................................................................................210Understanding automatic data-type validation ........................................................211Understanding how properties affect data entry ......................................................212

Navigating Records in a Datasheet ....................................................................................214Moving between records..........................................................................................214Finding a specific value ..........................................................................................215

Changing Values in a Datasheet ........................................................................................217Replacing an existing value manually ......................................................................217Changing an existing value ......................................................................................217Fields that you can’t edit..........................................................................................218

Using the Undo Feature ....................................................................................................219Copying and Pasting Values ..............................................................................................219Replacing Values................................................................................................................220Adding New Records ........................................................................................................221Deleting Records ..............................................................................................................221

xvii

Contents

02_046732 ftoc.qxp 11/21/06 8:43 AM Page xvii

Displaying Records............................................................................................................222Changing the field order..........................................................................................222Changing the field display width ............................................................................223Changing the record display height ........................................................................224Changing display fonts ............................................................................................225Displaying cell gridlines and alternate row colors ....................................................226Aligning data in columns ........................................................................................228Hiding and unhiding columns ................................................................................228Freezing columns ....................................................................................................229Saving the changed layout ......................................................................................229Saving a record ........................................................................................................229

Sorting and Filtering Records in a Datasheet ....................................................................229Using the QuickSort feature ....................................................................................230Using Filter by Selection..........................................................................................230Using Filter by Form ..............................................................................................233

Printing Records................................................................................................................233Printing the datasheet ..............................................................................................234Using the Print Preview window..............................................................................235

Summary ..........................................................................................................................235

Chapter 7: Creating Basic Access Forms . . . . . . . . . . . . . . . . . . . 237Adding Forms Using the Ribbon ......................................................................................237

Creating a new form ................................................................................................238Creating a split form................................................................................................239Creating a multiple-items form................................................................................240Creating a form using the Form Wizard ..................................................................241Creating a datasheet form ........................................................................................242Creating a blank form..............................................................................................243

Adding Controls................................................................................................................243Resizing the form area ............................................................................................244Saving the form ......................................................................................................244Understanding controls ..........................................................................................245The different control types ......................................................................................245The two ways to add a control ................................................................................247

Selecting Controls ............................................................................................................252Selecting a single control ........................................................................................253Selecting multiple controls ......................................................................................253Deselecting controls ................................................................................................253

Manipulating Controls ......................................................................................................254Resizing a control ....................................................................................................254Sizing controls automatically ..................................................................................255Moving a control ....................................................................................................255Aligning controls ....................................................................................................256Modifying the appearance of a control ....................................................................258Modifying the appearance of multiple controls ........................................................259Grouping controls ..................................................................................................259Deleting a control ....................................................................................................260

xviii

Contents

02_046732 ftoc.qxp 11/21/06 8:43 AM Page xviii

Attaching a label to a control ..................................................................................260Copying a control ....................................................................................................261Changing the control type ......................................................................................262

Understanding properties..................................................................................................262Displaying the Property Sheet..................................................................................263Understanding the Property Sheet ..........................................................................264Changing a control’s property setting ......................................................................264

Summary ..........................................................................................................................267

Chapter 8: Working with Data on Access Forms . . . . . . . . . . . . . . . 269Using Form View ..............................................................................................................269

The Form ribbon ....................................................................................................271Navigating between fields ........................................................................................272Moving between records in a form ..........................................................................273

Changing Values in a Form................................................................................................273Controls that you can’t edit......................................................................................274Working with pictures and OLE objects ..................................................................274Memo field data entry..............................................................................................276Date field data entry ................................................................................................276Using option groups ................................................................................................277Using combo boxes and list boxes ..........................................................................278Switching to Datasheet View....................................................................................278Saving a record ........................................................................................................279

Printing a Form ................................................................................................................279Using the Print Preview window..............................................................................280

Working with Form Properties ..........................................................................................280Changing the title bar text with the Caption property..............................................281Creating a bound form ............................................................................................282Specifying how to view the form..............................................................................282Eliminating the Record Selector bar ........................................................................284Other form properties..............................................................................................284

Adding a Form Header or Footer ......................................................................................290Changing the Layout ........................................................................................................291

Changing a control’s properties................................................................................291Setting the Tab Order ..............................................................................................292Aligning controls ....................................................................................................293Modifying the format of text in a control ................................................................293

Creating a Calculated Control ..........................................................................................295Converting a Form to a Report ..........................................................................................296Summary ..........................................................................................................................296

Chapter 9: Presenting Data with Access Reports . . . . . . . . . . . . . . . 297Understanding Reports......................................................................................................297

Understanding report types ....................................................................................297Distinguishing between reports and forms ..............................................................300Understanding the process of creating a report ........................................................301

xix

Contents

02_046732 ftoc.qxp 11/21/06 8:43 AM Page xix

Creating a Report with Report Wizards ............................................................................301Creating a new report ..............................................................................................302Selecting the grouping levels....................................................................................303Defining the group data ..........................................................................................304Selecting the sort order ............................................................................................304Selecting summary options......................................................................................305Selecting the layout ................................................................................................306Choosing the style ..................................................................................................307Opening the report design ......................................................................................307Using the Print Preview window..............................................................................308Viewing the Report Design window ........................................................................310

Printing a Report ..............................................................................................................310Saving the Report ..............................................................................................................311Starting with a Blank Form................................................................................................311

Layout view ............................................................................................................311Report Design view..................................................................................................312

Banded Report Writer Concepts ........................................................................................313The Report Designer sections ..................................................................................314

Creating a Report from Scratch..........................................................................................317Creating a new report and binding it to a query ......................................................319Defining the report page size and layout..................................................................320Placing controls on the report..................................................................................321Resizing a section ....................................................................................................322Working with text boxes and their attached label controls ......................................324Changing label and text box control properties ......................................................330Growing and shrinking text box controls ................................................................331Sorting and grouping data ......................................................................................332Sorting data within groups ......................................................................................333Adding page breaks ................................................................................................337

Making the Report Presentation Quality ............................................................................337Adjusting the Page Header ......................................................................................338Creating an expression in the group header ............................................................339Changing the picture properties and the Detail section............................................340Creating a standard page footer ..............................................................................341Saving your report ..................................................................................................343

Summary ..........................................................................................................................343

Part II: Programming Microsoft Access 345

Chapter 10: VBA Programming Fundamentals . . . . . . . . . . . . . . . . 347Understanding the Limitations of Macros ..........................................................................347Introducing Visual Basic for Applications ..........................................................................348Understanding VBA Terminology ......................................................................................349

xx

Contents

02_046732 ftoc.qxp 11/21/06 8:43 AM Page xx

Migrating from Macros to VBA ..........................................................................................351When to use macros and when to use VBA..............................................................351Converting existing macros to VBA..........................................................................352Using the Command Button Wizard to create VBA code..........................................354

Creating VBA Programs ....................................................................................................356Understanding events and event procedures............................................................357Understanding modules ..........................................................................................358Creating a new module............................................................................................360

Understanding VBA Branching Constructs ........................................................................368Conditional execution ............................................................................................369

Repetitive Looping ............................................................................................................372Working with Objects and Collections ..............................................................................374

The With statement ................................................................................................375The For Each statement ..........................................................................................376

Using Compiler Directives ................................................................................................377Access 2007 Options for Developers ................................................................................379

Editor tab in Options dialog box ............................................................................379The Project Properties dialog box ............................................................................380Command-line arguments ......................................................................................383

Summary ..........................................................................................................................384

Chapter 11: Mastering VBA Data Types and Procedures . . . . . . . . . . . 385The Access VBA Editor ......................................................................................................386Using Variables..................................................................................................................389

Naming variables ....................................................................................................390Declaring variables ..................................................................................................391

Working with Data Types ..................................................................................................395Comparing implicit and explicit variables................................................................397Forcing explicit declaration ....................................................................................399Using a naming convention ....................................................................................399Understanding variable scope and lifetime ..............................................................400

Understanding Subs and Functions ..................................................................................403Understanding where to create a procedure ............................................................404Calling VBA procedures ..........................................................................................404Creating subs ..........................................................................................................405

Creating Functions ............................................................................................................409Handling parameters ..............................................................................................409Calling a function and passing parameters ..............................................................411

Creating a Function to Calculate Taxes..............................................................................413Named arguments ..................................................................................................415

Summary ..........................................................................................................................416

xxi

Contents

02_046732 ftoc.qxp 11/21/06 8:43 AM Page xxi

Chapter 12: Understanding the Access Event Model . . . . . . . . . . . . . 417Programming Events ........................................................................................................417

How do events trigger VBA code? ............................................................................418Where to trigger event procedures ..........................................................................419

Common Events................................................................................................................420Form Event Procedures ....................................................................................................421

Primary form events ................................................................................................421Form mouse and keyboard events ..........................................................................423Form data events ....................................................................................................423Form PivotTable events ..........................................................................................424Form Access Data Project events..............................................................................425

Control Event Procedures..................................................................................................426Event Order ......................................................................................................................428

Opening a form with an event procedure ................................................................431Running an event procedure when closing a form ..................................................433Using an event procedure to confirm record deletion ..............................................434Using the MsgBox() function ..................................................................................435

Report Event Procedures ..................................................................................................438Running an event procedure as a report opens ........................................................438

Report Section Event Procedures ......................................................................................439Using the Format event ..........................................................................................440

Summary ..........................................................................................................................441

Chapter 13: Using Expressions in Queries and VBA Code . . . . . . . . . . 443Understanding Expressions ..............................................................................................443

The parts of an expression ......................................................................................445Creating an expression ............................................................................................448Special identifier operators and expressions ............................................................451Special keywords and properties..............................................................................454

Understanding Functions ..................................................................................................455Using functions in Access ........................................................................................455Types of functions....................................................................................................456Using the DLookUp() function for lookup tables ....................................................467

Summary ..........................................................................................................................469

Chapter 14: Accessing Data with VBA Code . . . . . . . . . . . . . . . . . 471Understanding SQL ..........................................................................................................471

Viewing SQL statements in queries ..........................................................................472An SQL primer ........................................................................................................473

Creating Programs to Update a Table ................................................................................480Updating fields in a record using ADO ....................................................................481Updating a calculated field for a record ..................................................................486Adding a new record ..............................................................................................490Deleting a record ....................................................................................................491Deleting related records in multiple tables ..............................................................492

Summary ..........................................................................................................................495

xxii

Contents

02_046732 ftoc.qxp 11/21/06 8:43 AM Page xxii

Chapter 15: Using the VBA Debugging Tools . . . . . . . . . . . . . . . . . 497Testing and Debugging Your Applications ........................................................................498Understanding the Sources of Errors ................................................................................499

Syntactical errors ....................................................................................................499Logical errors ..........................................................................................................501Runtime errors ........................................................................................................501Avoiding errors ........................................................................................................502

Using the Module Options ................................................................................................504Auto Syntax Check ..................................................................................................504Break on All Errors ..................................................................................................504Require Variable Declaration....................................................................................505Compile on Demand ..............................................................................................505Auto List Members ..................................................................................................505Auto Quick Info ......................................................................................................505Auto Data Tips ........................................................................................................506

Compiling VBA Code ........................................................................................................506Traditional Debugging Techniques ....................................................................................508

Using MsgBox..........................................................................................................508Using compiler directives ........................................................................................509Using Debug.Print ..................................................................................................511

Using the Access Debugging Tools ....................................................................................512Getting to know the Immediate window..................................................................512Running code with the Immediate window ............................................................512Suspending execution with breakpoints ..................................................................513Stepping through statements ..................................................................................515Using the Locals window ........................................................................................517Setting watches........................................................................................................518Using conditional watches ......................................................................................520Using the Call Stack window ..................................................................................521

Summary ..........................................................................................................................522

Part III: More Advanced Access Techniques 523

Chapter 16: Working with External Data . . . . . . . . . . . . . . . . . . . 525Access and External Data ..................................................................................................526

Types of external data ..............................................................................................526Methods of working with external data....................................................................526

Linking External Data........................................................................................................529Linking to external database tables ..........................................................................530Limitations of linked data ........................................................................................532Linking to other Access database tables ..................................................................533Linking to ODBC data sources ................................................................................536Linking to dBASE databases (tables) ........................................................................536Linking to Paradox tables ........................................................................................537

xxiii

Contents

02_046732 ftoc.qxp 11/21/06 8:43 AM Page xxiii

Linking to non-database data ..................................................................................537Splitting an Access database ....................................................................................542

Working with Linked Tables..............................................................................................543Setting view properties ............................................................................................543Setting relationships ................................................................................................544Optimizing linked tables ........................................................................................544Deleting a linked table reference..............................................................................544Viewing or changing information for linked tables ..................................................545

Using Code to Link Tables in Access ................................................................................546The Connect and SourceTableName properties........................................................546Checking links ........................................................................................................552

Summary ..........................................................................................................................554

Chapter 17: Importing and Exporting Data . . . . . . . . . . . . . . . . . . 555Types of Imports and Exports ............................................................................................555Importing External Data....................................................................................................557

Importing from another Access database ................................................................557Importing spreadsheet data ....................................................................................558Importing a SharePoint list ......................................................................................561Importing text file data ............................................................................................561Importing an XML document ..................................................................................569Importing an HTML document................................................................................570Importing Access objects other than tables ..............................................................571Importing an Outlook folder ..................................................................................572Importing through ODBC drivers ............................................................................572Importing non-Access, PC-based database tables ....................................................574Troubleshooting import errors ................................................................................576

Exporting to External Formats ..........................................................................................577Exporting objects to other Access databases ............................................................577Exporting through ODBC drivers ............................................................................578Functionality exclusive to exports............................................................................579

Summary ..........................................................................................................................580

Chapter 18: Advanced Access Query Techniques. . . . . . . . . . . . . . . 581Using Calculated Fields ....................................................................................................581Finding the Number of Records in a Table or Query ........................................................585Finding the Top (n) Records in a Query ............................................................................585How Queries Save Field Selections ....................................................................................587

Hiding (not showing) fields ....................................................................................587Renaming fields in queries ......................................................................................588Hiding and unhiding columns in Design View ........................................................589

Setting Query Properties....................................................................................................589Creating Queries That Calculate Totals ..............................................................................592

Query Wizard summaries ........................................................................................592Aggregate queries in Design View ............................................................................593Grand totals in aggregates........................................................................................595

xxiv

Contents

02_046732 ftoc.qxp 11/21/06 8:43 AM Page xxiv

Subtotals in aggregates ............................................................................................595Filtering aggregates with criteria ..............................................................................597

Crosstab Queries ..............................................................................................................599Duplicate and Unmatched Queries....................................................................................601

Find Duplicates Query Wizard ................................................................................601Find Unmatched Query Wizard ..............................................................................603

SQL-Specific Queries ........................................................................................................604Creating union queries ............................................................................................604Creating pass-through queries ................................................................................607Creating data definition queries ..............................................................................608Creating SQL subqueries in an Access query ..........................................................608

Action Queries ..................................................................................................................609Types of action queries ............................................................................................609Viewing the results of an action query ....................................................................610Action queries cannot be reversed ..........................................................................611Creating Action Queries ..........................................................................................611Troubleshooting action queries ................................................................................615

Summary ..........................................................................................................................616

Chapter 19: Advanced Access Form Techniques . . . . . . . . . . . . . . . 617Setting Control Properties ................................................................................................617

Customizing default properties................................................................................619Manipulating controls at runtime ............................................................................620Reading control properties ......................................................................................623

Working with Subforms ....................................................................................................624Form Design Techniques ..................................................................................................626

Using the Tab Stop property ....................................................................................626Tallying check boxes................................................................................................626Adding animation....................................................................................................627Using SQL for a faster refresh ..................................................................................628Selecting data for overtyping ..................................................................................628Toggling properties with Not ..................................................................................629Creating an auto-closing form ................................................................................629Combo box techniques............................................................................................630Determining whether a form is open ......................................................................631

Advanced Forms Techniques ............................................................................................632Page Number and Date/Time controls ....................................................................632Image control ..........................................................................................................633Control “morphing” ................................................................................................634Format Painter ........................................................................................................635Offering more end-user help....................................................................................635Adding background pictures ..................................................................................636Form events ............................................................................................................638

Using the Tab Control ......................................................................................................638Using Dialog Boxes to Collect Information ........................................................................641

Composing the SQL statement ................................................................................643Adding a default button ..........................................................................................644

xxv

Contents

02_046732 ftoc.qxp 11/21/06 8:43 AM Page xxv

Setting a Cancel button............................................................................................645Removing the control menu ....................................................................................645Closing the form......................................................................................................645

Summary ..........................................................................................................................646

Chapter 20: Advanced Access Report Techniques . . . . . . . . . . . . . . 647Hide Repeating Information ..............................................................................................648Alphabetically Group Data ................................................................................................650Group on Date Intervals ....................................................................................................654Create Numbered Lists ......................................................................................................655Add Bullet Characters........................................................................................................658Add Emphasis at Runtime ................................................................................................660Hide a Page Header ..........................................................................................................662Avoid Empty Reports ........................................................................................................663Start a New Page Number for Each Group ........................................................................664Avoid Null Values in a Tabular Report ..............................................................................664Add More Information to Report ......................................................................................665Add the User’s Name to a Bound Report............................................................................666Add Vertical Lines between Columns ................................................................................666Add a Blank Line Every n Records ....................................................................................668Even-Odd Page Printing ....................................................................................................670Display All Reports in a Combo Box..................................................................................672Use Different Formats in the Same Text Box ......................................................................674Fast Printing from Queried Data........................................................................................674Hide Forms during Print Preview ......................................................................................675A Few Quick Report Tips ..................................................................................................676

Center the title ........................................................................................................676Easily align control labels ........................................................................................676Micro-adjust controls ..............................................................................................676Always assign unique names to controls ..................................................................677

Use Snaking Columns in a Report ....................................................................................677Exploiting Two-Pass Report Processing..............................................................................682Summary ..........................................................................................................................684

Chapter 21: Building Multiuser Applications . . . . . . . . . . . . . . . . . 685Network Issues..................................................................................................................686

Network performance..............................................................................................686File location ............................................................................................................686Data sources ............................................................................................................688Special network situations ......................................................................................689

Database Open Options ....................................................................................................690Splitting Databases for Network Access ............................................................................692

Where to put which objects ....................................................................................696Using the Database Splitter add-in ..........................................................................696

Locking Issues ..................................................................................................................698Access’s built-in record-locking features ..................................................................699Default Open Mode ................................................................................................701

xxvi

Contents

02_046732 ftoc.qxp 11/21/06 8:43 AM Page xxvi

Number of Update Retries ......................................................................................701Update Retry Interval ..............................................................................................701Refresh Interval ......................................................................................................701ODBC Refresh Interval ............................................................................................702

Record-Lock Error Handling ............................................................................................702A function to handle lock errors ..............................................................................703Error 3260: Couldn’t update; currently locked by user . . . ......................................705Error 3186: Couldn’t save; currently locked by user x on machine y ......................709What about Error 3188?..........................................................................................711Error: 3197: Data has changed; operation stopped ..................................................712

Using Unbound Forms in Multiuser Environments ..........................................................714Creating an unbound form ......................................................................................715Making it work........................................................................................................716The Tag property ....................................................................................................716The form Open event ..............................................................................................716Moving through records ..........................................................................................718Editing data ............................................................................................................720

Summary ..........................................................................................................................722

Chapter 22: Integrating Access with Other Applications. . . . . . . . . . . 723Using Automation to Integrate with Office ........................................................................724

Creating Automation references ..............................................................................724Creating an instance of an Automation object..........................................................727Getting an existing object instance ..........................................................................728Working with Automation objects ..........................................................................729Closing an instance of an Automation object ..........................................................730

An Automation Example Using Word................................................................................730Creating an instance of a Word object......................................................................735Making the instance of Word visible ........................................................................736Creating a new document based on an existing template ........................................736Using Bookmarks to insert data ..............................................................................736Activating the instance of Word ..............................................................................737Moving the cursor in Word......................................................................................737Closing the instance of the Word object ..................................................................737Inserting pictures by using bookmarks ....................................................................737Using Office’s Macro Recorder ................................................................................738

Collecting Data with Outlook 2007 ..................................................................................740Creating an e-mail ..................................................................................................740Managing replies ....................................................................................................743

Summary ..........................................................................................................................747

Chapter 23: Integrating Access with SharePoint . . . . . . . . . . . . . . . 749What Is SharePoint? ..........................................................................................................749

What is SharePoint Services technology? ................................................................750What is a SharePoint Portal Server? ........................................................................750

SharePoint Applications: Types of Web Sites......................................................................751What Is a SharePoint List? ................................................................................................754

xxvii

Contents

02_046732 ftoc.qxp 11/21/06 8:43 AM Page xxvii

Introducing a SharePoint Services Web Site ......................................................................754Integrating Access 2007 and SharePoint ............................................................................758

Sourcing data from a SharePoint Services Web site ..................................................759Sourcing data from an Access database ....................................................................764

SharePoint and Different Operating Systems ....................................................................766SharePoint Lists as External Data ......................................................................................767Summary ..........................................................................................................................768

Chapter 24: Using ActiveX Controls. . . . . . . . . . . . . . . . . . . . . . 769Understanding Objects......................................................................................................769

Looking at the types of objects ................................................................................770Using bound and unbound objects..........................................................................770Linking and embedding ..........................................................................................771

Embedding Objects ..........................................................................................................772Embedding an unbound object ..............................................................................773Embedding bound objects ......................................................................................777Adding a bound OLE object ....................................................................................777Adding a picture to a bound object frame................................................................778Editing an embedded object ....................................................................................779

Linking Objects ................................................................................................................780Creating a Graph or Chart ................................................................................................782

The different ways to create a graph ........................................................................782Creating graphs using the Toolbox ..........................................................................783

Embedding a Graph in a Form..........................................................................................783Assembling the data ................................................................................................783Adding the graph to the form ..................................................................................784Customizing a graph ..............................................................................................791

Integration with Microsoft Office ......................................................................................792Checking the spelling of one or more fields and records..........................................792Using OLE automation with Office ..........................................................................793Creating an Excel-type PivotTable............................................................................793

Summary ..........................................................................................................................799

Chapter 25: Handling Errors and Exceptions . . . . . . . . . . . . . . . . . 801Dealing with Errors ..........................................................................................................801

Logical errors ..........................................................................................................802Runtime errors ........................................................................................................802

Which Errors Can Be Detected? ........................................................................................806What is an error handle?..........................................................................................806Setting a basic error trap..........................................................................................807

Trapping Errors with VBA ................................................................................................808The Error event ......................................................................................................809The ADO Errors collection ......................................................................................810The Err object..........................................................................................................812VBA Error statement variations................................................................................813

Summary ..........................................................................................................................820

xxviii

Contents

02_046732 ftoc.qxp 11/21/06 8:43 AM Page xxviii