100% found this document useful (1 vote)
9 views

Expert Access 2007 programming Rob Cooper pdf download

The document provides information about the book 'Expert Access 2007 Programming' by Rob Cooper and Michael Tucker, published by Wiley Publishing, Inc. It includes details on the book's content structure, covering programming applications, data manipulation, and application interaction, along with acknowledgments and author backgrounds. Additionally, it offers links to other related eBooks available for download.

Uploaded by

matievbrich
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
9 views

Expert Access 2007 programming Rob Cooper pdf download

The document provides information about the book 'Expert Access 2007 Programming' by Rob Cooper and Michael Tucker, published by Wiley Publishing, Inc. It includes details on the book's content structure, covering programming applications, data manipulation, and application interaction, along with acknowledgments and author backgrounds. Additionally, it offers links to other related eBooks available for download.

Uploaded by

matievbrich
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 82

Expert Access 2007 programming Rob Cooper pdf

download

https://ebookgate.com/product/expert-access-2007-programming-rob-
cooper/

Get Instant Ebook Downloads – Browse at https://ebookgate.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Expert Python Programming 2nd Edition Jaworski

https://ebookgate.com/product/expert-python-programming-2nd-edition-
jaworski/

ebookgate.com

Microsoft Office Access 2007 On Demand 1st Edition Steve


Johnson

https://ebookgate.com/product/microsoft-office-access-2007-on-
demand-1st-edition-steve-johnson/

ebookgate.com

Access Database Design Programming 3rd ed Edition Steven


Phd

https://ebookgate.com/product/access-database-design-programming-3rd-
ed-edition-steven-phd/

ebookgate.com

Expert Systems Principles and Programming fourth edition


Joseph Ciarratano

https://ebookgate.com/product/expert-systems-principles-and-
programming-fourth-edition-joseph-ciarratano/

ebookgate.com
Access 2007 All in One Desk Reference For Dummies 1st
Edition Alan Simpson

https://ebookgate.com/product/access-2007-all-in-one-desk-reference-
for-dummies-1st-edition-alan-simpson/

ebookgate.com

The Unofficial Guide to Microsoft Office Access 2007


Unofficial Guide 1st Edition Jim Keogh

https://ebookgate.com/product/the-unofficial-guide-to-microsoft-
office-access-2007-unofficial-guide-1st-edition-jim-keogh/

ebookgate.com

Microsoft Access VBA programming for the absolute beginner


3rd Edition Michael (Michael Vine) Vine

https://ebookgate.com/product/microsoft-access-vba-programming-for-
the-absolute-beginner-3rd-edition-michael-michael-vine-vine/

ebookgate.com

The Keys to the Universe Access the Ancient Secrets by


Attuning to the Power and Wisdom of the Cosmos Diana
Cooper
https://ebookgate.com/product/the-keys-to-the-universe-access-the-
ancient-secrets-by-attuning-to-the-power-and-wisdom-of-the-cosmos-
diana-cooper/
ebookgate.com

Programming for Unified Communications with Microsoft


Office Communications Server 2007 R2 1st Edition Rui
Maximo
https://ebookgate.com/product/programming-for-unified-communications-
with-microsoft-office-communications-server-2007-r2-1st-edition-rui-
maximo/
ebookgate.com
74029ffirs.qxd:WroxPro 9/27/07 7:38 PM Page v

Expert
Access™ 2007 Programming

Rob Cooper and Michael Tucker

Wiley Publishing, Inc.


74029ffirs.qxd:WroxPro 9/27/07 7:38 PM Page ii
74029ffirs.qxd:WroxPro 9/27/07 7:38 PM Page i

Exper t Access ™ 2007 Programming


Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv

Part I: Programming Access Applications . . . . . . . . . . . . . . . . . 1


Chapter 1: Overview of Programming for Access. . . . . . . . . . . . . . . . . . . . . . . 3
Chapter 2: Extending Applications Using the Windows API . . . . . . . . . . . . . . 11
Chapter 3: Programming Class Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Chapter 4: Debugging, Error Handling, and Coding Practices . . . . . . . . . . . . 105
Part II: Data Manipulation 145
Chapter 5: Parsing Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Chapter 6: Using SQL to Retrieve Data and Manipulate Objects . . . . . . . . . 193
Chapter 7: Managing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
Part III: Interacting with the Application 297
Chapter 8: Using Code to Add Advanced Functionality to Forms . . . . . . . . . 299
Chapter 9: Using Code to Add Advanced Functionality to Reports . . . . . . . . 357
Chapter 10: Using Automation to Add Functionality . . . . . . . . . . . . . . . . . . 387
Chapter 11: Creating Dynamic Ribbon Customizations . . . . . . . . . . . . . . . . 441
Part IV: Finalizing the Application 489
Chapter 12: Configuration and Extensibility . . . . . . . . . . . . . . . . . . . . . . . . 491
Chapter 13: Personalization and Security . . . . . . . . . . . . . . . . . . . . . . . . . . 525
Chapter 14: Deployment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 559
Chapter 15: Help and Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 613
Appendix A: Programming Tips and Tricks . . . . . . . . . . . . . . . . . . . . . . . . . 637
Appendix B: Query Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 657
Appendix C: Pattern Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673
74029ffirs.qxd:WroxPro 9/27/07 7:38 PM Page ii
74029ffirs.qxd:WroxPro 9/27/07 7:38 PM Page iii

Expert
Access™ 2007 Programming
74029ffirs.qxd:WroxPro 9/27/07 7:38 PM Page iv
74029ffirs.qxd:WroxPro 9/27/07 7:38 PM Page v

Expert
Access™ 2007 Programming

Rob Cooper and Michael Tucker

Wiley Publishing, Inc.


74029ffirs.qxd:WroxPro 9/27/07 7:38 PM Page vi

Expert Access™ 2007 Programming


Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2008 by Wiley Publishing, Inc., Indianapolis, Indiana
ISBN: 978-0-470-17402-9
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
Library of Congress Cataloging-in-Publication Data is available from the publisher.
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 of the 1976 United States Copyright Act, without either the prior written permis-
sion of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright
Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to
the Publisher for permission should be addressed to the Legal Department, 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 no representations or war-
ranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all
warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be
created or extended by sales or promotional materials. The advice and strategies contained herein may not
be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in
rendering legal, accounting, or other professional services. If professional assistance is required, the services
of a competent professional person should be sought. Neither the publisher nor the author shall be liable for
damages arising herefrom. The fact that an organization or Website is referred to in this work as a citation
and/or a potential source of further information does not mean that the author or the publisher endorses
the information the organization or Website may provide or recommendations it may make. Further, readers
should be aware that Internet Websites listed in this work may have changed or disappeared between when
this work was written and when it is read.

For general information on our other products and services please contact our Customer Care Department
within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, 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. Microsoft and Access are trade-
marks or registered trademarks of Microsoft Corporation in the United States and/or other countries. All other
trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any prod-
uct 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 in electronic books.
74029ffirs.qxd:WroxPro 9/27/07 7:38 PM Page vii

To my family, Sandi, Isabel, Gillian, and Taryn for their support and patience over the years.

— Rob Cooper

To my family, and to everyone who shares my love for data.

— Michael Tucker
74029ffirs.qxd:WroxPro 9/27/07 7:38 PM Page viii

About the Authors

Rob Cooper is a Test Lead on the Access team at Microsoft. He started at Microsoft as a support engineer in
Charlotte, North Carolina in 1998 and joined the Access 2003 test team in Redmond in 2001. During the
Access 2007 release, he led the security efforts across the test team and worked on several new features
including disabled mode, database encryption, Office Trust Center, and sorting, grouping, and totals. Rob
also led efforts around the Access object model and continues to provide direction around programmability
and security in Access.

A long-time fan of Access, Rob is a frequent speaker at the Seattle Access Group and PNWADG meet-
ings and has written for the Microsoft Knowledge Base and Access Advisor. Aside from writing code in
Access and C#, he also enjoys spending time with his family watching movies, going to the zoo and
aquarium, and hanging out in and around Seattle.

Michael Tucker is a Software Design Engineer on the Microsoft Access test team in Redmond. He joined
Microsoft in 1993 as a Product Support Engineer supporting the very first release of Microsoft Access,
and has been passionate about Access ever since. During the Access 2007 release, he worked on the new
ACE database engine, and owned the complex data and SharePoint workflow integration features.

Michael designed and coordinated implementation of the test automation infrastructure used by the test
team. He also has previous experience as a Test Lead and Program Manager on a variety of products at
Microsoft. His specialties include SQL, data normalization, and object model design, and anything
related to his passions for airplanes, airports, and traveling the world.
74029ffirs.qxd:WroxPro 9/27/07 7:38 PM Page ix

Credits
Executive Editor Vice President and Executive Group Publisher
Robert Elliott Richard Swadley

Development Editor Vice President and Executive Publisher


Ed Connor Joseph B. Wikert

Technical Editors Project Coordinator, Cover


Oliver Stohr and Matt Bumgarner Lynsey Osborn

Production Editor Compositor


Daniel Scribner Craig Woods, Happenstance Type-O-Rama

Copy Editor Proofreader


Nancy Rapoport Sossity Smith

Editorial Manager Indexer


Mary Beth Wakefield Ron Strauss

Production Manager Anniversary Logo Design


Tim Tate Richard Pacifico
74029ffirs.qxd:WroxPro 9/27/07 7:38 PM Page x

Acknowledgments

The authors would like to thank the following individuals who really made this possible. First of all to
Teresa Hennig for helping us get set up on this project. By giving us the opportunity to work on the last
book, you helped lead to this one. To our incredible tech editors, Oli Stohr and Matt Bumgarner. Your
insight and suggestions really make this book what it is and we are grateful for your hard work and
keen eyes! To Kevin Nickel on the Access test team who gave us some great suggestions and considera-
tions as we were beginning to flush out the content.

We’d also like to thank everyone at Wiley who helped bring this together, in particular Bob Elliott for
getting us started and guiding us through the process. Special appreciation goes out to our development
editor Ed Connor who helped us make sure that the content and tone was accurate and for keeping us
on track.

Lastly, but certainly not least, to the Access team at Microsoft. The incredible amount of passion, hard work,
and dedication that went into the Access 2007 release from everyone involved is nothing short of amazing.

Rob Cooper

I’d like to thank my children, Isabel and Gillian, who were even more patient and more understanding
than they were for the last book—you continue to inspire me! Thanks to my wife, Sandi, for her support
during all of the late nights and weekends. I’m free to do yard work again!

Thanks to my co-author Michael for keeping me in check and helping me make sure that we covered
things that we felt should be covered. Thanks in particular for your great suggestions and for setting the
tone for the SQL and Data chapters!

Extra thanks to Bob Elliott at Wiley for his insight and wisdom as I was taking on this role. Your
patience, understanding and willingness to help were greatly appreciated.

Huge thanks to everyone on the Access product team at Microsoft — without you and your hard work
on a great release of Access 2007, this wouldn’t have been possible! To Sherri Duran for her continued
support while I worked this project.

Lastly but certainly not least, thanks to the Access community, particularly the amazing people at
utteraccess.com. It’s truly an honor to be a member of a community of people who are as passionate
about Access as we are, and to the Seattle Access Group and Pacific Northwest Access Developer’s
Group for allowing me to come listen and speak from time to time.

Michael Tucker

To my family, whom I don’t see often enough, but who are never out of my thoughts: Mom and Dad,
Mike and Margie, Shari, Kimberlee, Heidi, Danna, Holly, Kathlee, Rayne and Ann. Monica and Jason
and their little Archer, Scott, Kittridge, and Markus: thank you for your friendship, constant kind words
of encouragement, thought-provoking conversations, and nudges.
74029ffirs.qxd:WroxPro 9/27/07 7:38 PM Page xi

My co-author and colleague Rob Cooper has been an inspiration ever since I returned home to the
Access team. His knowledge of Access is encyclopedic, and his enthusiasm and passion are infectious.
I am honored and privileged to have been invited to join him on this project.

To all of the amazing professionals on the Microsoft Access product team who daily put so much energy
into making an amazing product even more so, thank you for your inspiration. The most satisfying thing
about working at Microsoft is being surrounded by so many amazing minds from around the world, who
bring a myriad of talents and varied perspectives. To Mike Garlick and Sherri Duran who welcomed me
home, I will always be in your debt. To Anderson Dupree, who was my first Best Manager; Steve Alboucq
who opened doors to the product team; and Mark Langley who mentored me into management, my grati-
tude for your support and guidance.

Finally, my appreciation to all the Access users I’ve had the privilege to work with over the last 14 years.
You never cease to amaze me with the unusual, often creative, and occasionally inspirational ways you
use our product. I remember fondly a small and select group of particularly memorable customers who
made my time in product support especially interesting: my psychic friends in Florida, a certain banker
in San Diego who taught me the value of scaled integers, the OSHA man in Portland who shares my
passion for aviation, and the lovely lady from AT&T in Chicago who proved once and for all that every-
thing is relative.
74029ffirs.qxd:WroxPro 9/27/07 7:38 PM Page xii
74029ftoc.qxd:WroxPro 9/27/07 1:40 PM Page xiii

Contents
Acknowledgments x
Introduction xxv

Part I: Programming Access Applications 1


Chapter 1: Overview of Programming for Access 3
Writing Code for Access 3
The Access Object Model 4
The DAO Object Model 4
The ADO Object Model 4
Object-Oriented Thinking 4
Windows API Programming 5
Working with Managed Code 5
What Is Managed Code? 6
Versions of Visual Studio 6
Writing Managed Code Libraries to Use with Access 6
Referencing the Access Object Model from Managed Code 7
Referencing Other Applications 7
Discovering References 8
Adding References to Office Applications 8
Summary 9

Chapter 2: Extending Applications Using the Windows API 11


Windows API Overview 11
Why Use API Functions 12
API Resources 12
Writing Declare Statements 13
Example Conversion 17
Error Messages from API Functions 18
Retrieving System Information 19
Return the User Name in Different Formats 19
Return the Computer Name in Different Formats 21
Retrieve the Command Line 21
Windows Shell Functions 24
Get the Path to a Special Folder 24
Show the Property Dialog Box for a File 25
Determine Whether a Computer Is Connected to the Internet 27
Determine Whether a User Is an Administrator 27
74029ftoc.qxd:WroxPro 9/27/07 1:40 PM Page xiv

Contents
Controlling Processes and Threads 28
Determining the Current Process ID 28
Pausing Code Execution 29
Quitting a Process 29
Waiting for a Process to Complete 32
Windows Vista Task Dialogs 35
Introduction to Task Dialogs 35
A Simple Message Box Replacement 37
More Complex Task Dialogs 40
Icons 56
Miscellaneous API Functions 57
Creating a GUID 58
ShellExecute Tricks 59
Summary 60

Chapter 3: Programming Class Modules 63


Overview of Class Modules 63
Why Use Class Modules? 64
Class Module Members 65
Code Reuse in VBA 73
Subclassing 76
Subclassing Access Forms and Reports 76
Sinking Form Events 77
Interfaces 80
Inheritance in VBA 81
Specialization 83
Testing the Type of an Object 83
Collections 85
Writing the Standard Collection Class 86
An Alternate Implementation for the Add Method 89
Setting a Default Member 91
For Each Enumeration 91
The ICollectionEx Interface 92
Events 96
Why Write Custom Events? 96
Creating Custom Events 97
Listening for Custom Events 98
Design Considerations 99
Copying a Class Instance 100
Exposing the Interface of a Derived Type 101
Raising Errors 102
Summary 104

xiv
74029ftoc.qxd:WroxPro 9/27/07 1:40 PM Page xv

Contents

Chapter 4: Debugging, Error Handling, and Coding Practices 105


Debugging 106
Using Watches 106
Using the Watches Window 108
Using the Immediate Window 109
Using the Locals Window 110
Viewing the Call Stack 110
Building a Call Stack Using Code 111
Assertions 115
Creating a Debug Build 120
Error Handling 123
Handling Errors Inline 123
Categorizing Errors 124
System Error Codes and HRESULTS 124
Creating an Error Handler Class 125
Logging Errors 129
Using the Error Handling Class and Logging 135
Coding Practices 136
Readability 136
Version Control 139
Refactoring 139
Code Reviews 142
Summary 142

Part II: Data Manipulation 145


Chapter 5: Parsing Data 147
File Input/Output 147
Using VBA I/O statements 148
Using FileSystemObject 157
Determining Whether a File Is ANSI, Unicode, or UTF-8 160
Splitting Strings 164
The VBA String Handling Functions 165
Replacing Tokens in Strings 169
Formatted Token Replacement 170
Parsing into Data Types 171
An End-to-End Example 174
Splitting Names 178
Address Element Granularity 180
Phone Number Granularity 182

xv
74029ftoc.qxd:WroxPro 9/27/07 1:40 PM Page xvi

Contents
Creating HTML 182
Exporting HTML Files 182
Why Create HTML Using Code? 187
Creating HTML Files 188
Summary 192

Chapter 6: Using SQL to Retrieve Data and Manipulate Objects 193


Where SQL Can Be Used in Access 194
Form and Report Recordsets 194
Partial SQL Properties 194
The Various Types of SQL Queries 195
The SELECT Query 196
Project Your Columns: the Field List 197
Choose Your Tables: The FROM Clause 203
Filter Your Data: The WHERE Clause 205
Sort Your Results: The ORDER BY Clause 216
Add Data from More Than One Table Using Table Joins 218
Inner Joins 219
Outer Joins 220
Joining More Than Two Tables Using Nested Joins 222
Self Joins 224
Cartesian Products 225
Prompt Users for Data with Parameters 227
Add Data from Other Databases Using the IN Clause 230
Selection Predicates 231
ALL Predicate 231
TOP Predicate 231
DISTINCT Predicate 233
Aggregating Data 234
Bucket Your Data: The GROUP BY Clause 234
Filter Your Data Based on Bucketed Data: the HAVING Clause 237
Action Queries 238
Make Table Query 239
Append Query 240
UPDATE Query 243
DELETE Query 245
Crosstab Queries 246
Ordering Column Headings 248
Common Expressions Used with Crosstab Queries 249
UNION Queries 251
Sorting a UNION Query 252
Using the Designer to Create Union Queries 253

xvi
74029ftoc.qxd:WroxPro 9/27/07 1:40 PM Page xvii

Contents

Subqueries 253
Data Definition Queries 254
Create Table 255
Alter Table 257
Drop Table 258
Create Index 258
Drop Index 259
Alter Database Password 259
SQL Pass-Through Queries 259
Running Ad Hoc SQL Pass-Through Queries 260
ANSI Mode 261
String Pattern Matching Using ANSI-92 Syntax 261
Summary 261

Chapter 7: Managing Data 263


Finding Data 263
Find Methods 264
Seek Method 266
Move Methods 268
Search Optimization Tips 271
Categorization and Sorting 272
Categorization Using the Choose Function 273
Using a Custom Sort Order Field 273
Backup and Restore 276
Using Checksum Functions 278
MD5 Algorithm 279
Mod-10 Checksum 279
Access 2007 Specifics 285
Locale-Agnostic Parser for ColumnHistory Function 285
Getting a List of Attachments in an Attachment Field 289
Searching for Records with Attachments 292
Searching for Specific Attachments 294
Summary 296

Part III: Interacting with the Application 297


Chapter 8: Using Code to Add Advanced Functionality to Forms 299
Working with Form Events 299
How to Determine When Data Is Added 300
How to Determine When Data Is Changed 301

xvii
74029ftoc.qxd:WroxPro 9/27/07 1:40 PM Page xviii

Contents
How to Determine When Data Is Deleted 301
Validating Form Data 302
Suppressing Access Error Messages 304
How to Determine If a Modifier Key Is Pressed 305
Periodic Backups Using the Timer Event 306
Moving a Form Without a Border 307
Customizing ControlTipText 308
Working with Controls 309
Validating Control Data 309
Disabling all Controls 310
Reusing a Subform Control 310
Extended List Box Functionality 311
Custom Progress Bars 319
Custom Up/Down Buttons 321
Displaying Multiple Attachments Onscreen 322
Common Forms for Your Applications 324
Dynamic Menu Forms and Dashboards 324
Splash Screens 349
About Dialog Boxes 351
Kiosk Forms 351
Custom Form Navigation 352
Navigation Bars 352
“I Need To” Drop-Down 354
Keyboard-Driven Navigation 355
Summary 356

Chapter 9: Using Code to Add Advanced Functionality to Reports 357


Interactive Reports Using Access 2007 357
Sorting a Report Using Controls on a Report 358
Filtering a Report Using Controls 360
Drill-Down 363
Navigating to a Map Dynamically 365
Report Scenarios 366
Creating a Report with Data Bars 366
Creating a Calendar Report 370
Displaying Images Using an Attachment Field 377
Displaying Images Dynamically Using a Path 378
Creating a Report Manager 379
Creating the Reports Table 380
Implementing Report Manager Features 381
Summary 386

xviii
74029ftoc.qxd:WroxPro 9/27/07 1:40 PM Page xix

Contents

Chapter 10: Using Automation to Add Functionality 387


Automation Basics 387
When to Automate 388
Shell Function 388
CreateObject vs. GetObject 389
Early Binding vs. Late Binding 389
Discovering Object Models Using Built-in Tools 390
Automating Windows 391
The Shell Object 392
Windows Scripting Host 395
Automating Office Applications 409
Determining If an Office Application Is Installed 409
Word: Creating a Formatted Letter with Data 412
Excel: Creating an Excel Chart with Data 421
Outlook: Create Appointments from an Events Database 429
Automating Internet Explorer 432
Opening a URL in a New Tab in IE7 432
Common Web Queries 433
Parsing HTML from Internet Explorer 435
Summary 440

Chapter 11: Creating Dynamic Ribbon Customizations 441


Overview of Ribbon Customizations in Access 441
Development Tips 442
How to Write Ribbon Customizations 444
Loading Ribbons 446
Using the USysRibbons Table 447
Using the LoadCustomUI Method 448
Programming the Ribbon 449
Ribbon Objects 449
Using Callback Routines 449
Refreshing Controls 452
Organizing Ribbon Items 453
Tabs 453
Contextual Tabs 453
Groups 454
Ribbon Controls 454
Buttons 455
Toggle Buttons 455
Check Boxes 456

xix
74029ftoc.qxd:WroxPro 9/27/07 1:40 PM Page xx

Contents
Combo Boxes and Drop-Downs 457
Labels and Edit Boxes 458
Menus 458
New Types of Controls 460
Dialog Box Launcher 460
Gallery 461
Split Button 462
Dynamic Menu 462
Images 462
Images Included with Office 462
Loading Images from External Files 463
Loading Images from an Attachment Field 468
Moving Functionality into the Ribbon 469
The NotInList Event — Ribbon Style 470
Form Navigation 472
Managing Filters Using a Dynamic Menu 477
Creating a Split Button That Sticks 482
Other Ribbon Modifications 484
Modifying the Office Menu 484
Overriding Commands and Repurposing Controls 485
Summary 486

Part IV: Finalizing the application 489


Chapter 12: Configuration and Extensibility 491
Localization 491
Locale Settings 492
Determining the Current Language of Office 494
How to Create Localized Access Applications 494
Application Options 506
Storing Options in Tables 508
Storing Options in the Registry 508
Creating a Class to Work with Options 509
Creating Options Forms 513
Displaying Options in the Ribbon 516
Creating Form Themes 518
Theming Forms 518
Summary 523

xx
74029ftoc.qxd:WroxPro 9/27/07 1:40 PM Page xxi

Contents

Chapter 13: Personalization and Security 525


What Is Security? 525
Authentication 526
Authorization 527
What Is Personalization? 527
Overview of Security in Access 2007 527
Database Encryption 527
Disabled Mode 528
Office Trust Center 529
Digital Signatures 531
Signed Packages 531
Access 2007 Navigation Pane 533
Customizing the Navigation Pane 533
Restricting the View of the Navigation Pane 536
Hiding the Design Surface of Objects 539
Password-Protecting Objects 539
Creating the User Table 540
Creating the Login Form 540
Prompting for Password with Forms and Reports 544
Creating a Password Protected Form Object 545
Windows Integration 546
Determining the Logon Name 547
Locking the Computer 548
Receiving Notifications When the Computer Is Locked or Unlocked 548
Simulating Record Level Security 551
Limiting the View to a Particular User 551
Locking Records Based on Logon 552
Database Encryption with DAO and ADO 553
Creating an Encrypted Database with DAO 553
Changing the Database Password with DAO 553
Adding a Database Password to a Database with DAO 554
Changing the Database Password with ADO 555
Best Practices 556
Using a Client-Server Database to Protect Data 556
AllowBypassKey Property 556
Using an ACCDE or MDE File 557
Using an ACCDR File 557
File Format Selection 557
Summary 558

xxi
74029ftoc.qxd:WroxPro 9/27/07 1:40 PM Page xxii

Contents
Chapter 14: Deployment 559
Creating an Automated Build 559
Creating the Visual Studio Project 560
Building the Application 571
Handling Application Dependencies 578
Installing Files from an Attachment Field 579
Updating References 581
Testing Reference Fix-Up 583
Late Binding 584
Licensing Your Applications 585
Creating a Limited-Use Application 585
Registering an Application 590
Miscellaneous Deployment Scenarios 596
Updating Your Applications 596
Programmatically Creating DSNs 607
Ensuring an Application Runs Locally 610
Summary 612

Chapter 15: Help and Documentation 613


Documentation via Built-in Properties 613
Using the Description Property 614
End SubSetting the Status Bar Text 619
Using the Tag Property 620
Setting the Control Tip 620
Database Documenter 621
Providing Help to Users 621
Storing Help Text in a Table 621
Creating a Help Form 622
Trapping the F1 Key 623
Alternatives to a Floating Help Window 624
External Approaches 625
Writing HTML Content for Help 625
Mapping HTML Files to Objects 627
Opening the Browser 628
Creating Compiled HTMLHelp Files 631
Summary 635

xxii
74029ftoc.qxd:WroxPro 9/27/07 1:40 PM Page xxiii

Contents

Appendix A: Programming Tips and Tricks 637


Dynamically Running Code 637
CallByName 637
Application.Run 641
Eval 641
Object Helper Functions 641
Object Initialization 642
Object Termination 643
Global Object Properties 644
Date Data Type Tricks 644
Looping Through Dates 645
Arrays of Dates 646
Determining Dates Dynamically 646
Miscellaneous Tips 647
Categorizing Constant Values 647
Comparing Class Instances 648
Add Number of Retries to a Code Block 649
Add a Timeout to a Code Block 650
Tools for the Immediate Window 651
Clearing the Immediate Window 652
Displaying the Watch Window 652
Displaying the Locals Window 652
Making a Backup of Objects 653
Closing All Code Windows 654

Appendix B: Query Performance 657


The Query Optimizer 657
Designing Tables for Performance 658
Use the Smallest Appropriate Data Type 658
Indexes 658
Designing Queries for Performance 659
Reduce the Amount of Data 659
Other Performance Considerations 662
Bulk Edits 662
Minimize Network Traffic 662
Database Maintenance 663
Hard Drive Maintenance 663
Microsoft Access Performance Analyzer 663

xxiii
74029ftoc.qxd:WroxPro 9/27/07 1:40 PM Page xxiv

Contents
Appendix C: Pattern Reference 665
Introducing Patterns 665
What Is a Pattern 665
Why Use Patterns? 666
Patterns Used in This Book 666
Gang of Four Patterns 666
VBA Object Patterns 667
Other Patterns 669
Working with Strings 670
Where and How to Find Patterns 671

Index 673

xxiv
74029flast.qxd:WroxPro 9/27/07 1:42 PM Page xxv

Introduction

The largest release of Access in five years, Access 2007 includes many new features that you can leverage
both in your own development work and as application features that you can pass along to your users.
This book discusses new features such as developing for the Ribbon and the Attachment control, as well
as new ways of looking at old problems such as automation, debugging, and deployment. It aims to fill
the gaps between casual Access development and professional Access development. We wrote this book
as a tribute to the product that we’ve come to use every day. It represents a labor of love for the years
that we have spent working with Access both at Microsoft and prior to joining Microsoft.

Building Off-the-Shelf Applications


Throughout this book, we discuss several topics that contribute to off-the-shelf quality. Off-the-shelf is a
term used to describe software that is typically available for release to the public. This doesn’t necessar-
ily mean that the software is available commercially (although it could). Even departmental or larger
scale internal applications can benefit from features such as configuration (discussed in Chapter 12), and
deployment (discussed in Chapter 14). We live in a global marketplace. If you are developing databases
for use by people in locales other than your own, you might be particularly interested in Chapter 12,
where we will also discuss localization.

Forms are essential to most Access applications. Forms are used for everything from displaying and
validating data, to splash screens, to About dialog boxes. You will learn about creating different types of
forms such as these in Chapter 8. It doesn’t stop there, however. You will also learn about how to create
custom navigation solutions for forms to provide intuitive experiences for your users. In many solu-
tions, seeing an error message from Access is less than desirable so you will also learn how to suppress
Access error messages to provide your own. We also discuss using Form events to validate data; detect
when records are added, updated, or deleted; and much, much more.

But let’s not forget about reports! Reports are also an integral feature of Access solutions. They provide
another mechanism for presenting information to the user and are optimized for printing. Access 2007
includes a new view for reports called Report view, which allows users to interact with reports as never
before. You will learn how to use Report view to create compelling scenarios for your users such as sort-
ing and filtering. You no longer need to use a separate form to sort or filter reports. Features such as this
are discussed in Chapter 9.

A Little Background
We both started our careers at Microsoft in what was then known as Product Support Services (PSS) as
members of the Access support team. Learning Access from the support perspective was extremely valuable.
For starters, calls didn’t come in because Access was working just fine! People tend to call when something
is broken or they have questions about how to implement a piece of functionality. This breadth of knowl-
edge led to developing common methods for working with a particular task. Upon making the transition to
testing Access, we learned development practices that were in place on a large software project. It is largely
these practices that we implement in our Access development projects.
74029flast.qxd:WroxPro 9/27/07 1:42 PM Page xxvi

Introduction

Whom This Book Is For


This book is primarily geared toward intermediate to advanced Access programmers using VBA and
SQL. Some of the concepts apply to VBA as a language and not to one application in particular. As a
result, VBA programmers using other tools such as Excel or Word may also find some of the topics use-
ful. Familiarity with Access 2007 is helpful but not required. New features mentioned in Access 2007 are
called out as such and explained throughout. You’ll find that several of the concepts apply to previous
versions of Access as well.

This book contains some examples written in managed code using Visual C#. A basic familiarity with
this language will be helpful for those examples. The code available for download with this book
includes managed code samples in both Visual C# and Visual Basic .NET.

Some experience with XML will be useful for Chapter 11.

What This Book Covers


Expert Access 2007 Programming aims to show you how to create off-the-shelf quality applications using
Access that are fun to write, feature-rich, and easy to use. Several of the techniques covered in this book
are used to develop Access itself at Microsoft such as using assertions, build numbers, and classes. Some
techniques such as handling exceptions are also closely tied to the work we do with managed code. We
have adapted these techniques to apply to the process of writing Access-based applications, and these
are techniques we implement in our own solutions. Employing these techniques, even in Access-based
solutions, can simplify the development process and provide consistency across multiple applications.

How This Book Is Str uctured


This book is structured in four parts with either three or four chapters in each part. This book is meant to
walk you through the important steps in creating a full-featured application. As such, it is designed to be
read sequentially from beginning to end.

Part I: Programming Access Applications


The chapters in Part I are designed to provide the foundations of programming Access applications.
Chapters 2 through 4 apply to VBA developers, regardless of the application.

❑ Chapter 1, “Overview of Programming for Access,” describes in broad strokes what it means to
write applications for Access. Often, this means writing VBA code in a particular database, but
there may also be times when you are required to write applications that target Access, for
example, using managed code. This chapter discusses some of the basics of working with man-
aged code, in particular C# and VB.NET.
❑ Chapter 2, “Extending Applications Using the Windows API,” provides information about
using API functions that are defined in Windows, and then provides many useful examples of
API functions that you can use in your Access applications.

xxvi
74029flast.qxd:WroxPro 9/27/07 1:42 PM Page xxvii

Introduction
❑ Chapter 3, “Programming Class Modules,” gives you in-depth information about writing class
modules for use in your applications. The chapter begins with an overview of writing class
modules in Access, and then jumps right in to using them to extend, and even simplify, pro-
gramming tasks. The chapter ends with defining events that you can use as notification when
particular conditions are met.
❑ Chapter 4, “Debugging, Error Handling, and Coding Practices,” provides a detailed look at
debugging VBA applications and extending debugging to make it work for you.

Part II: Data Manipulation


With a new version of the Access database engine (formerly known as Jet) and built-in support for other
database engines, it’s an understatement to say that Access applications are well suited for data. In Part II,
we move into the nitty-gritty of Access development — data. The chapters in Part II describe working
with data in many different forms.

❑ Chapter 5, “Parsing Text and HTML,” starts out with an in-depth look at working with data in
different types of files using VBA I/O statements and the FileSystemObject. Along the way,
it shows you how to determine the byte order mark of a file to determine whether a text file is
ANSI or Unicode. The chapter then discusses working with strings and how to parse data into
various data types. It ends with a look at generating formatted HTML.
❑ Chapter 6, “Using SQL to Retrieve Data and Manipulate Objects,” shows you how to use SQL
to do just about anything. It begins with a discussion about places in Access where SQL can be
used and the different types of queries that can be created. It then goes into the details of the
SELECT statement. It also shows you how to work with other query types such as crosstab and
action queries, and ends with data-definition and SQL pass-through queries.
❑ Chapter 7, “Managing Data,” shows you how to find data in a database, as well as how to
categorize data and create a custom sort field. Creating a backup of data in the database is an
important task and the chapter describes a mechanism for archiving and backing up records in
the database. This chapter ends with examples that target new features in Access 2007: append-
only memo fields and attachment fields.

Part III: Interacting with the Application


Once data is stored in the database, your users will need a way to view the data and interact with it. This is
where Part III comes in. The chapters in Part III are designed to make interfaces and functionality that pop.

❑ Chapter 8, “Using Code to Add Advanced Functionality to Forms,” shows you how to create
reusable forms for your applications such as dynamic menu screens and dashboards, as well
as splash screens and About dialog boxes. As events are critical of any form-driven application
in Access, there is an in-depth look at working with form and control events.
❑ Chapter 9, “Using Code to Add Advanced Functionality to Reports,” begins with interactive
scenarios that use an exciting new feature of Access 2007 — Report view. It then provides some
other examples such as creating a calendar report and data bars à la Excel 2007, and ends with
a full-featured report manager.
❑ Chapter 10, “Using Automation to Add Functionality,” provides samples that can be used to
extend an Access application outside the boundaries of Access. It starts out with the basics of

xxvii
74029flast.qxd:WroxPro 9/27/07 1:42 PM Page xxviii

Introduction
automation such as the GetObject and CreateObject functions, and then gives you some sce-
narios for automating Windows — yes, Windows. Because Access is a part of the overall Office
family of applications, the chapter provides code for interacting with Word, Excel, Outlook, and
Project. Web applications and social applications such as instant messaging are becoming more
and more popular. To address this trend, the chapter ends with examples for automating Internet
Explorer and Windows Live Messenger, formerly MSN Messenger.
❑ Chapter 11, “Creating Dynamic Ribbon Customizations,” goes into the fine points of Ribbon
development. It begins with some development tips that we found useful and then jumps right in
to the details of writing callback routines and XML for the Ribbon. The chapter also shows you
how to use images in your customizations and then contains some examples of moving typical
Access functionality such as the NotInList event of a combo box into the Ribbon. The chapter is
aimed primarily at Access developers, but because the Ribbon can be used by other applications
in Office, VBA developers in Word, Excel, and PowerPoint may also find this useful.

Part IV: Finalizing the Application


Okay, so you’ve developed the core functionality in your application and tested it. It’s time to start
wrapping it up. Part IV covers some of the essentials for finishing an Access-based application.

❑ Chapter 12, “Configuration and Extensibility,” shows you how to create localized applications
and detect locale information on the computer. It then creates a framework for extending an
application using options and, last, shows you how to theme your Access applications.
❑ Chapter 13, “Personalization and Security,” describes the new security features in Access 2007.
It discusses how you can create personalized solutions for your users using the navigation pane,
and how to add Windows integration to an application. Chapter 13 ends with some best prac-
tices related to security and personalization.
❑ Chapter 14, “Deployment,” shows you how to create builds for your applications and includes a
managed code tool to accomplish this. This chapter also discusses including dependencies for
your applications and how to update them. It ends with a discussion about licensing and regis-
tering an Access application.
❑ Chapter 15, “Help and Documentation,” shows you how to add help to your applications. It
describes some built-in approaches such as status bar text and tooltips, and then discusses context-
sensitive help. Web-based help is also popular for many applications and the chapter shows you
how to create that. The chapter ends with the details of creating a compiled HTML help file.

What You Need to Use This Book


You must have a computer that meets the minimum system requirements for Microsoft Office 2007.
The minimum requirements for Office 2007, according to Microsoft, are a 500 MHz computer or higher,
256MB of RAM, and 2GB of hard-drive space.

To create the managed code examples, you will need a version of Visual Studio that targets the Microsoft
.NET Framework 2.0. This includes Visual Studio 2005 Standard Edition or higher or either the Visual Basic
.NET 2005 Express Edition or Visual C# 2005 Express Edition. Creating the resource DLL described in
Chapter 12 requires Visual Studio 2005 Standard Edition or higher, or the Visual C++ 2005 Express Edition.

xxviii
74029flast.qxd:WroxPro 9/27/07 1:42 PM Page xxix

Introduction
The minimum requirements for Visual Studio 2005 Standard Edition are a 600 MHz computer or higher,
192MB of RAM, and 2GB of hard-drive space.

Conventions
To help you get the most from the text and keep track of what’s happening, we’ve used a number of con-
ventions throughout the book.

Source
This section includes the source code.
Source code

Source code

Source code

Output
This section lists the output:
Example output

Example output

Example output

Source Code
As you work through the examples in this book, you may choose either to type in all the code manually
or to use the source code files that accompany the book. All of the source code used in this book is avail-
able for download at www.wrox.com. Once at the site, simply locate the book’s title (either by using the
Search box or by using one of the title lists) and click the Download Code link on the book’s detail page
to obtain all the source code for the book.

Because many books have similar titles, you may find it easiest to search by ISBN; this book’s ISBN is
978-0-470-17402-9.

Once you download the code, just decompress it with your favorite compression tool. Alternately, you
can go to the main Wrox code download page at www.wrox.com/dynamic/books/download.aspx to
see the code available for this book and all other Wrox books.

xxix
74029flast.qxd:WroxPro 9/27/07 1:42 PM Page xxx

Introduction

Errata
We make every effort to ensure that there are no errors in the text or in the code. However, no one is per-
fect, and mistakes do occur. If you find an error in one of our books, like a spelling mistake or faulty piece
of code, we would be very grateful for your feedback. By sending in errata you may save another reader
hours of frustration and at the same time you will be helping us provide even higher quality information.

To find the errata page for this book, go to www.wrox.com and locate the title using the Search box or
one of the title lists. Then, on the book details page, click the Book Errata link. On this page you can view
all errata that has been submitted for this book and posted by Wrox editors. A complete book list includ-
ing links to each book’s errata is also available at www.wrox.com/misc-pages/booklist.shtml.

If you don’t spot “your” error on the Book Errata page, go to www.wrox.com/contact/techsupport
.shtml and complete the form there to send us the error you have found. We’ll check the information
and, if appropriate, post a message to the book’s errata page and fix the problem in subsequent editions
of the book.

p2p.wrox.com
For author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a Web-based sys-
tem for you to post messages relating to Wrox books and related technologies and interact with other
readers and technology users. The forums offer a subscription feature to e-mail you topics of interest of
your choosing when new posts are made to the forums. Wrox authors, editors, other industry experts,
and your fellow readers are present on these forums.

At http://p2p.wrox.com you will find a number of different forums that will help you not only as you
read this book, but also as you develop your own applications. To join the forums, just follow these steps:

1. Go to p2p.wrox.com and click the Register link.


2. Read the terms of use and click Agree.
3. Complete the required information to join as well as any optional information you wish to pro-
vide and click Submit.
4. You will receive an e-mail with information describing how to verify your account and com-
plete the joining process.

You can read messages in the forums without joining P2P but in order to post your own messages, you
must join.

Once you join, you can post new messages and respond to messages other users post. You can read mes-
sages at any time on the Web. If you would like to have new messages from a particular forum e-mailed
to you, click the Subscribe to this Forum icon by the forum name in the forum listing.

For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to ques-
tions about how the forum software works as well as many common questions specific to P2P and Wrox
books. To read the FAQs, click the FAQ link on any P2P page.

xxx
74029c01.qxd:WroxPro 9/27/07 1:43 PM Page 1

Part I: Programming Access


Applications

Chapter 1: Overview of Programming for Access

Chapter 2: Extending Applications Using the Windows API

Chapter 3: Programming Class Modules

Chapter 4: Debugging Error Handling and Coding Practices


74029c01.qxd:WroxPro 9/27/07 1:43 PM Page 2
74029c01.qxd:WroxPro 9/27/07 1:43 PM Page 3

Over view of Programming


for Access

In this chapter, you take a look at the different mechanisms available for programming for Access
and what it means to program Access applications. You will see that with the ability to use the
Access object model outside of Access, programming for Access is not necessarily the same as pro-
gramming in Access. And, while the possibility is there to develop external applications that con-
sume the Access object model, the primary focus of the book is scenarios that use the Access object
model and Visual Basic for Applications (VBA) from within Access itself.

In this chapter, you:

❑ Learn about using managed code and how it can be used to work with Access applications
❑ Review object models that are often used with Access
❑ Learn about off-the-shelf applications in the context of Access development and what it
means to develop off-the-shelf applications

Writing Code for Access


As a part of the overall Microsoft Office family of products, Access finds itself in an interesting posi-
tion. It provides many tools that Access developers and programmers at all levels use to create robust
database applications for themselves or their users. Access 2007 includes a database engine for stor-
age, forms and reports for presenting data, macro objects for automating simple tasks, and a full-
featured programming model using VBA. Collectively, these components make it possible for you,
as the programmer or developer, to create rich solutions that can be easily deployed to your users.

As fun as it is to write Access applications, Access doesn’t provide everything. For example, it
doesn’t provide an easy way to create e-mail messages with an arbitrary attachment such as
Outlook. It doesn’t provide statistical functions, such as Excel, and it doesn’t provide word
74029c01.qxd:WroxPro 9/27/07 1:43 PM Page 4

Part I: Programming Access Applications


processing functionality, such as Word. It can, however, interact with these applications, as a part of the
overall Office family, using each application’s respective object model to participate in the larger solu-
tion. Chapter 10 provides insight into how Access fits into the larger picture when creating a solution.

In many cases, writing code for Access is different from writing code for other Office applications, such
as Word and Excel. Many Access solutions are designed specifically to work with multiple Office appli-
cations. In our day-to-day work, we use applications that we have written to enable us to send custom
e-mail messages using Outlook or to create a Word document with very specific formatting. In addition,
when you develop a database in Access, often you are developing a full-featured application for use by
multiple users.

The Access Object Model


The code you write for Access forms, reports, and controls targets the Access object model, but to
retrieve data you need to use a data access technology such as Data Access Objects (DAO), or ActiveX
Data Objects (ADO). The requirement for using two object models creates an interesting dichotomy
when you’re writing applications for Access, which also sets Access apart from writing code for other
Office applications.

The result of this separation makes it possible to write code for Access applications that can easily be
reused between applications. You might be thinking, “Can’t I write modular code for Excel-based appli-
cations as well?” Of course. But we think you’re more likely to do so when writing an Access-based
application. From the pure coding perspective, we are not suggesting that you should always separate
presentation code from data access code (in different files), but rather that it’s possible. However, if
you think about it, we do frequently separate the presentation layer from the data access layer when
we create an application with linked tables.

The DAO Object Model


Data Access Objects, or DAO, has long been used as the native data access technology for Access. Originally
included in the Jet database engine with previous versions of Access, new features appear in DAO for use
with Access 2007. You learn more about these new features, and other features of DAO in Chapter 7.

The ADO Object Model


ActiveX Data Objects, or ADO, is another data access technology available to use with Access. Both tech-
nologies are acceptable and can be used in conjunction with one another, although it’s probably not neces-
sary to do so. DAO, as the native application programming interface (API) for the Access database engine,
has performance benefits over ADO. That said, ADO is more generic and thus has its own benefits. For
example, ADO provides the ability to create Recordset objects that are not bound to a table or query, but
rather are created at runtime by appending fields. In addition, you can use an ADO recordset as the data
source for a form, combo box, or list box.

Object-Oriented Thinking
Object-oriented programming (OOP) organizes programming tasks into classes. A class is a blueprint of the
thing being modeled. Often, this is something in the real world such as a customer, or an employee. Other

4
74029c01.qxd:WroxPro 9/27/07 1:43 PM Page 5

Chapter 1: Overview of Programming for Access


times, it may be something more abstract such as a log file, or a dialog box. Classes are said to be self-
describing because they describe the characteristics of an entity, and its behaviors — that is, what it can do.
The characteristics of a class are known as properties, and the behaviors of a class are known as methods.

A class is different from an object. An object is a unique instance of a class. Over the years, language
changes to Visual Basic, and subsequently VBA, have provided some of the OOP features long used by
C++ programmers to VB and VBA developers.

Making the decision to use classes often represents a different way of thinking from traditional proce-
dural programming. Classes play an important role in some of the concepts discussed throughout the
book. As a result, we discuss programming classes and class design in greater detail in Chapter 3.
Classes form the basis of several other pieces of functionality that follow in this book.

Windows API Programming


For those tasks that VBA or the Access object model does not provide, you can use the Windows API.
An API, or application programming interface, is a set of functions grouped together by technology. The
Windows API contains the core set of functions for Windows itself, but there are other APIs as well. For
example, the DAO API consists of the objects, properties, and methods that make up DAO. The API is
discussed in depth in Chapter 2.

Wor king with Managed Code


At the beginning of this chapter, we mentioned managed code as an alternative for working with the
Access object model. Managed code refers to code whose memory is managed by the Common
Language Runtime (CLR) of the .NET Framework. This often refers to code written in Visual C#, or
Visual Basic .NET, although this is not a requirement. For example, Visual C++ developers can use
C++/CLI available with Visual Studio 2005 to write managed code.

The focus of this book is writing solutions that utilize Access for its strengths and for building high-quality
applications that are based on Access. Sometimes, this means writing code using other object models such
as Outlook, or Excel, and integrating them as part of an overall solution. Other times, it means writing code
in a different language altogether. Several chapters in this book provide examples using C# to either drive
the Access object model, or as a library that you call from VBA code inside Access. The managed code sam-
ples that are available for download with this book include both C# and VB.NET.

A great amount of material has been written about C# ranging from syntax to constructs to design.
Therefore, we won’t spend much time explaining the language. We don’t expect you to be a C# whiz, but
if you are that’s great! If not, no worries. We explain the code as we go so the managed code solutions pro-
vided are straightforward and understandable. Although the managed code in this book is written using
C#, we have provided the VB.NET equivalents on the corresponding Web site for this book.

Because we use managed code in this book, in addition to VBA, let’s spend some time discussing managed
code in a little more detail.

5
74029c01.qxd:WroxPro 9/27/07 1:43 PM Page 6

Part I: Programming Access Applications

What Is Managed Code?


As mentioned, managed code refers to any code that is written where memory is managed by the CLR.
For the purposes of this book, we write managed code in C# — although you could just as well write in
VB.NET. We chose C# because we use it in our daily work in testing Access and find it to be a nice lan-
guage for many programming tasks.

The portion of the CLR that manages memory is known as the garbage collector. The garbage collector is
responsible for detecting when objects are no longer needed, and for disposing of them appropriately. If
you have written code in other languages such as C or C++, you may quickly recognize this as a power-
ful feature, although many C and C++ developers may prefer to manage memory themselves. If you fall
into this camp, the garbage collector in the CLR provides features for tighter control when objects are
cleaned up. Although VBA does not have built-in garbage collection, you are, in effect, managing your
own memory in VBA when you set an object to Nothing such as:

Set objMyObject = Nothing

The opposite of managed code of course is unmanaged code. Unmanaged code is code whose memory is
not managed by a runtime such as the .NET Runtime. This includes code written in C, C++, Visual Basic,
or even VBA.

For more information about managed code, please refer to Appendix C of the Access 2007 VBA
Programmer’s Reference, ISBN 978-047004703.

Versions of Visual Studio


Managed code and the .NET Runtime were first available with Visual Studio 2002, which included
version 1.0 of the .NET Framework. Version 1.1 of the .NET Framework was released with Visual
Studio 1.1. The most recent release of Visual Studio, Visual Studio 2005 includes version 2.0 of the .NET
Framework. For users running Windows XP or Windows 2003 Server, you can download either version
of the .NET Framework from the Microsoft Web site. If you are running Windows Vista, version 3.0 of
the .NET Framework is now included with the operating system and offers new libraries that further
enhance managed code development.

You can even use one of the Visual Studio Express Editions to write managed code using either VB.NET
or C#. However, be cautious — the Express Editions of the languages do not include the tools required
to create a type library for use with Access and so you have to use a command-line tool that is included
with Express Edition. We talk more about this tool in the next section.

Writing Managed Code Libraries to Use with Access


In addition to features such as garbage collection, the .NET Framework provides many libraries that you can
use in managed code. Collectively, these libraries are known as the Base Class Library (BCL), and include
functionality that is typically found in the Windows API. Because these libraries are available to you when
writing managed code, they are nice to use in a type library that you call from VBA code in Access.

A library you create in a managed language such as C# creates a dynamic link library (DLL) file. And,
while you can create references to DLL files from Access and VBA, you cannot reference a managed DLL
directly. In order to set a reference to a DLL from VBA, it must expose the necessary COM interfaces that

6
74029c01.qxd:WroxPro 9/27/07 1:43 PM Page 7

Chapter 1: Overview of Programming for Access


are used to provide type information about a class. Managed DLL files do not include these interfaces.
Therefore, in order to create a reference to a managed code library, you must first create a type library for
the DLL. You can use Visual Studio to create the type library or a command-line tool called tlbexp.exe.
This tool is available as part of the Visual Studio SDK, which is freely available on the Microsoft Web site.

So, you’re probably thinking, why would we include an additional reference in the application when we
can just use the Windows API? Good question. Managed code makes it pretty straight forward to write
complex libraries that would have required a fair amount of API code to implement in VBA. Examples
of this include:

❑ Using Windows common dialog boxes


❑ Working with the Windows Registry
❑ Writing to the Windows event log
❑ Retrieving the version number of a file

Writing managed code libraries to use in an Access solution has its benefits — namely, it’s easier to write
and deploy. However, it is not without its drawbacks. Installing a library written in any language requires
an additional file as a part of the installation. However, we feel that the benefits of using managed code
(when necessary) as part of a solution outweighs the drawbacks.

Referencing the Access Object Model from Managed Code


In addition to creating managed code libraries that you can call from VBA, you can write managed code
that drives the Access object model itself. For example, you might write a report manager solution that
bundles the reports in an Access application together to print multiple reports based on a timer. Such an
application could use the Access object model to get a list of reports in the database and to print them.

You can add two types of references to a managed application — .NET and COM. Because Access is a
COM-based application, the reference to the Access object model is a COM reference. If you add a reference
to the Microsoft Access 12.0 object library in Visual Studio, you’ll notice that a few additional references are
given to you. These additional references are ADODB, DAO, Microsoft.Office.Core, and VBIDE. These
references are all used somewhere in the Access object model and as a result are included automatically
when you add the Access object model from your managed code.

In Chapter 14, you see how to create a managed application using C# to create a build of an Access
application including features such as version and build numbers and release dates.

Referencing Other Applications


In order to use object models provided by applications such as Outlook or Project, you typically add a
reference. However, adding references creates dependencies in an application that may not be desired.
For instance, what happens if you add a reference to the Outlook 12.0 object library but your users are
using Outlook 2002 (10.0)?

Issues such as these can be avoided using a technique known as late-binding. Late-binding enables you to
write code without providing type information about an object. And while it also enables you to trap for

7
74029c01.qxd:WroxPro 9/27/07 1:43 PM Page 8

Part I: Programming Access Applications


error conditions at runtime instead of compile time, it tends to lead to code that is slower to execute.
This lag is negligible on today’s fast processors with a decent amount of memory. The opposite of late-
binding is early-binding. Early-binding provides benefits such as compile-time checking and performance
improvements. This sounds pretty nice, but it causes problems if your users do not have the same appli-
cations installed or the same version. For these times, late-binding becomes very useful.

Discovering References
The easiest way to find a reference to use in your Access application is to view the References dialog box
from the Visual Basic Editor, as shown in Figure 1-1.

Figure 1-1

You can add references to COM objects that reside in DLL, EXE, or OCX files, or even to other databases
that you create in Access. By adding references to other databases you can create reusable libraries of
your own written in VBA. We discuss using references to databases in more detail in Chapter 3, and the
issue of updating references in Chapter 14.

If you’ve opened the References dialog box, shown in Figure 1-1, and scrolled through the list, you’ll
quickly notice that there are a lot of files listed. Because there are probably more files listed on your
development machine than those of your users, can you imagine the headache of trying to manage
multiple references in an application? With all of these references to choose from, how do you know
what you can or should use?

Adding References to Office Applications


The applications in the Office family of products are designed to work well together. As such, it’s very
common to find Access applications that include references to Office, Outlook, Excel, and the like. You
can add a reference to other Office applications in the References dialog box. Adding a reference uses
early-binding to an external application.

8
74029c01.qxd:WroxPro 9/27/07 1:43 PM Page 9

Chapter 1: Overview of Programming for Access


To use late-binding to another application, you must know its programmatic identifier, or ProgID. The
ProgID is a string that identifies an application for use by another application. The following table pro-
vides the ProgID values for Office applications:

Application ProgID

Access Access.Application

Excel Excel.Application

InfoPath InfoPath.Application

OneNote OneNote.Application

Outlook Outlook.Application

PowerPoint PowerPoint.Application

Project Project.Application

Publisher Publisher.Application

Visio Visio.Application

Word Word.Application

Summar y
In this chapter, we provided some thoughts about what it means to write an Access-based solution. We
examined how writing applications for Access is quite different from writing VBA code in other Office
applications. Because Access is used to develop applications, sometimes off-the-shelf, it is often viewed
as a development tool when compared to other applications in Office such as Word and Excel.

To support this view of Access as a development tool, we discussed the following:

❑ Object models commonly used while writing Access applications


❑ Programming tools and techniques such as the Windows API and object-oriented programming
❑ Using managed code that targets the Access object model, as well as using managed code as a
library inside of an Access application

You also saw a glimpse into what lies ahead in the rest of this book. Features that are often found in com-
mercial applications such as configuration, deployment, and help also have their place in Access applica-
tions. More important, you can standardize them across many applications. Over the course of the book
we introduce code that you can use to integrate features such as these into your own applications.

Coming up next, you learn how to use the Windows API and why it can be useful in your applications.

9
74029c01.qxd:WroxPro 9/27/07 1:43 PM Page 10
74029c02.qxd:WroxPro 9/27/07 1:43 PM Page 11

Extending Applications
Using the Windows API

VBA simplifies certain tasks, such as reading data from files, asking the user for information, or
even launching an external application. As a programming language, it also does a good job at
preventing you from shooting yourself in the foot. As a result, a fair amount of functionality to
developers of other languages, such as C++ or C#, is not available natively. Therefore, you utilize
the Windows API to achieve some of this same functionality.

In this chapter, you learn how you can leverage the Windows API in your applications. More
specifically, you learn the following:

❑ How to translate an API function declaration written in C/C++ to VBA


❑ How to use the API to retrieve information about the system
❑ How to control processes and threads, and work with the Windows shell
❑ How to use new task dialogs in Windows Vista that allow you to create exciting user
interfaces for your applications running on Vista

Windows API Over view


The Windows API contains literally thousands of functions that can be used to perform a wide
variety of tasks ranging from retrieving information about the system, to printing, to creating
processes, to well, you name it. Virtually everything that Windows does as an operating system
can be accomplished using the API.
74029c02.qxd:WroxPro 9/27/07 1:43 PM Page 12

Part I: Programming Access Applications

Why Use API Functions


VBA is a great language, and along with C#, it is certainly our favorite. It contains many powerful features
that we as developers use to provide very rich applications to our users. That said, it doesn’t do everything,
and that’s okay. You can use the API to take it that extra mile and to obtain the most amount of control over
the experience provided by your application. For some tasks, such as showing a Windows common dialog
box, using the API can even prevent you from having to deploy extra components with your application
such as an ActiveX control.

We also mentioned obtaining control, and the Windows common dialog box scenario is another good
example of this. The Access object model includes a property called FileDialog, which wraps the
Windows common dialog box. This property alone allows you to keep from using the comdlg32.ocx
ActiveX control, but it still doesn’t provide everything that the API itself can do. For example, using the
API you can include a Help button in the common dialog box and call a function in your VBA code
when it is clicked. Neither the ActiveX control nor the FileDialog object does this.

Finally, there are just certain things that VBA cannot do. For example, it cannot retrieve certain informa-
tion about the system, or create a Globally Unique Identifier (GUID). It cannot create a new task dialog
provided by Windows Vista, and for that matter, cannot determine which operating system is running.
For all of these things you’ll need the API.

API Resources
Knowing how to translate the MSDN documentation to VBA is important but in many cases you actually
won’t have to. There are several resources available online where these functions have already been trans-
lated to VB for you. The ones we use most often are as follows:

❑ http://vbnet.mvps.org
❑ www.pinvoke.net

The term pinvoke refers to P/Invoke, or platform invoke which is the mechanism used in managed code
to refer to API functions. For more information about P/Invoke, refer to the C# or VB.NET documenta-
tion on MSDN.

Both sites include documentation for the constants, types, and declarations used for many scenarios
where you want to use the API. Here are some other tools that you can use when working with the
Windows API:

❑ Platform SDK — An SDK, or software development kit, includes tools and documentation for
working with a particular set of API functions. The Platform SDK is the core documentation
for the Windows API and can be downloaded freely from the Microsoft Web site. This would
take the place of the MSDN library online and would run locally on your computer.
❑ dumpbin.exe — A command-line tool available with the Platform SDK and Visual C++. You can
use the dumpbin command with the /exports command-line switch to get a list of functions
that are exported from a library. These functions can potentially be used in a Declare statement.
❑ depends.exe — A graphical tool available with the Platform SDK and Visual C++. Displays
library dependencies for a module, but also includes the list of exported functions for a library.

12
Another Random Document on
Scribd Without Any Related Topics
I thought—even before I remembered that you knew her—that you
would not mind that if you were next to dear Lady Gundred.’
‘You must remember,’ answered young Restormel, ‘that the place
was sold when I was only six months old, so I cannot feel that I
have any very intimate acquaintance with Lady Gundred. Tell me
some more about her; what is she like?’
‘The sweetest and best of women, Mr. Restormel. And so pretty.
Quite extraordinary, for she must be—what?—well over thirty,
certainly, and yet she looks quite like a young girl still. Fair, you
know, with a delightful complexion and lovely golden hair, and that
kind of beautiful little figure which never alters. Yes, she must
certainly be over thirty. She has got a son who can’t be less than
fifteen. Jack, surely Jim Darnley is quite fifteen?’
Young Hoope-Arkwright glanced up from the photograph-book with
which he was beguiling the time.
‘What, Jim Darnley? Oh yes, fifteen, at least.’
‘There you are. And his mother looks like his sister still. He is the
dearest boy, Jim Darnley—the simplest, most unaffected creature.
And, of course, he will be Duke of March and Brakelond one of these
days, when his grandfather dies. They are sure to revive the title for
him. But he might be just anybody, and his mother the same. I have
always wondered why she does not make her husband take her own
name. But no; she is such a really good woman that she thinks a
wife ought always to stick to her husband’s name. That shows you
what she is. And such a worker of all good kind works, indefatigable
among the poor and the sick—for ever sending out soup and boots
and blankets, you know. Her life is quite made up of kindnesses.
They very, very seldom dine out, the Darnleys, in the country, so
that you are lucky to meet them here like this to-night. Her husband
is a very nice man too. I am sure you will like them both immensely.
But of course she is the most interesting of the two.’
At this point the other guests began to arrive, and Mrs. Hoope-
Arkwright was forced to abandon her dialogue with young
Restormel. She introduced him rather perfunctorily to one or two of
the new arrivals, taking pains to slur over his name until she should
have the opportunity of explaining his identity quietly to them at
dinner or afterwards; then she turned to her hospitable duties, and
Jack Hoope-Arkwright carried off his friend into one of the windows,
where they stood laughing and talking together while the guests
gradually gathered. Then, after a few moments, Ivor Restormel and
his host came back towards the hearth to look at some photograph
or ornament that stood on the primitive oak table that stood close
by, and thus it was that they were once more close at the hostess’s
side when at last, in a significant pause, the butler re-entered. His
appearance suggested an archbishop of sporting tendencies, and he
evidently cultivated a nice sense of drama. His voice boomed
sonorous as he announced:
‘Mr. and Lady Gundred Darnley.’
Mrs. Hoope-Arkwright moved forward a step or two.
Minute but majestic, the Lady Gundred Darnley proceeded up the
room, panoplied in perfections, and giving exactly the proper
amount of smiles, of exactly the proper kind, in exactly the proper
way, to all the proper people. At her heels came Kingston, but
nobody cared to look twice at him. Lady Gundred was the star of the
evening; as she entered, she had the double consciousness of not
only conferring great pleasure, but of conferring it in the
handsomest and most ungrudging manner. For in the plenitude of
her generosity she had decided that it was her duty not to fob off
poor, kind Mrs. Hoope-Arkwright’s dinner with one of her second-
best frocks; and now she reaped the reward of her efforts in the
general gaze of delight that greeted her appearance in one of her
smartest gowns, looking incredibly crisp and young in a beautifully-
built harmony of pale blue and pale gold. The frock set the crown
upon the favour of her coming. It was, indeed, very rarely that the
Darnleys dined out in the neighbourhood of Brakelond, and therefore
Gundred was the more ready to emphasize the approval that her
coming was to bestow on Mrs. Hoope-Arkwright in the eyes of all the
county. Dear woman, how good she had been about that bazaar!
how loyally she had turned away her Liberal gardeners! She well
deserved not only to be dined with, but to be dined with in one of
one’s decent gowns. And then one might ask her to tea at
Brakelond, and show her the pictures. Gundred showed herself
sweet and kind in the highest degree, as Mrs. Hoope-Arkwright
made her welcome. Her manner always had a tranquil friendliness
and a grace so instinct with placidity that only the most discerning
could have discerned her underlying pride, in her demeanour’s very
negation of pride. Here and there, perhaps, an acute onlooker might
guess that her gentleness was founded on an intense arrogance
unsuspected even by its possessor, on a self-esteem so tremendous
as to have passed beyond all hint of self-assertion into a Nirvana of
apparent unself-consciousness. An ingenious friend in London,
indeed, had once said that, though Gundred’s manner and signature
unfailingly wore the proper style of ‘Gundred Darnley,’ yet that,
reading between the lines, both of manner and signature, one could
always see that it really ran, ‘Gundred March and Brakelond.’
However, her pride was far too cardinal a point of doctrine to be
made the theme of declamation; Gundred never obtruded it, never
lowered its dignity by insisting on it, never allowed it to make her
offensive, except in minute and subtle ways. Now, as she pressed
Mrs. Hoope-Arkwright’s hand and commended her kindness, the
hostess felt that never had she met anyone so pleasant and cordial
and delightfully unaffected.
Then Gundred raised her eyes and looked round her to see who else
might be in the room. She saw Sir Nigel, saw the Lemmingtons, saw
the Archdeacon and his wife; she was glad that Mrs. Hoope-
Arkwright had chosen such unexceptionable people to be witnesses
of Brakelond’s condescension. Then her gaze moved on. The next
moment she saw somebody whom instantly, inexplicably, she
disliked as she had never before disliked anyone at first sight. Cool
and gracious, Gundred was the last person in the world to feel
unusual emotions; but now, as she looked at a tall dark young man
—a boy of about twenty, he seemed, remarkably beautiful and
attractive—her soul started proudly away in a flurry of instinctive
repulsion. He was unpleasant, that good-looking youth, altogether
unpleasant and odious. She had no notion why this feeling swept so
completely across her mood; it took entire possession of her. Quickly
she averted her eyes, and glanced round the uneventful circle of the
other guests. They, for their part, quite unsuspicious of Lady
Gundred’s sudden outburst of dislike, were concentrating their
admiration on the calm grace of her manner, so exquisitely civilized
and concise. Passions must always be very far from that serene
pleasantness of demeanour. And meanwhile Gundred was busy
thinking how displeasing that young man was, while with soft smiles
she responded to Mrs. Hoope-Arkwright’s compliments. But suddenly
the hostess became conscious of someone at her side. She turned
towards the handsome dark boy, and before Gundred could see
what was to happen, had brought him forward. ‘Let me introduce
you to Lady Gundred Darnley,’ she said. The young man made a
motion as if to put out his hand. Gundred instantly responded by
taking that cruel revenge which is always in a woman’s power on
such occasions. She ignored the hand, gave a glacial little smile and
a glacial little bow. The young man seemed slightly astonished at
this chill, and his eyes met hers for a moment. They were splendid
eyes, those of his—cool, deep, grey, kindly. They glanced with
wonder into the ice of Gundred’s stare, and in that moment she felt
his gaze intolerable, saw things that she mysteriously hated and
dreaded in those grey depths. For once in her life Gundred’s
composure was faintly ruffled. She dropped her glance, and faintly
blushed with annoyance. This is what one got by being generous
and dining with presumptuous people like the Hoope-Arkwrights.
Under her calm, imperturbably smiling exterior Gundred was gravely
annoyed. She moved backwards, away from this unwelcome
introduction. Her movement produced a change in the arrangement
of the crowd. Kingston stepped forward, and came into sight of the
tall, slender figure with which his wife had seemed to be talking.
Already he had had a strong conviction that he knew the back; now
that he saw the face, he recognised the wayfarer whom he had
passed on his road that afternoon. And once again, tyrannous,
overwhelming, came the certainty of old acquaintance. Before,
however, he could start a conversation, dinner was announced, and
Mrs. Hoope-Arkwright began to marshal her guests in procession.
Gundred hailed the release with joy, and passed out with gentle
majesty at the head of the cortège.
What, then, was her indignation when, having settled herself at her
host’s right, delicately removed her gloves, unfolded her napkin,
untied the little bundle of pastry faggots that lay before her knotted
up with blue ribbon, she turned towards her other neighbour, and
discovered that he was no other than the strange, beautiful young
man for whom she had conceived so unusually sudden a dislike. She
hated strong emotions, and very rarely indulged them, but this one
was beyond her control—a matter of instinct. In the first flash of
revelation, she felt convinced that this beautiful boy was a corrupter
of youth, a contemner of religion, everything that was bad and
horrible; she plumed herself immediately on the nice discernment
that enabled a Christian woman to divine such things, and made a
virtue of the hostility she harboured. Talk to such a creature she
would not. She turned quickly upon her host, and initiated the usual
introductory conversation on the beauty of the table decorations.
The dinner-table was of a piece with the rest of the restored house.
It was so aggressively old as to be obviously new. It was of that
ancient oak which is for ever modern; and, in deference to primitive
simplicity, it wore no cloth. Glass and silver gleamed down its long
narrow stretch, and in the middle ranged a hedge of roses and
orchids embowered in ferns. Electric light was not permitted to mar
its harmony with any suggestion of modernity. Candles in plain old
silver candlesticks illuminated the table and its guests, shedding a
soft and discreet glamour of pink from beneath their shades of
crimson paper. Gundred commented amiably on the beautiful effect
attained.
Mr. Hoope-Arkwright, who left such details to his wife and the
decorators, made what reply he could, and the conversation flowed
placidly along the lines that Gundred loved, developing in the way
that showed her social aptitudes at their best.
‘My wife says that electric light does not do for a dinner-table,’
explained Mr. Hoope-Arkwright. ‘Too harsh a light it sheds, she tells
me. I don’t understand such things myself, but everyone says the
candles and their pink shades are very becoming.’
‘Yes, indeed,’ replied Gundred; ‘one always likes a soft gentle light.
And so clever of dear Mrs. Hoope-Arkwright not to have a tablecloth.
All the glass and silver shows up so well. Such wonderful taste she
has.’
‘Well, I always like a tablecloth myself, you know—seems cleaner,
somehow; but Maggie says it is not the thing in a house like this.’
‘Such a delightful house—yes? And I do think you and dear Mrs.
Hoope-Arkwright have been so tactful about it—altering nothing, as
it were, and yet improving everything, and making it so comfortable.
It was very different in the poor Restormels’ time. I can remember
what it was like then.’
Mr. Hoope-Arkwright saw that she had not grasped her other
neighbour’s identity, and as personal explanations are not easy
unless one has the tact to shout them, so that their object may have
no suspicion who is meant, he preferred to turn the conversation
into other channels. ‘Are you fond of flowers, Lady Gundred?’ he
asked.
In such temperate dialogues Gundred particularly shone. She was
especially valuable in London for her power of flowing endlessly and
amiably on about matters which could never possibly interest or
stimulate anybody, or arouse difficulties of any sort. She was felt to
be a thoroughly safe guest. So Mr. Hoope-Arkwright’s question gave
her a most favourable opportunity for the display of her favourite
qualities, and she seized upon the topic with joy.
‘Oh yes,’ she answered; ‘I have always been devoted to flowers.
Such a comfort they are—yes? Quiet friends, I always say. One could
not live without them.’
‘Roses, now—do you care particularly for roses?’ pursued Mr. Hoope-
Arkwright.
‘Oh, the queen of flowers,’ she made haste to reply. ‘But, do you
know, I can never quite care for a rose that has no scent. There is
something unnatural about it—no? But these of yours are perfectly
lovely, and how sweet! Do you find the soil good for them here?’
‘Well, as to that I can hardly tell you. I leave such matters to my
wife and the gardener. But they are fine fellows, as you say.’
‘Quite like little pink cabbages—yes? Only so very, very beautiful, of
course. How one loves a rose! And they go so well with the orchids
too. So nice to be able to grow orchids.’
‘Yes, they do run into money, orchids do. You would be astonished at
the prices some of them fetch.’
Gundred thought this a vulgar ostentation, and assumed her mildly
pious air. ‘And I dare say, after all, not half so beautiful as many a
dear little flower of the hedgerows?’ she replied. ‘Money means so
little—yes? I often feel that one’s greatest pleasures are those which
cost us least. The lovely lights on the hills, the roseate hues of early
dawn—these are the joys which no money can buy. How thankful
one ought to be to Heaven for giving us all these healthy pleasures
—yes?’
Neither Mr. Hoope-Arkwright nor Gundred herself had any exhaustive
experience of early dawn and its roseate hues. But the sentiment
was improving and laudable. The host, however, was inclined to be
prosaic.
‘Well,’ he answered, ‘one need not sniff at money, either, Lady
Gundred. Where would one be without it?’
‘Ah, where indeed?’ sighed Gundred; ‘and yet one never has enough.
But one always likes to feel that there is something higher than
money, Mr. Hoope-Arkwright—yes? Money can give you all these
beautiful flowers, and this delightful house, but can money give
happiness, Mr. Hoope-Arkwright?’
‘Anyway, money can give us most of the things that make up
happiness.’
‘Not a tender, loving heart, Mr. Hoope-Arkwright. Not a childlike faith
and simplicity,’ replied Gundred pathetically. ‘And without these what
is life? Our only real happiness lies in doing what one can for others.
And that, I always feel, is the most real and precious use of money—
yes?’
Mr. Hoope-Arkwright’s most characteristic activities had hitherto lain
rather in doing others than in doing things for them. Also, he had
very different views on the use of money from those so correctly
enunciated by Gundred. So he preserved a discreet silence on the
point, and listened unprotesting while she proceeded to enlarge on
the more idyllically beautiful possibilities of life. He inserted ‘Ah yes,’
and ‘Ah no,’ at intervals into the interstices of her remarks, and cast
about for an early opportunity of taking refuge with his other
neighbour. Mr. Hoope-Arkwright did not really share his wife’s
hospitable instincts, and he did not care two straws about Lady
Gundred Darnley—or, for that matter, about Lady Anybody Anything.
‘To do the civil’ he saw to be his duty, but the moment that dinner
was half over and his duty duly discharged, he meant to indemnify
himself for his endurance of this dull, pretty woman and her boring
platitudes by having a good time with his other partner, Sir Nigel
Pope’s second wife, a young woman of a gay and kindred spirit.
Accordingly, when the roast peacock had arrived, he seized his
moment with great promptitude.
‘Now, that is what I call quite poetic,’ he exclaimed, when Gundred
had finished by saying that she thought a good, useful life was like
some fragrant flower. ‘What do you think, Lady Pope?’
Lady Pope made a prompt, flashing reply, and in another moment
was engaged in a warm duologue with her host; Gundred was left
out in the cold. She felt a certain annoyance at being dropped like
this. Her self-complacence would not, of course, let her know that
she had been dropped. She knew that she had been giving poor
dear Mr. Hoope-Arkwright one of the pleasantest half-hours of his life
—a little uplifting talk with a really refined woman—but still it was
just a trifle tiresome that he should have so very keen a sense of
duty. Evidently it was only the strictest sense of duty that had made
him change partners so precisely at the halfway house of the meal;
but Gundred would have been better pleased if he had not allowed
his sense of duty to be quite so minute and intrusive. Very proper
and right, of course, yet almost too scrupulously right and proper to
be altogether tactful. Then it suddenly occurred to her that she in
turn ought to talk to her horror on the other side. No, that she
would not. Duty and right themselves should not compel her. She
stared stonily before her, eating the peacock with wrathful and
mincing precision. She would hear no preliminaries on her right. She
gazed straight out across the table. Far off she saw her husband
looking at her. Watchful interest and curiosity filled his expression as
he glanced from her neighbour to herself. Perhaps he was wondering
why she was not talking to him. Duty clearly commanded her to. But
for once in her life correct, decorous Gundred would be deaf to the
call which she usually heard and obeyed so sedulously. She nibbled
at a pastry faggot, and kept a stern silence. Her neighbour made
two attempts at conversation, but she answered so coldly as to nip
them both in the bud. Then, abruptly, her attention was caught and
riveted. The pink candle-shade in front of her was tilting to one side,
threatening every moment to take fire. She looked anxiously round
to her host for help, but he was by now far too deeply engaged with
Lady Pope. Gundred gazed in annoyance at the paper shade. Surely
it was beginning to smoulder? Ever since the catastrophe at
Brakelond Gundred had disliked fire hardly less than the burned
child, and now her untutored desires would have prompted her to
get up and move away. But she had the martyr-like courage of her
breeding and conventions. She sat there in suspense, smiling, calm,
and altogether smooth to look at. However, there was no need, after
all, to feel so helpless. She must inevitably appeal to the young man
on her right. Speech had become a necessity, though always a
distasteful one. Besides, after all, how absurd to let even so strong
an instinct make one uncivil! Gundred fought down her reluctance
bravely, and turned to her neighbour.
‘Do you think,’ she asked firmly, though in a low, rather strained
voice, ‘that you could lower that shade a little? Do you see, I believe
it will catch fire in a moment—yes?’
No answer followed her appeal. In astonishment she repeated it,
and raised her eyes to her enemy’s face. She was astounded by
what she saw there. She herself had been put out, even alarmed for
a minute by the imminent fate of the candle-shade; but her
neighbour’s gaze was fixed on the point of peril in a set white pallor
of pure terror. Never in her life had she seen such an agony of dread
on any human countenance. The young man, so beautiful, so lithe,
so strong, was a monstrous coward. His face was rigid with fear, his
eyes staring horribly. The sight was indecent in its nude revelation of
weakness. In an instant all Gundred’s courage came back to her, and
at the same moment her hatred for her neighbour was mitigated by
a cold ferocity of contempt. He was still evil and hateful, but now he
was contemptible also. He, a man, to be so terrified of a little
burning candle-shade! At that same moment the shade tilted further,
caught, and flamed. Gundred was conscious that her neighbour’s
hands clenched upon his chair in a convulsive jerk of fright. Calmly,
firmly she reached forth her arm, and crushed the blazing paper into
a blackened flake. Servants came running to sweep up the ashes,
and Mr. Hoope-Arkwright confounded himself in apologies for his
neglect. Gundred showed herself perfectly amiable to her host, but
on her other neighbour she would have no mercy.
‘I saw it was going to catch,’ she said gently, ‘and I asked Mr.—this
gentleman, to put it out. But he cannot have heard me, I think.’ She
included both men in her remarks, and spoke in soft, far-reaching
tones that could not escape their attention. Mr. Hoope-Arkwright
made some polite rejoinder, gave her a few compliments, then went
back to his dialogue with Lady Pope. Gundred, reinstated in her own
self-esteem, turned to see what effect her cut had had upon the
coward. Had he winced beneath the lash? Yes, evidently he had.
Gundred was justly pleased. Heaven had made her the instrument of
his well-merited punishment. And now he was trying to make
excuses. She would listen, so as the better to slight them. She
offered a coldly acquiescent air as he began to speak.
‘I am sorry,’ he said in a slow, hesitating voice, hardly yet restored to
equanimity. ‘I am afraid I heard you perfectly.’
Gundred would see no courage in the confession. It was mere
effrontery. ‘Yes?’ she replied. There was a pause. ‘Yes?’ repeated
Gundred cruelly, demanding an answer.
The young man went on, speaking with difficulty. Gundred felt a
keen joy in thus dragging the coward through a confession of his
cowardice. To be a man and a coward—that was not punishment
enough. He should also know what a woman thought of him.
‘I ... well, the long and the short of it is, I can’t face fire,’ continued
the hesitating, painful voice.
‘You would not make a good soldier—no?’ rejoined Gundred, with a
pinched little smile.
‘Oh, in that way I hope I should be all right. It is flame and smoke
and burning that I cannot face. All my life I have had the fear. I
suppose everyone has a secret horror in their lives. Fire is mine. I
have suffered from it always. You don’t know what it is. It is
something far worse than fear. I am not really afraid of the fire. I
knew how ridiculously harmless that little burning shade would be,
but it was the fire, the flame that made me—well, made me almost
sick with a shrinking—a sort of supernatural repulsion that I cannot
explain.’
‘How very unfortunate!’ answered Gundred, deliberately cool and
incredulous in tone. ‘It must be so very inconvenient—yes? People
are sadly apt to misunderstand, don’t you find?’
The young man, however, was a worm only in his tendency to turn.
He flushed, seeing clearly the hard malice of her mood. ‘Very few,
thank Heaven,’ he answered, ‘have ever had the opportunity of
misunderstanding. You have been especially unlucky, and so have I.’
‘Oh, don’t mention it,’ replied Gundred, politely demurring.
‘I must, obviously,’ he went on. ‘You see, one bears one’s secret
horror, whatever it may be, quite alone, telling nobody about it. But
sometimes, once or twice in one’s life, some cursed accident drags it
to the surface, and the horror becomes too bad to bear, and an
outsider gets a glimpse of it. I have been unfortunate in the moment
of my accident, and in the person who saw it, and there is no more
to be said: that is all.’
The young man, the coward, the unmentionable, seemed actually to
be snubbing the brave, the serene, the faultless Lady Gundred
Darnley. This must instantly be put a stop to.
‘One does not like to believe that any man can have a fear too bad
to bear—no?’ inquired Gundred, very gently and softly, as if asking
for the sake of information.
The victim had clearly had enough of this persecution. ‘After all,’ he
said, ‘when one comes to think of it, I suppose you are yourself
more or less responsible for my fears, if anyone is.’
Gundred gave him a blank blue stare.
‘I?’ she questioned in amazement, as if the very suggestion were an
insolent piece of irreverence.
The young man was not abashed, however, and proceeded to make
his position good.
‘You had a ghastly fire at Brakelond many years ago,’ he answered.
‘Somebody was burnt—a cousin of yours, I think. Well, that fire was
a great shock to my mother, and upset her dreadfully. I was the
result, and I am the incarnation of her terrors.’
Gundred hesitated in her enmity, and her manner changed.
‘I beg your pardon,’ she said; ‘but I did not quite catch your name
before dinner. But from what you have just said, are you—surely you
must be——’
‘I am Ivor Restormel,’ said the enemy. ‘I was born about twelve
hours after your fire at Brakelond. So you cannot wonder that I carry
the traces of it in my life, as it were. And so, you see, I was right:
you are in some way responsible for my dread of fire. Wasn’t it a
careless servant who set light to the old wooden wing of Brakelond?
Well, if it had not been for that careless servant, I should not have
had any dread or shrinking from fire.’
‘Really,’ said Gundred, hardly heeding him, ‘this is wonderfully
interesting. Then you are poor dear Mary Restormel’s son? I used to
know your mother so well in the days before you were born. And
then the place was sold, of course, to these Hoope-Arkwrights, and I
never saw much of poor dear Mary again. But how very strange to
meet you here—yes?’
Gundred was always faithful to her traditions and her memories. The
stranger came immediately into the hallowed circle of Gundred’s own
class, and no longer suffered the condemnation of the outsider. In
her heart of hearts, Gundred, perhaps, would never surmount her
first mysterious sense of repulsion; but anger, disdain, reproof must
at once be very much modified in the case of a person who now
stood revealed as no longer an unhallowed, nameless member of
the Hoope-Arkwright world, but as poor dear Mary Restormel’s son,
with the right divine to Gundred’s sympathetic loyalty. Her strong
and dutiful esprit de corps even prompted her to something
resembling an apology.
‘Of course I had no notion who you were,’ she said. ‘What you tell
me is a perfect explanation. How very dreadful for you, though! But
I quite understand your feeling—a simple instinct. Yet, of course,
until one knew who you were, it did seem a little strange—yes?’
Ivor Restormel had ceased to take much interest in the question.
‘Oh, well,’ he said, ‘one is always meeting odd things in life. I only
wish I had escaped that particular oddity. However, I do all I can to
get the better of it, and in a way I have succeeded. I can face flame
more than I could, though it still gives me the same supernatural
creepy feeling. What I have suffered, too, in seeing women smoke is
more than I can express.’
‘Not at all a nice habit, I think,’ replied Gundred. ‘Somehow, it never
seems appropriate or ladylike—no?’
‘Oh, it is not that I mind, but the possibilities are so horrible. A man
wears rough tweeds and things. No spark could settle on them. But
think of the innumerable frills and fluffs and films that a woman has
floating all round her nowadays. A chance spark, and the dropping
of a red cigarette-end, and—ah! it doesn’t bear thinking of.’
He broke off, shuddering, and Gundred could see that at the bare
notion of such a catastrophe the old white, shivering terror had laid
hold of him. She had heard before of these strange, inherited
passions, prenatal, ineradicable, but this was the first instance she
had ever met with, and it filled her with interest now that she
realized that its victim was a man of her own order, and as such, of
course, not to be classed in the common rank of cowards. Her
subconscious fear and dislike of Ivor Restormel still held their place
in her mind, but they had retired to the background of her thought
for the moment, leaving room for the curiosity that his identity and
his idiosyncrasy aroused.
‘So very dreadful,’ she murmured, ‘for your poor mother. I had not
realized that dear Mary had been so much upset by that awful fire.
You know, Mr. Restormel, I feel as if we were quite old friends, you
and I. As you say, I cannot help feeling, after all, that we have got
some of the responsibility to bear for the odd feelings that you have
inherited. You have had quite a distressing legacy from those old
wooden rooms at Brakelond—yes?’
Laudably, deliberately friendly, Gundred raised her neat smile to
meet Ivor Restormel’s gaze. He was looking at her full, with his deep
grey eyes, true and honest, and altogether pleasant. Yet, as she met
their glance, suddenly the instinctive hostility surged up into
Gundred’s mind with redoubled strength. Fear and dislike seized her.
She could not bear that glance, could not tolerate her neighbour’s
presence. She turned away her head with a sensation of almost
terrified hostility. What was this imperious repulsion that now held
her—the first emotion that had ever threatened to pass the limits of
her self-control? She could not understand it; never before had she
felt anything even remotely resembling this blind, paradoxical dislike.
Perhaps, years since, her bitter memories of Isabel had been tinged
with the same unreasoning horror, but those far-off qualms had
been faint and colourless compared with the vehement feeling now
aroused in her by this beautiful and harmless stranger. She stiffened
herself to show a firm front; self-contempt began to stir in her. Why,
had it come to this, that she, Lady Gundred Darnley, the model of
deportment and nice tact, now wished publicly to violate her own
code, to be rude and inconsiderate to a person who on all counts, as
being unobjectionable, a fellow-guest, and an equal, claimed her
consideration and her courtesy? Such a lapse could never be
permitted. She must fight down this folly, and be kind to Ivor
Restormel through the rest of this nightmare meal. Then she would
leave the house as soon as she could, and pray Heaven that she
might never set eyes on him again.
Ivor Restormel saw something strange in her manner, but took no
heed. He did not in the least care what Lady Gundred Darnley might
choose to think of him. He felt confident that he could in no way
have offended her; further than that his interest in her attitude did
not go. The secret dislikes of one’s acquaintances are incalculable. It
is both hopeless and useless to take such things into one’s
consideration. One can but watch one’s own behaviour to keep it
clear of offence, and then leave the rest to Providence.
‘Brakelond must be wonderfully beautiful,’ continued Ivor Restormel,
amiably manufacturing conversation in the pause made by Gundred’s
sudden lapse into silence, ‘judging by the view of it from here. I
have never seen anything so fairy-like and splendid. I suppose you
have rebuilt the burnt part long ago? All wood, you say it was? Yes, I
have heard so much of that old wing that I feel as if I knew it well,
every step and winding of it. Ugh! what a ghastly death-trap!’ Again
he shuddered at his vivid recollections of a place he had never seen.
Any criticism on her family or its possessions always roused Gundred
to polite animosity. Now the feeling came to her rescue, and armed
her against this dreadful young man who seemed so pleasant and
innocuous.
‘It was very interesting and wonderful,’ she answered reprovingly.
‘We all loved it. But, of course, wood is always rather a peril—yes?
Oak panelling is most delightful, but one cannot help feeling it a
responsibility.’
‘I hate the very idea of it,’ replied the other with fervour. ‘Why,
whenever I think of those wooden rooms at Brakelond, I can smell
that horrible cold, old, acrid smell of a burnt-out ruin—the horrible
smell of charred wood, which gets into one’s nostrils and one’s
throat. Sometimes in my life I have had to meet that smell, and
whenever I get a whiff of it, I always have a vision of the wing at
Brakelond, all wrecked and blackened and fallen in, haunted by the
dreadful acid fumes of stale fire and smoke.’
Gundred might have protested further against the quite uncalled-for
vigour of Ivor Restormel’s memory, but at that moment Mrs. Hoope-
Arkwright was making efforts to capture her attention from behind a
bower of odontoglossums. She smiled her acquiescence, made some
indifferent remark to her neighbour, and rose to head the departing
procession. Thank Heaven, the ordeal was over, and she had come
out of it safely, without any more loss of self-respect than was
involved in the conception of so incalculable an instinct of hostility.
Gundred felt her self-complacency returning. She knew that it does
not matter what sentiments one may entertain, so long as one gives
no sign of entertaining them. One’s private blemishes are one’s own
private concern alone, provided that one does not let one’s clothes
slip down and reveal them to the world.
Her husband, meanwhile, at the other end of the table had proved
but a tame and uninteresting companion to Mrs. Hoope-Arkwright.
His attention throughout the meal had been fixed at every possible
moment on Gundred’s right-hand partner. For whole long minutes he
scanned that keen, handsome face. Where had he seen it before?
Why did he find it so very much more attractive than even its own
intrinsic beauty warranted? He stared at it, analyzed it, dissected its
features. No, collectively and separately they were quite new to him.
He grew more and more confident that he had never met the young
fellow before; otherwise he must have remembered him. It was not
a face to be forgotten. No, he had never seen it before. And yet the
imperious conviction grew and deepened in him that that face was
worn by no stranger—that he and the boy at the end of the table
were in some mysterious way the oldest of intimate friends. Many
years before he had felt the same passion of recognition when he at
last understood what it was he felt for Isabel; now the same
haunting sense of old acquaintance returned to him, and held him in
a firm and inexorable grip. As soon as the women had all left the
room, he carried round his glass, and settled himself decisively at
Ivor Restormel’s side, thereby upsetting all the post-prandial
arrangements, which had been meant to make him the prey of more
interesting and conspicuous men among the guests.
‘We met on the road this afternoon, I think,’ said Kingston; ‘or,
rather, I passed you. You refused to accept a lift.’
Ivor Restormel smiled back at him.
‘It was awfully good of you,’ he replied. ‘I have never been offered a
lift by a motor before. But, you see, I was so close to Restormel, it
would hardly have been worth while.’
‘Are you staying here?’ inquired Kingston, more and more strongly
drawn to this new acquaintance.
‘Yes; Jack Hoope-Arkwright is a great friend of mine. We are at
Oxford together. And, besides, I belong here in a sort of way. The
place used to be my people’s. I am Ivor Restormel.’
The name instantly brought back to Kingston’s mind that deadly
accident which had eventually been the secondary cause of Isabel’s
death. He shuddered. But the link of recollection thus forged seemed
to bind him more closely to young Restormel. The boy had an
inexplicably strong fascination. He was pleasant, he was good-
looking, he was well built; but there was something else. He was
more attractive than all these good qualities could have made him.
Kingston took an increasing pleasure in hearing him speak.
‘I remember all about you,’ answered the older man. ‘My wife used
to know your mother well. It was my wife you have been sitting next
to. Perhaps she told you how she used to know your people.’
Kingston knew Gundred’s devoted loyalty to all old friends and
neighbours, and was anxious to impress Ivor Restormel’s identity
upon her, foreseeing that it would incline her favourably to his
sudden plan of seeing as much as possible of the young fellow.
‘Yes, Lady Gundred soon recognised who I was. But I am afraid she
was a little disappointed in me. I think I could see it.’
Kingston was slightly alarmed. He knew Gundred’s prejudices of old
—soft and mild as milk; hard, ineluctable as iron.
‘Oh, nonsense!’ he replied, with more anxiety than the occasion
appeared to warrant. ‘My wife is always a little cool and non-
committal when she meets people for the first time. You will soon
get accustomed to her.’
It never occurred to him that he was apparently explaining his wife,
more or less apologetically, to a total stranger. Ivor Restormel was
puzzled. His beauty had already made him many sudden friends, had
immensely helped him on his way through life, predisposing
everyone in his favour; but it had never yet kindled such a fire of
zeal as seemed to be developing in Mr. Darnley. He was inclined to
be cautious in acceptance, and during the rest of the meal gave
careful, quiet answers to Kingston’s advances. But Kingston had not
the faintest interest in the boy’s beauty, nor, precisely, in the boy
himself. It was the acquaintance, the old friend in him, that Kingston
divined so keenly, and was eager to investigate more fully. The
vehement attraction that he felt towards Ivor Restormel was
something, so to speak, impersonal, something quite unconnected
with the boy’s pleasant manners or agreeable face. It was an
attraction towards something deep and hidden in the young fellow’s
personality, and the attraction grew stronger and clearer with every
minute of their dialogue.
At last the time came to go into the drawing-room. The men rose,
and drifted in knots towards the door. Kingston, as he went, retained
possession of young Restormel, despite the evident anxiety of Mr.
Hoope-Arkwright and Sir Nigel to have a word with Lady Gundred’s
husband.
‘Look here,’ he said. ‘How long are you staying with the Hoope-
Arkwrights? Come over to Brakelond, will you? Come over to-
morrow. I should like you to see the place.’
Ivor Restormel accepted the unexpected invitation with thanks. Jack
Hoope-Arkwright, following in their wake, wondered at the
precipitate friendliness of Mr. Darnley. Such sudden hospitality was
by no means in the traditions of Brakelond. A long preliminary
purification was generally necessary before Lady Gundred considered
her friends well tested enough to be invited to the Castle. And here
was Ivor Restormel, after half an hour’s acquaintance, not only
asked, but pressed to come, and to come as soon as possible. Times
were changing indeed. It had taken the Hoope-Arkwrights three
years to know the Darnleys, and eight to be dined with by them.
The rest of the evening passed without event. Gundred, however,
gradually grew displeased with her surroundings. At first she had
duly been throned on the best sofa, and listened to in silent
admiration while she pronounced on the weather, the decadence of
decorum in the servants’ hall, and the proper management of cooks.
But ere long Lady Pope, whom, in her mind, Gundred characterized
as a pushing young person, had begun to cut in frivolously,
irreverently, with jokes and stories. Gundred, who had a faint instinct
that all wit was more or less vulgar, did her best to repress these
interruptions; but her efforts were vain, and soon even her devout
hostess was listening and laughing at Lady Pope’s sallies. Lady
Gundred was left rather out of the picture, and her authoritative
comments on cooks began to lose their hold on the general
attention. Then when the men appeared it was even worse. Lady
Pope became the centre of a court; even those who came to make
their dutiful obeisance to Lady Gundred passed hastily on, after a
few pallid words about the weather, to join the cheerful crowd round
the younger woman. Then games were played, largely at Lady
Pope’s instigation; and Gundred, who would have disliked any
proposal that sprung from one whom she now felt herself compelled
to regard, however disdainfully, as a rival, had, further, personal
reasons for disapproving this development. For she sang; and she
expected, accordingly, to be asked to sing. Her music was waiting
outside to be fetched; it would have been obviously proper of Mrs.
Hoope-Arkwright to press her most important guest to perform. But
apparently everyone preferred the thoughtless gaiety of this
unprofitable evening to hearing Lady Gundred discoursing
Chaminade in her neat and well-drilled little flute of a voice, which,
as her friends said in extenuation, was so truly wonderful for a
woman of forty.
Finally, to add to all these annoyances, she saw her husband
neglecting everyone else in the room to talk to that young man for
whom she had conceived such a repulsion. She would rather, even,
have seen him spending the time in attendance on that forward Lady
Pope. But Kingston was so distressingly friendly. Actuated by many
collaborating motives, Gundred made haste to ask for her carriage,
and showed every sign of imminent departure, much to the distress
of hospitable Mrs. Hoope-Arkwright. Mrs. Hoope-Arkwright felt that
the evening had not been altogether satisfactory since dinner. Lady
Pope had evidently shone excessively; and the light of Lady Gundred
Darnley had been thereby most unjustly dimmed. It grew plain that
Lady Gundred was a little put out. Gaiety and dignity were hard to
combine. Lady Pope offered the gaiety; Lady Gundred the dignity.
And the two ambitions were irreconcilable; for it was already clear
that Lady Gundred could not amuse—certainly not while Lady Pope
was of the party. Grievously did Mrs. Hoope-Arkwright regret that
she had infused the gay and sparkling element of the young woman
into what she had meant to be the serene if soporific delights of a
dinner made illustrious by the presence of March and Brakelond. But
it was now too late for regret, and no entreaties could soften Lady
Gundred’s determination to go.
‘Thanks so much,’ said Gundred sweetly. ‘Such a delightful evening.
We have enjoyed ourselves so much. But we must really think of the
horses. Good-night, Mrs. Hoope-Arkwright. Good-night—good-night
—good-night.’
Scattering bows and farewell condescension like a queen, the Lady
Gundred Darnley moved towards the hall. Kingston obediently
followed her, and soon the door of the brougham was shut upon
them, and they were off. Gundred smoothed out her flounce with a
certain pettishness unusual to her calm temperament.
‘A dreadful house,’ she said decisively, ‘so horribly rich and new—and
the most vulgar and trying people. One wonders how even the
Hoope-Arkwrights contrive to collect such a crew. Surely, Kingston, I
could not have heard you asking one of them to come to Brakelond?
Just as we were leaving. It must have been my fancy, of course.’ She
was sitting very upright, rigid with rectitude, her pale lips
compressed, her pale eyes gleaming scornfully. Kingston felt like a
guilty child.
‘Only young Restormel,’ he said. ‘You will like him, Gundred. I am
sure you will like him immensely. He is one of the most attractive
people I have ever met. After all, he is an old neighbour of yours,
not like the Hoope-Arkwrights and the rest of their friends. I made
him promise to come over to-morrow. And then, later on, he might
come to stay with us for a bit. I should like you to see more of him,
Gundred. He will be someone for you to help and befriend.’
A very long silence, leaden and ominous, filled the brougham. Then
Gundred spoke, in a bland, deliberate low voice.
‘Really, Kingston,’ she said, ‘you are almost trying at times.’
Her husband felt himself annihilated. This, from Gundred, was very
heavy rebuke. He made no answer, and they drove on to Brakelond
without another word.
CHAPTER XVIII
Gundred, however, was too good a wife to make useless difficulties.
As her husband had invited this young man, this young man must
clearly be endured. After all, the visit would soon be over, and she
herself need not put in more than a bare appearance. To tell the
truth, she was not quite easy as to her own attitude in the matter. It
could not be altogether right to conceive such violent antipathies,
and she was painfully surprised to find herself entertaining such a
feeling. She told herself that there could be no smoke without fire,
and that sooner or later her infallible female instinct would be found
justified. But until it should be so found justified, she was far too
conscientiously good a woman to be happy in the indulgence of an
unreasonable hatred. Accordingly, she deliberately suppressed her
annoyance, and made it her penance to receive Ivor Restormel on
the morrow with her usual quiet grace. The effort brought its own
reward; dislike him mysteriously, instinctively, she still did and always
would, but there was no longer the uncomfortable vehemence about
the feeling. She could tolerate him, though she could not make him
welcome.
Ivor Restormel walked over in the afternoon. Gundred gave him tea
and then left him to her husband’s care, on the plea of a post to
catch. Kingston took his guest into the new wing that had been built
on the promontory after the fire, and proceeded to question him and
talk to him more exhaustively than had been possible the night
before amid the exigencies of a party, no matter how scandalously
disregarded. There was no beginning about their friendship, it
seemed to Kingston, no breaking of new ground. It was simply the
picking up of a dropped thread where it had fallen. The feeling was
strange and almost uncanny, the more so that it was evidently not
shared by Ivor Restormel. He received his host’s overtures with
diffidence, seemed ill at ease, at a loss to understand the warmth of
his treatment. Mr. Darnley was nothing more to him than a chance
acquaintance of the night before. As the dialogue went forward, too,
the visitor’s uneasiness became more and more marked. His face
took on a strange look of strain and anxiety; in his speech could be
heard from time to time that note of abstraction which can be heard
in a voice whose owner is trying hard to keep up a conversation,
while his mind is fixed far away on the contemplation of unpleasant
private matters. Kingston watched the expression of his guest’s eyes,
the curious hunted fear that his whole manner began to suggest,
and again experienced more strongly than ever the mysterious
feeling of having seen that manner, that strained expression,
somewhere before. His memory must be playing him the maddest
tricks; for he could have sworn that this boy was well known to him
in every detail of face and disposition; yet by now it was clearly
proved—as clearly proved, at least, as anything in this world could
ever be—that the two had never met, and never even set eyes on
each other before. But Kingston still hoped against hope that a
chance discovery in the dialogue might reveal some hint or glimpse
of a former meeting, however brief, partial, trifling. Thus, and thus
alone, could his instinct be justified.
But, as the conversation went forward, the visitor’s uneasiness grew
keener and more unsettling. At last it could no longer be controlled.
‘I should awfully like to see some more of the Castle,’ he said. ‘You
said something last night about showing me the pictures.’
But the boy’s evident wish to move was too interesting to be
gratified. Kingston saw it, could not understand it, meant to
understand it.
‘Oh, there will be heaps of time,’ he replied. ‘You must come over
again some afternoon. But it takes at least a day to see the Castle
thoroughly. We may just as well stay here peacefully. Really, these
are the most comfortable rooms in the whole building, although they
are quite modern.’
‘Modern, are they?’ answered young Restormel. It was a silly answer,
and betrayed the inattention of his mind. For the rooms were too
obviously modern for any comment on the fact to be other than
fatuous.
‘Yes, they were only built about—yes, twenty years ago.’
Ivor Restormel leapt to his feet. His anxiety culminated, seemed
mysteriously confirmed. His eyes were filled with a horror he was
trying to conceal. ‘Surely,’ he stammered, ‘these are not the rooms
that were restored after the——’
‘After the fire? Yes. This was where the old wing stood.’
‘I thought so; I knew they must be,’ replied Ivor Restormel with
forced calm. ‘And they have not got rid of the smell yet. I noticed it
as soon as I got inside.’
‘The smell! What smell?’ asked his host, amused by this odd notion
of his visitor’s, and sniffing about for the aroma of dead rats.
‘The smell of fire,’ said Ivor Restormel, speaking in a low voice, as of
a thing too dreadful to be talked of in normal tones. ‘The whole
place is full of the smell of fire. Don’t you notice it, Mr. Darnley? I
suppose nothing can be on fire now? No; it is the stale old smell of a
fire that has been out for a long time—the sharp, beastly smell of
charred wood and burnt stone. I know it so well.’ He shivered
against his will.
Kingston was startled at this strange new development. He had
heard nothing of Ivor Restormel’s hidden horror. Gundred had
disliked the whole subject too much to tattle about it. Kingston was
astounded at the sudden fantastic anxiety of his guest, the
perturbation of his manners, his evident discomposure. So vivid was
Ivor Restormel’s apprehension that it even impressed itself on
Kingston. The host inhaled the air sharply. There was not the
faintest suggestion of fire or smoke. The room was sleepily fragrant
with potpourri from the old perforated jade censer on the corner
table. Otherwise there was nothing in the air. And yet it was evident
that Ivor Restormel was dodging some secret terror that was almost
on the point of breaking covert and declaring itself.
‘You have got a most wonderful imagination,’ said Kingston at last.
‘There is no smell of fire here. On my word, there isn’t. There
couldn’t be. The fire was put out twenty years ago, hang it all! The
smell of it could not very well be hanging about here still.’
‘No; I suppose not,’ answered the other, obviously quite
unconvinced.
Then, lamely, hesitatingly, he explained the reasons why the
memories of the catastrophe at Brakelond had become so closely
involved with his own life, and what a troublesome legacy it had left
him through the shock that his mother had suffered. Kingston was
more and more stirred.
‘I never heard anything more extraordinary,’ he replied. ‘Suggestion,
I suppose it must be. And this room makes you feel uncomfortable
even now, I can see, and you manage to smell fire where there has
been no fire for twenty years. And yet you have no more
recollections?’
‘Recollections? I don’t quite know what there could be for me to
recollect.’
‘Well, to tell you the truth, when I first saw you on the road, I had a
vague and yet a very strong feeling that you and I have met before,
and known each other quite well. I imagine that was all a mistake?
See if you can’t remember any previous meeting between us,
though. It would be interesting if you could, for my instinct was
quite extraordinarily clear on the point, though my memory seems to
say accurately and definitely that I had never seen your face till I
passed you in the car yesterday afternoon.’
Ivor Restormel shook his head positively, and made haste to answer
in the negative. The question did not interest him in the least. The
one feeling of which he was conscious was his tyrannous need of
getting away from those serene and pleasant modern rooms, which,
to his excited fancy, seemed full of horrid ghosts.
‘No,’ he said. ‘I am pretty well certain we can never have met before.
I was brought up abroad, you see, by my mother, after they sold
Restormel. And the last two or three years I have been living at
Oxford. I have not been to London or anywhere where we could
have met. No—no.... I say, I am a most awful idiot to-day. I can’t
imagine what has come over me,’ he cried abruptly. ‘But this jolly
room of yours—well, it feels to me horribly uncanny. You say there is
no fire, and of course there isn’t; yet the smell is in my nostrils and
my throat all the time, choking and stifling me. Did you ever hear
such rot? Do you mind if we go out in the garden or somewhere?
I’m not often taken like this, please believe me. I have never felt
anything like this in my life. I told you how I hate and dread fire,
though I have never suffered from it; but nothing has ever given me
such an awful impression of fire as I feel here to-day.’
He had been standing ever since he rose from his chair, or walking
uneasily from end to end of the room. Now he stood in front of his
host, gazing at him with eyes which, for all his tongue’s pretence at
ease, were filled with a haunting dread. Kingston was deeply moved
by the spectacle of this fighting terror before him. The terror moved
his pity, the courage of its victim moved his admiration. And, behind
everything else lay the curiosity that this manifestation woke in him.
But he could no longer disregard his visitor’s eagerness to be gone
elsewhere. He rose from the window-seat.
‘I am sorry,’ he said. ‘I cannot understand it. Yes, let us go, if you
wish. We might take a turn in the garden. I would not have brought
you in here if I had had the slightest idea that you feel like this. But
I never could have believed that such a stretch of imagination was
possible.’ Kingston broke off, studying the controlled fear in the
young man’s face. Then he abruptly began again. ‘Look here,’ he
said, ‘do tell me exactly what it is you see and feel that gets on your
nerves so. I cannot understand it.’
Ivor Restormel glanced round the room. Under Gundred’s
supervision it had been rebuilt in a cool and placid modern style.
Everything in it was pretty, graceful, harmonious. The walls were
panelled in white; flowers were standing about in tall blue glasses.
The big windows admitted shafts of soft afternoon light through
their drawn white blinds, and the whole impression was one of
fragrant, comfortable peace.
But Ivor Restormel’s eyes saw something very different.
After a pause he answered, huskily, in broken, difficult tones:
‘You will think me more of an ass than you do already,’ he replied. ‘I
suppose it must be my mother’s stories that account for it. But,
besides the awful smell of burning here, I seem to see a horrible
wreckage of charred ruins. Oh, I can see these walls and all the jolly
decorations. And yet, somehow, when I look again they are not
there any longer. There is only the shell of some other building,
something all fallen in and blistered and blackened with fire. Great
heaps of ashes and bleached rubbish are piled high between what is
left of the walls. The whole place is choking with the stale fumes of
smoke. And the rooms are open to the grey sky far overhead; and
grey drifts of rain come dashing in from time to time on the
smouldering masses.’
Kingston watched his visitor’s face with an amazement that bereft
him of words.
‘By God!’ he said slowly, wondering where his thoughts would lead
him in the next few minutes. ‘By God! you describe it exactly as if
you had been here twenty years ago.’
Ivor Restormel shook his head fiercely, as if trying to shake off some
horrid, persistent memory.
‘I feel as if I had,’ he replied suddenly. ‘I feel just as if I had been
here twenty years ago, worse luck. The moment I came into the
room I saw it all. I felt—oh, well, I felt that I must have been here in
the ruins ever so long ago, and had the worst time here that anyone
ever had—as if I had been tied by the leg here, somehow, and
pinned down in damnable terror and pain.’
‘Come along out of it,’ said Kingston quietly, after a pause. He dared
not trust himself to say more. An idea had been born in his brain—
born, or called once more to life?—an idea so wild, so fantastic, that
he hardly dared to entertain it. And yet, in the depths of his heart,
he knew that it was the truth. In silence he led the way towards the
Castle, while his visitor tried to impress upon his unheeding ears a
dozen apologies for the gross and idiotic folly of which his nerves
had made him guilty.
As soon as he was out of the fateful room all his self-possession
seemed to have returned, and he could not account for the sudden
vertigo of terror that had haunted him there. What had come over
him he could not imagine. Mr. Darnley must certainly think him the
most confounded idiot. What must Mr. Darnley think of anyone who
could let himself be made such a rude, mannerless idiot of by a sort
of hysterical schoolgirl qualm? The whole thing was too asinine for
words. He had no excuse to make.
And all the time Mr. Darnley said nothing, heard nothing of his
guest’s protestations. This beautiful nervous boy had no interest for
Kingston Darnley; he did not care what he said or felt or looked like.
But the terror that haunted Ivor Restormel was not his; the
mysterious attraction that filled him was not his own. Somewhere,
deep down in his being, lived Something that had felt that terror,
Something that exercised that attraction over Kingston, Something
that called to Kingston as an old friend. And that Something,
Kingston knew it, heard it calling to him imperiously out of the
eternal past. It was the Something that had once carried the name
and shape of Isabel. There was no mistaking it. Now at last Kingston
understood what it was that had gripped him yesterday on the road,
what inexplicable summons of old friendship. The dead had come
back to him after many years. But clothed in alien flesh, forming part
of a new personality, shut off from recognition by the barriers of the
body. For in this boy lived only the one fragmentary recollection of
the final catastrophe. Nothing in Kingston’s soul, no call of ancient
kinship, no appeal to bygone pledges, could penetrate to the ears of
that secret self. The dead had come back, known to him, but
incapable of knowing him again. How could he wake memory in that
changed thing which had returned, at once the same, and yet so
different, in its freedom from that bond which once had made them
one, and now, still as strong as ever in the hold it had over himself,
had broken and fallen away for ever from the other soul it had
gripped? Kingston looked at his visitor with a feeling that drew near
to hatred. This stranger held the thing he still loved. The body and
the shape of it was an irrelevant, a maddening accident; it was the
secret thing that Kingston called to, the secret thing that was
prevented from hearing by this new personality in which it had
clothed itself. Kingston felt a sharp grudge against Ivor Restormel,
his body, his brain, his beauty. That body, that brain, that beauty
made the locked casket that imprisoned the living dead. And yet,
inasmuch as Ivor Restormel was the shrine of that lost passion, he
was, on the other hand, ineffably precious and sacred. He could not
be let go. The boy himself was less than nothing; but what he held
was more than everything.
Ivor Restormel thought his host justifiably offended, and tried to
mitigate the effect of his own silly rudeness. But his pleasant chatter
fell on unheeding ears, and he began to think that he had alienated
Mr. Darnley beyond reconciliation. And no wonder. Who could be
expected to put up with a puling idiot like that? Ivor Restormel
mentally kicked himself, and felt that he would gladly have
vindicated his character by returning into those haunted rooms.
Without having any special wish to please either of the Darnleys, he
was one of those people who always like to be popular, and grow
faintly unhappy when they fail to make a favourable impression. He
did all he could to mollify his host, and was distressed, though not
surprised, to find all his efforts fall flat. In ordinary circumstances he
would not have minded so much; but now he felt that he really
owed Mr. Darnley some extra pleasantness, if only to make up for
having just made so egregious an ass of himself. He tried his level
best to set matters right; but for a long time he got no answer—or
at most an absent-minded monosyllable. Kingston was not yet equal
to conversing with this tiresome young interloper who had come
between himself and the dead, while, at the same time, revealing at
last to him the return of the lost. They walked in silence up and
down the garden together, while Gundred watched them from an
upper window, disliking the visitor as much as ever, and wondering
when in the world he would begin to think about going.
‘Wanted to see the pictures, didn’t you?’ said Kingston abruptly at
last, cutting, regardless, into something that the other was saying.
Ivor Restormel felt more and more out of place. Evidently he would
do well to say good-bye. However, he could not escape from this
civility of his host, however perfunctory. So he followed Kingston as
he strode into the Castle, paying no attention to the boy at his heels.
Gradually Kingston was beginning to recover his composure and face
the inevitable. This wonderful secret certainty of his must be
cherished and acted on, though already he began to taste something
of the pain that had been foretold him, from incessant yearning
knowledge of a thing that could not recognise him in turn, and could
never recognise him again. The door between them was of locked
iron—a vain agony to beat against. And yet it was not an agony that
he could spare himself, for, though the door was of locked iron for
ever, yet behind it dwelt the thing he had sought for so long. He saw
now the irony of his fate. But nothing could divert its course. Ivor
Restormel found his host growing calmer and more courteous again.
Soon he was even cordial, and the tension of the situation seemed
at an end. The two men passed through the picture-gallery, giving a
share of attention to every picture, though each, in reality, was busy
with his own thoughts, Ivor feeling the satisfaction of successful
effort, and Kingston foreboding the anguish of an effort that could
never be successful. At last they had gone the length of the gallery,
and stood before the old panel of Queen Isabel.
‘Here is the She-wolf,’ said Kingston pleasantly. ‘Don’t you think she
looks her name? Isabel of France and England.’
The younger man laughed uneasily.
‘Yes,’ he answered. ‘An evil lady, I suppose? It is curious what a
horror I have of the very name. Isabel—it seems to stand to me for
everything I hate most in the world, fire included. I must have some
Welcome to Our Bookstore - The Ultimate Destination for Book Lovers
Are you passionate about books and eager to explore new worlds of
knowledge? At our website, we offer a vast collection of books that
cater to every interest and age group. From classic literature to
specialized publications, self-help books, and children’s stories, we
have it all! Each book is a gateway to new adventures, helping you
expand your knowledge and nourish your soul
Experience Convenient and Enjoyable Book Shopping Our website is more
than just an online bookstore—it’s a bridge connecting readers to the
timeless values of culture and wisdom. With a sleek and user-friendly
interface and a smart search system, you can find your favorite books
quickly and easily. Enjoy special promotions, fast home delivery, and
a seamless shopping experience that saves you time and enhances your
love for reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!

ebookgate.com

You might also like