Access 2007: The Missing Manual [1 ed.] 0596527608, 9780596527600

This is well written and helps me bridge the gap between what is necessary and what I wish was intuitive.

301 54 17MB

English Pages 851 Year 2006

Report DMCA / Copyright

DOWNLOAD PDF FILE

Table of contents :
Access 2007: The Missing Manual ......Page 0
Table of Contents......Page 1
Copyright......Page 5
The Missing Credits......Page 7
Introduction......Page 11
Part I:  Storing Information in Tables......Page 31
1. Creating Your First Database......Page 32
Section 1.1.  Understanding Access Databases......Page 33
Section 1.2.  Getting Started......Page 34
Section 1.3.  Saving and Opening Access Databases......Page 50
Section 1.4.  The Navigation Pane......Page 61
2. Building Smarter Tables......Page 65
Section 2.1.  Understanding Data Types......Page 66
Section 2.2.  Design View......Page 68
Section 2.3.  Access Data Types......Page 73
Section 2.4.  The Primary Key......Page 93
Section 2.5.  Six Principles of Database Design......Page 96
3. Datasheet: Sorting, Searching, Filtering......Page 101
Section 3.1.  Datasheet Customization......Page 102
Section 3.2.  Datasheet Navigation......Page 108
Section 3.3.  Advanced Editing......Page 121
Section 3.4.  Printing the Datasheet......Page 128
4. Blocking Bad Data......Page 132
Section 4.1.  Data Integrity Basics......Page 133
Section 4.2.  Input Masks......Page 145
Section 4.3.  Validation Rules......Page 155
Section 4.4.  Lookups......Page 163
5. Linking Tables with Relationships......Page 169
Section 5.1.  Relationship Basics......Page 170
Section 5.2.  Using a Relationship......Page 176
Section 5.3.  More Exotic Relationships......Page 192
Section 5.4.  Relationship Practice......Page 198
Part II:  Manipulating Data with Queries......Page 205
6. Queries That Select Records......Page 206
Section 6.1.  Query Basics......Page 207
Section 6.2.  Creating Queries......Page 208
Section 6.3.  Queries and Related Tables......Page 229
7. Essential Query Tricks......Page 240
Section 7.1.  Calculated Fields......Page 241
Section 7.2.  Query Functions......Page 249
Section 7.3.  Summarizing Data......Page 263
Section 7.4.  Query Parameters......Page 270
8. Queries That Update Records......Page 273
Section 8.1.  Understanding Action Queries......Page 274
Section 8.2.  Update Queries......Page 276
Section 8.3.  Append Queries......Page 283
Section 8.4.  Delete Queries......Page 292
Section 8.5.  Tutorial: Flagging Out-of-Stock Orders......Page 296
9. Crosstab Queries and Pivot Tables......Page 299
Section 9.1.  Understanding Crosstab Queries......Page 300
Section 9.2.  Creating Crosstab Queries......Page 304
Section 9.3.  Pivot Tables......Page 313
Section 9.4.  Pivot Charts......Page 326
Part III:  Printing Reports......Page 332
10. Creating Reports......Page 333
10.1. Report Basics......Page 337
10.2. Printing, Previewing, and Exporting a Report......Page 347
10.3. Formatting a Report......Page 354
10.4. Filtering and Sorting a Report......Page 355
11. Designing Advanced Reports......Page 358
Section 11.1.  Improving Reports in Design View......Page 359
Section 11.2.  The Report Wizard......Page 370
Section 11.3.  The Label Wizard......Page 374
Section 11.4.  Fine-Tuning Reports with Properties......Page 379
Section 11.5.  Expressions......Page 385
Section 11.6.  Grouping......Page 387
Part IV:  Building a User Interface with Forms......Page 399
12. Creating Simple Forms......Page 400
Section 12.1.  Form Basics......Page 401
Section 12.2.  Sorting and Filtering in a Form......Page 412
Section 12.3.  Creating Better Layouts......Page 417
Section 12.4.  The Form Wizard......Page 429
13. Designing Advanced Forms......Page 432
Section 13.1.  Customizing Forms in Design View......Page 433
Section 13.2.  Taking Control of Controls......Page 450
Section 13.3.  Forms and Linked Tables......Page 462
14. Building a Navigation System......Page 466
Section 14.1.  Mastering the Navigation Pane......Page 467
Section 14.2.  Building Forms with Navigation Smarts......Page 478
Section 14.3.  Linking to Related Data......Page 490
Part V:  Programming Access......Page 498
15. Automating Tasks with Macros......Page 499
Section 15.1.  Macro Essentials......Page 500
Section 15.2.  Macros and Security......Page 509
Section 15.3.  Three Macro Recipes......Page 517
Section 15.4.  Managing Macros......Page 523
Section 15.5.  Connecting Macros to Forms......Page 527
Section 15.6.  Conditional Macros......Page 534
16. Automating Tasks with Visual Basic......Page 540
Section 16.1.  The Visual Basic Editor......Page 541
Section 16.2.  Putting Code in a Form......Page 546
Section 16.3.  Understanding Objects......Page 553
Section 16.4.  Using Objects......Page 563
17. Writing Smarter Code......Page 574
Section 17.1.  Exploring the VB Language......Page 575
Section 17.2.  Dealing with Trouble......Page 586
Section 17.3.  Deeper into Objects......Page 592
Section 17.4.  Using VB to Run a Better Business......Page 599
Part VI: Sharing Access with the WWW ......Page 614
18. Sharing a Database with Multiple Users......Page 615
Section 18.1.  Opening Up Your Database to the World......Page 616
Section 18.2.  Preparing Your Database......Page 618
Section 18.3.  Playing Well with Others......Page 633
Section 18.4.  Data Corruption......Page 640
Section 18.5.  Securing Your Database......Page 642
19. Importing and Exporting Data......Page 650
Section 19.1.  Case for Importing and Exporting......Page 651
Section 19.2.  Using the Clipboard......Page 654
Section 19.3.  Import and Export Operations......Page 659
Section 19.4.  Access and XML......Page 671
Section 19.5.  Collecting Info by Email......Page 681
20. Connecting Access to SQL Server......Page 691
Section 20.1.  Should You Switch to SQL Server?......Page 692
Section 20.2.  Getting Started: SQL Server 2005 Express......Page 697
Section 20.3.  Creating a SQL Server Database......Page 703
Section 20.4.  Adding Objects to a SQL Server Database......Page 713
21. Connecting Access to SharePoint......Page 723
Section 21.1.  Understanding SharePoint......Page 724
Section 21.2.  Setting Up SharePoint......Page 729
Section 21.3.  SharePoint and Access......Page 739
Part VII:  Appendix......Page 764
Appendix A. Customizing the Quick Access Toolbar......Page 765
Section A.1.  The Quick Access Toolbar......Page 766
Colophon......Page 770
INDEX ......Page 771
Symbol ......Page 772
A......Page 774
B......Page 779
C......Page 781
D......Page 788
E......Page 795
F......Page 799
G......Page 806
H......Page 808
I......Page 809
J......Page 811
K......Page 812
L......Page 813
M......Page 816
N......Page 819
O......Page 821
P......Page 824
Q......Page 828
R......Page 830
S......Page 834
T......Page 840
U......Page 843
V......Page 845
W......Page 847
X......Page 849
Y......Page 850
Z......Page 851
Recommend Papers

Access 2007: The Missing Manual [1 ed.]
 0596527608, 9780596527600

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Citation preview

Table of Contents

Access 2007: The Missing Manual By Matthew MacDonald ............................................... Publisher: O'Re illy Pub Dat e: D e ce m be r 0 1 , 2 0 0 6 I SBN- 10: 0 - 5 9 6 - 5 2 7 6 0 - 8 I SBN- 13: 9 7 8 - 0 - 5 9 6 - 5 2 7 6 0 - 0 Pages: 6 0 0

Table of Contents Copyright The Missing Credits Introduction Part I: Storing Information in Tables Chapter 1. Creating Your First Database Section 1.1. Understanding Access Databases Section 1.2. Getting Started Section 1.3. Saving and Opening Access Databases Section 1.4. The Navigation Pane Chapter 2. Building Smarter Tables Section 2.1. Understanding Data Types Section 2.2. Design View Section 2.3. Access Data Types Section 2.4. The Primary Key Section 2.5. Six Principles of Database Design Chapter 3. Mastering the Datasheet: Sorting, Searching, Filtering, and More Section 3.1. Datasheet Customization Section 3.2. Datasheet Navigation Section 3.3. Advanced Editing Section 3.4. Printing the Datasheet Chapter 4. Blocking Bad Data Section 4.1. Data Integrity Basics Section 4.2. Input Masks Section 4.3. Validation Rules Section 4.4. Lookups

file:///C|/html/0596527608/toc.html (1 of 4) [1/7/2007 7:04:36 AM]

Table of Contents

Chapter 5. Linking Tables with Relationships Section 5.1. Relationship Basics Section 5.2. Using a Relationship Section 5.3. More Exotic Relationships Section 5.4. Relationship Practice Part II: Manipulating Data with Queries Chapter 6. Queries That Select Records Section 6.1. Query Basics Section 6.2. Creating Queries Section 6.3. Queries and Related Tables Chapter 7. Essential Query Tricks Section 7.1. Calculated Fields Section 7.2. Query Functions Section 7.3. Summarizing Data Section 7.4. Query Parameters Chapter 8. Queries That Update Records Section 8.1. Understanding Action Queries Section 8.2. Update Queries Section 8.3. Append Queries Section 8.4. Delete Queries Section 8.5. Tutorial: Flagging Out-of-Stock Orders Chapter 9. Analyzing Data with Crosstab Queries and Pivot Tables Section 9.1. Understanding Crosstab Queries Section 9.2. Creating Crosstab Queries Section 9.3. Pivot Tables Section 9.4. Pivot Charts Part III: Printing Reports Chapter 10. Creating Reports Section 10.1. Report Basics Section 10.2. Printing, Previewing, and Exporting a Report Section 10.3. Formatting a Report Section 10.4. Filtering and Sorting a Report Chapter 11. Designing Advanced Reports Section 11.1. Improving Reports in Design View Section 11.2. The Report Wizard Section 11.3. The Label Wizard Section 11.4. Fine-Tuning Reports with Properties

file:///C|/html/0596527608/toc.html (2 of 4) [1/7/2007 7:04:36 AM]

Table of Contents

Section 11.5. Expressions Section 11.6. Grouping Part IV: Building a User Interface with Forms Chapter 12. Creating Simple Forms Section 12.1. Form Basics Section 12.2. Sorting and Filtering in a Form Section 12.3. Creating Better Layouts Section 12.4. The Form Wizard Chapter 13. Designing Advanced Forms Section 13.1. Customizing Forms in Design View Section 13.2. Taking Control of Controls Section 13.3. Forms and Linked Tables Chapter 14. Building a Navigation System Section 14.1. Mastering the Navigation Pane Section 14.2. Building Forms with Navigation Smarts Section 14.3. Linking to Related Data Part V: Programming Access Chapter 15. Automating Tasks with Macros Section 15.1. Macro Essentials Section 15.2. Macros and Security Section 15.3. Three Macro Recipes Section 15.4. Managing Macros Section 15.5. Connecting Macros to Forms Section 15.6. Conditional Macros Chapter 16. Automating Tasks with Visual Basic Section 16.1. The Visual Basic Editor Section 16.2. Putting Code in a Form Section 16.3. Understanding Objects Section 16.4. Using Objects Chapter 17. Writing Smarter Code Section 17.1. Exploring the VB Language Section 17.2. Dealing with Trouble Section 17.3. Deeper into Objects Section 17.4. Using VB to Run a Better Business Part VI: Sharing Access with the Rest of the World Chapter 18. Sharing a Database with Multiple Users Section 18.1. Opening Up Your Database to the World

file:///C|/html/0596527608/toc.html (3 of 4) [1/7/2007 7:04:36 AM]

Table of Contents

Section 18.2. Preparing Your Database Section 18.3. Playing Well with Others Section 18.4. Data Corruption Section 18.5. Securing Your Database Chapter 19. Importing and Exporting Data Section 19.1. Case for Importing and Exporting Section 19.2. Using the Clipboard Section 19.3. Import and Export Operations Section 19.4. Access and XML Section 19.5. Collecting Info by Email Chapter 20. Connecting Access to SQL Server Section 20.1. Should You Switch to SQL Server? Section 20.2. Getting Started: SQL Server 2005 Express Section 20.3. Creating a SQL Server Database Section 20.4. Adding Objects to a SQL Server Database Chapter 21. Connecting Access to SharePoint Section 21.1. Understanding SharePoint Section 21.2. Setting Up SharePoint Section 21.3. SharePoint and Access Part VII: Appendix Appendix A. Customizing the Quick Access Toolbar Section A.1. The Quick Access Toolbar Colophon Index SYMBOL A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

file:///C|/html/0596527608/toc.html (4 of 4) [1/7/2007 7:04:36 AM]

Copyright

Acce ss 2 0 0 7 : Th e M issin g M a n u a l by Mat t hew McDonald Copyright © 2007 O'Reilly Media, I nc. All right s reserved. Print ed in t he Unit ed St at es of Am erica. Published by O'Reilly Media, I nc., 1005 Gravenst ein Highway Nort h, Sebast opol, CA 95472. O'Reilly books m ay be purchased for educat ional, business, or sales prom ot ional use. Online edit ions are also available for m ost t it les ( safari.oreilly.com ) . For m ore inform at ion, cont act our corporat e/ inst it ut ional sales depart m ent : ( 800) 998- 9938 or corporat [email protected] .

Ta ble Pr in t in g H ist or y: Decem ber 2006:

First Edit ion.

Nut shell Handbook, t he Nut shell Handbook logo, t he O'Reilly logo, and " The book t hat should have been in t he box" are regist ered t radem arks of O'Reilly Media, I nc. Access 2007: The Missing Manual, The Missing Manual logo, Pogue Press, and t he Pogue Press logo are t radem arks of O'Reilly Media, I nc. Many of t he designat ions used by m anufact urers and sellers t o dist inguish t heir product s are claim ed as t radem arks. Where t hose designat ions appear in t his book, and O'Reilly Media, I nc. was aware of a t radem ark claim , t he designat ions have been print ed in caps or init ial caps. While every precaut ion has been t aken in t he preparat ion of t his book, t he publisher and aut hor assum e no responsibilit y for errors or om issions, or for dam ages result ing from t he use of t he inform at ion cont ained herein.

This book uses RepKover™, a durable and flexible lay- flat binding. I SBN- 10: 0- 596- 52760- 8 I SBN- 13: 978- 0- 596- 52760- 0 [ M]

file:///C|/html/0596527608/access2007tm-PREF-1.html (1 of 2) [1/7/2007 7:05:02 AM]

Copyright

file:///C|/html/0596527608/access2007tm-PREF-1.html (2 of 2) [1/7/2007 7:05:02 AM]

The Missing Credits

The Missing Credits About the Author

M a t t h e w M a cD on a ld is an aut hor and program m er ext raordinaire. He's t he aut hor of Excel 2007: The Missing Manual, Creat ing Web Sit es: The Missing Manual, and over a dozen books about program m ing wit h t he Microsoft .NET Fram ework. I n a dim ly rem em bered past life, he st udied English lit erat ure and t heoret ical physics.

About the Creative Team Pe t e r M e ye r s ( edit or) works as an edit or at O'Reilly Media on t he Missing Manual series. He lives wit h his wife and cat s in New York Cit y. Em ail: pet er.m eyers@gm ail.com . Ju e l Bor t olu ssi ( t echnical reviewer) has worked as an Access dat abase developer for invent ory and asset m anagem ent syst em s in t he design, beverage, and publishing indust ries. She t hinks t his book would m ake a great classroom t ext book, providing st udent s wit h dat abase, Visual Basic, SQL, and SharePoint skills. Em ail: j [email protected] M ich a e l Sch m a lz ( t echnical reviewer) works in banking and perform s business and t echnology consult ing in a variet y of indust ries. He has done t echnical edit ing for O'Reilly on Microsoft Office books. Michael has a degree in finance from Penn St at e. He lives wit h his wife and daught er in Pennsylvania. Soh a ila Abdu la li ( copy edit or) is a freelance writ er and edit or. She has published a novel, several children's books, and num erous short st ories and art icles. She recent ly finished an et hnography of an aboriginal I ndian wom an. She lives in New York Cit y wit h her husband Tom and t heir sm all but larger- t hanlife daught er, Sam ara. She can be reached t hrough her Web sit e at www.sohailaink.com . Jill St e in be r g ( copy edit or) is a freelance writ er and edit or based in Seat t le, and has produced cont ent for O'Reilly, I nt el, Microsoft , and t he Universit y of Washingt on. Jill was educat ed at Brandeis Universit y, William s College, and St anford Universit y. Em ail: saysj ill@m ac.com .

Acknowledgements Writ ing a book about a program as sprawling and com plex as Access is a labor of love ( love of pain, t hat is) . I 'm deeply indebt ed t o a whole host of people, including t hose who helped m e t rack down all t he neat and nift y t hings you can do wit h t he lat est version of Office ( including bloggers ext raordinaire Jensen Harris and Erik Rucker) , t hose who kept t he book clear, concise, and t echnically accurat e ( Pet er Meyers, Sarah Milst ein, Brian Sawyer, Juel Bort olussi, and Michael Schm alz) , and t hose who put up wit h m e while I wrot e it ( m ore on t hat in a m om ent ) . I also owe t hanks t o m any people who worked t o get t his book form at t ed, file:///C|/html/0596527608/access2007tm-PREF-2.html (1 of 4) [1/7/2007 7:05:06 AM]

The Missing Credits

indexed, and print edyou can m eet m any of t hem on t he Missing Credit s page. Com plet ing t his book required a few sleepless night s ( and m any sleep- deprived days) . I ext end m y love and t hanks t o m y daught er Maya, who put up wit h it wit hout crying m ost of t he t im e; m y dear wife Faria, who m ost ly did t he sam e; and our m om s and dads ( Nora, Razia, Paul, and Ham id) , who cont ribut ed hours of babysit t ing, t ast y m eals, and general help around t he house t hat kept t his book on t rack. So t hanks everyonewit hout you half of t he book would st ill be t rapped inside m y brain!

The Missing Manual Series Missing Manuals are wit t y, superbly writ t en guides t o com put er product s t hat don't com e wit h print ed m anuals ( which is j ust about all of t hem ) . Each book feat ures a handcraft ed index. Recent and upcom ing t it les include: Access 2003 for St art ers: The Missing Manual by Kat e Chase and Scot t Palm er Access 2007 for St art ers: The Missing Manual by Mat t hew MacDonald AppleScript : The Missing Manual by Adam Goldst ein AppleWorks 6: The Missing Manual by Jim Elferdink and David Reynolds CSS: The Missing Manual by David Sawyer McFarland Creat ing Web Sit es: The Missing Manual by Mat t hew MacDonald Digit al Phot ography: The Missing Manual by Chris Grover and Barbara Brundage Dream weaver 8: The Missing Manual by David Sawyer McFarland eBay: The Missing Manual by Nancy Conner Excel 2003 for St art ers: The Missing Manual by Mat t hew MacDonald Excel 2003: The Missing Manual by Mat t hew MacDonald Excel 2007 for St art ers: The Missing Manual by Mat t hew MacDonald Excel 2007: The Missing Manual by Mat t hew MacDonald FileMaker Pro 8: The Missing Manual by Geoff Coffey and Susan Prosser Flash 8: The Missing Manual by E. A. Vander Veer Front 2003: The Missing Manual by Jessica Mant aro

file:///C|/html/0596527608/access2007tm-PREF-2.html (2 of 4) [1/7/2007 7:05:06 AM]

The Missing Credits

GarageBand 2: The Missing Manual by David Pogue Google: The Missing Manual, Second Edit ion by Sarah Milst ein, J.D. Biersdorfer, and Mat t hew MacDonald Hom e Net working: The Missing Manual by Scot t Lowe iMovie HD 6: The Missing Manual by David Pogue iPhot o 6: The Missing Manual by David Pogue iPod: The Missing Manual, Fift h Edit ion by J.D. Biersdorfer Mac OS X: The Missing Manual, Tiger Edit ion by David Pogue Office 2004 for Macint osh: The Missing Manual by Mark H. Walker and Franklin Tessler PCs: The Missing Manual by Andy Rat hbone Phot oshop Elem ent s 5: The Missing Manual by Barbara Brundage PowerPoint 2007 for St art ers: The Missing Manual by E. A. Vander Veer PowerPoint 2007: The Missing Manual by E. A. Vander Veer QuickBooks 2006: The Missing Manual by Bonnie Biafore Quicken for St art ers: The Missing Manual by Bonnie Biafore Swit ching t o t he Mac: The Missing Manual, Tiger Edit ion by David Pogue and Adam Goldst ein The I nt ernet : The Missing Manual by David Pogue and J.D. Biersdorfer Windows 2000 Pro: The Missing Manual by Sharon Crawford Windows XP for St art ers: The Missing Manual by David Pogue Windows XP Hom e Edit ion: The Missing Manual, Second Edit ion by David Pogue Windows XP Pro: The Missing Manual, Second Edit ion by David Pogue, Craig Zacker, and Linda Zacker Windows Vist a: The Missing Manual by David Pogue Windows Vist a for St art ers: The Missing Manual by David Pogue Word 2007 for St art ers: The Missing Manual by Chris Grover file:///C|/html/0596527608/access2007tm-PREF-2.html (3 of 4) [1/7/2007 7:05:06 AM]

The Missing Credits

Word 2007: The Missing Manual by Chris Grover

file:///C|/html/0596527608/access2007tm-PREF-2.html (4 of 4) [1/7/2007 7:05:06 AM]

Introduction

Introduction I n t he past , people have t ried a variet y of t echniques t o organize inform at ion. They've used Rolodexes, punch cards, cardboard boxes, vert ical files, Post - it not es, 10,000- page indexes, and ( when all else failed) large piles on t op of flat surfaces. But aft er m uch suffering, people discovered t hat com put ers were far bet t er at dealing wit h inform at ion, especially when t hat inform at ion's large, com plex, or changes frequent ly. That 's where Microsoft Access com es int o t he pict ure. Access is a t ool for m anaging dat abasescarefully st ruct ured cat alogs of inform at ion ( or dat a) . Dat abases can st ore j ust about any t ype of inform at ion, including num bers, pages of t ext , and pict ures. Dat abases also range wildly in sizet hey can handle everyt hing from your list of fam ily phone num bers t o a ginorm ous product cat alog for Aunt Et hel's Discount But t on Bout ique. I n t his book, you'll learn how t o design com plet e dat abases, m aint ain t hem , search for valuable nugget s of inform at ion, and build at t ract ive form s for quick and easy dat a ent ry. You'll even delve int o t he black art of Access program m ing, where you'll pick up valuable t ricks and t echniques t hat you can use t o aut om at e com m on t asks, even if you've never t ouched a line of code before. Best of all, t his book was writ t en from scrat ch for Access 2007, t he lat est and great est incarnat ion of Microsoft 's best selling dat abase soft ware. Access 2007's quit e a bit different from previous versions, wit h a slick new int erface t hat has com put er geeks buzzing. And for once, it 's not j ust a gim m ick. As you'll see in t his book, once you m ast er Access's new st yle, you'll be able t o build great dat abases in record t im e.

What You Can Do with Access The m odern world is filled wit h inform at ion. A Web search for a ho- hum t opic like " canned carrot s" net s m ore t han a m illion Web pages. As a result , it 's no surprise t hat people from all walks of life need great t ools t o st ore and m anage inform at ion. I t 's im possible t o describe even a fract ion of t he different dat abases t hat Access fans creat e every day. But j ust t o get you t hinking like a dat abase m aven, here are som e com m on t ypes of inform at ion t hat you can st ore handily in an Access dat abase: ● ● ● ● ●

Cat alogs of books, CDs, rare wine vint ages, risqué m ovies, or anyt hing else you want t o collect and keep t rack of Mailing list s t hat let you keep in t ouch wit h friends, fam ily, and co- workers Business inform at ion, like cust om er list s, product cat alogs, order records, and invoices List s of guest s and gift s for weddings and ot her celebrat ions List s of expenses, invest m ent s, and ot her financial planning det ails

Think of Access as a personal assist ant t hat can help you organize, updat e, and find any t ype of inform at ion. This help isn't j ust a convenienceit also let s you do t hings you could never accom plish on your own. I m agine you've j ust finished com piling a dat abase for your collect ion of 10,000 rare com ic books. On a whim , you decide t o t ake a look at all t he books writ t en in 1987. Or j ust t hose t hat feat ure Aquam an. Or t hose t hat cont ain t he words " special edit ion" in t he t it le. Perform ing t hese searches wit h a paper cat alog would t ake days. On an average com put er, Access can perform all t hree searches in under a second. Access is also t he king of sm all businesses, because of it s legendary powers of cust om izat ion. Aft er all, you can use virt ually any dat abase product t o creat e a list of cust om er orders. But only Access m akes it easy t o build a full user int erface for t hat dat abase ( as shown in Figure I - 1) .

The Two Sides of Access As you'll see, t here are act ually t wo separat e t asks you'll perform wit h Access: ● ●

D e sign in g you r da t a ba se . This t ask involves creat ing t ables t o hold dat a, queries t hat can ferret out im port ant pieces of inform at ion, form s t hat m ake it easy t o ent er inform at ion, and report s t hat produce at t ract ive print out s. D e a lin g w it h da t a . This t ask involves adding new inform at ion t o t he dat abase, updat ing what 's t here, or j ust searching for t he det ails you need. I n order t o do t his work, you use t he t ables, queries, form s, and report s t hat you've already built .

file:///C|/html/0596527608/access2007tm-PREF-3.html (1 of 20) [1/7/2007 7:05:23 AM]

Introduction

Figu r e I 1 . This sales database includes handy forms that sales people can use to place new orders (shown here), customer service representatives can use to sign up new customers, and warehouse staff can use to review outgoing shipments. Best of all, the people who are using the forms in the database don't need to know anything about Access. As long as a database pro (like your future self, once you've finished this book) has designed these forms, anyone can use them to enter, edit, and review data.

Most of t his book's dedicat ed t o t ask # 1creat ing and perfect ing your dat abase. This j ob's t he heart of Access, and it 's t he part file:///C|/html/0596527608/access2007tm-PREF-3.html (2 of 20) [1/7/2007 7:05:23 AM]

Introduction

t hat init ially seem s t he m ost daunt ing. I t 's also what separat es t he Access m ast ers from t he neophyt es. Once you've finished t ask # 1, you're ready t o m ove on t o t ask # 2act ually using t he dat abase in your day- t o- day life. Alt hough t ask # 1 is m ore challenging, you'll ( event ually) spend m ore t im e on t ask # 2. For exam ple, you m ight spend a couple of hours creat ing a dat abase t o keep t rack of your favorit e recipes, but you'll wind up ent ering new inform at ion and looking up recipes for years ( say, every t im e you need t o cook up dinner) .

Access vs. Excel Access isn't t he only Office product t hat can deal wit h list s and t ables of inform at ion. Microsoft Excel also includes feat ures for creat ing and m anaging list s. So what 's t he difference? Alt hough Excel's perfect ly good for sm all, sim ple am ount s of inform at ion, it j ust can't handle t he sam e quant it y and com plexit y of inform at ion as Access. Excel also falt ers if you need t o m aint ain m ult iple list s wit h relat ed inform at ion ( for exam ple, if you want t o t rack a list wit h your business cust om ers, and a list of t he orders t hey've m ade) . Excel forces you t o com plet ely separat e t hese list s, which m akes it harder t o analyze your dat a and int roduces t he possibilit y of inconsist ent inform at ion. Access let s you set up st rict links bet ween t ables, which prevent s t hese problem s.

UP TO SPEED The Benefits of a Good Database Many people use an address book t o keep t rack of close friends, dist ant relat ives, or annoying co- workers. For t he m ost part , t he low- t ech address book works great . But consider what happens if you decide t o st ore t he sam e inform at ion in an Access dat abase. Even t hough your cont act list isn't st oring Google- sized volum es of inform at ion, it st ill offers a few feat ures t hat you wouldn't have wit hout Access: ●









Ba ck u p. I f you've ever t ried t o decipher a phone num ber t hrough a coffee st ain, you know t hat som et im es it helps t o have t hings in elect ronic form . Once you place all your cont act inform at ion int o a dat abase, you'll be able t o preserve it in case of disast er, and print up as m any copies as you need ( each wit h som e or all of t he inform at ion showing) . You can even share your list wit h a friend who needs t he sam e num bers. Spa ce . Alt hough m ost people can fit all t he cont act s t hey need int o a sm all address book, a dat abase ensures you'll never fill up t hat " M" sect ion. Not t o m ent ion t hat t here are only so m any t im es you can cross out and rewrit e t he address for your it inerant Uncle Sy before you run out of room . Se a r ch in g. An address book organizes cont act s in one wayby nam e. But what happens once you've ent ered everyone in alphabet ical order by last nam e, and you need t o look up a cont act you vaguely rem em ber as Joe? Access can effort lessly handle t his search. I t can also find a m at ching ent ry by phone num ber, which is great if your phone gives you a log of m issed calls and you want t o figure out who's been pest ering you. Sh a r in g. Only one person at a t im e can edit m ost ordinary files, like Microsoft Word docum ent s and spreadsheet s. This lim it at ion causes a problem if you need your ent ire office t eam t o collaborat e on a pot luck m enu. But Access let s m ult iple people review and change your dat a at t he sam e t im e, on different com put ers. Chapt er 18 has t he full st ory. I n t e gr a t ion w it h ot h e r a pplica t ion s. Access int roduces you t o a realm of t im esaving possibilit ies, like m ail m erge. You can feed a list of cont act s int o a form let t er you creat e in Word, and aut om at ically generat e dozens of individually addressed let t ers. You'll see how t o do t his in Chapt er 19.

All t hese exam ples dem onst rat e solid reasons t o go elect ronic wit h alm ost any t ype of inform at ion.

Access also provides all sort s of feat ures t hat don't have any parallel in t he spreadsheet world, such as t he abilit y t o creat e cust om ized search rout ines, design finet uned form s for dat a ent ry, and print a variet y of snazzy report s. Of course, all t his isn't t o say t hat Access is bet t er t han Excel. I n fact , in m any cases you m ight want Excel t o part ner up wit h Access. Excel shines when crunching ream s of num bers t o creat e graphs, generat e st at ist ics, or predict t rends. Many organizat ions use Access t o st ore and m anage inform at ion, and t hen export a port ion of t hat inform at ion t o an Excel spreadsheet whenever t hey need t o analyze it . You'll learn how t o t ake t his st ep in Chapt er 19.

file:///C|/html/0596527608/access2007tm-PREF-3.html (3 of 20) [1/7/2007 7:05:23 AM]

Introduction

Note: Looking to polish up your Excel skills? Check out Excel 2007: The Missing Manual.

Access vs. SQL Server Microsoft provides anot her dat abase product t he indust rial- st rengt h SQL Server, which powers everyt hing from Microsoft 's own search engine t o t he NASDAQ st ock exchange. Clearly, SQL Server is big business, and m any Access fans wonder how t heir favorit e dat abase soft ware com pares. One of t he m ost im port ant differences bet ween Access and dat abase product s like SQL Server is t hat Access is a client - side dat abase. I n non- t echie t erm s, t hat m eans t hat Access runs right on your personal com put er. Dat abase engines like SQL Server are server- based: They st ore t he dat a on a high- powered server com put er, which you access from a garden variet y PC. ( This int eract ion happens over a local net work.) Server- based dat abases are m uch m ore com plex t o set up and m aint ain, but t hey provide enhanced perform ance and rock- solid st abilit y, even when t housands of people use t hem at once. However, t he only people t hat require high- end dat abases like SQL Server are large organizat ions. Am azon.com wouldn't last five m inut es if it had t o rely on an Access dat abase. But Access works j ust fine for m ost sm all and m id- sized businesses. I t 's also perfect for personal use. ( I f you st ill have lingering doubt s about whet her Access can m eet your needs, check out t he box " When Access I s Not Enough" in Sect ion 3.2.) Anot her im port ant difference bet ween Access and server- side dat abase product s is t hat Access is an all- in- one solut ion for st oring and int eract ing wit h dat a. Server- side dat abase engines like SQL Server focus exclusively on st oring dat a ( and sending t hat dat a t o ot her com put ers when t hey request it ) . However, t his single- m inded design has a sizable price. An ordinary person can't direct ly edit a dat abase t hat 's st ored by SQL Server. I nst ead, you need t o use yet anot her program t hat can t alk t o SQL Server and ask for t he inform at ion it needs. I n m ost cases, t his program needs t o be hand- built by a savvy program m er. I n ot her words, if you're using SQL Server, you need t o writ e a whole applicat ion before you can effect ively use your dat abase. Som et im es, Access fans do t urn int o SQL Server gurus. You can st art wit h a m odest Access dat abase and t hen st ep up t o SQL Server when your needs exceed what Access provides. The process isn't always seam less, but it 's possible. You can even keep using Access as a front - end t o m anage your SQL Server dat abase. You can learn about t his t rick in Chapt er 20.

The New Face of Access 2007 Ever since Microsoft Office conquered t he world ( way back in t he 1990s) , program s like Word, Excel, and Access haven't changed a lot . Alt hough a genuinely useful new feat ure appears once in a while, Microsoft spends m ore t im e wedging in odd gim m icks like a t alking paper clip.

WORD TO THE WISE When Access Is Not Enough I f you've picked up t his book, you probably have a good sense t hat Access will m eet your needs. But if you're in any doubt , a quick realit y check will confirm whet her you're on t he right pat h. The following list describes a few warning signs t hat suggest you and Access j ust aren't a good fit . I f you don't fall int o any of t hese cat egories, congrat ulat ionsyou're ready t o use t he m ost st raight forward and product ive dat abase soft ware anywhere! ●





You n e e d t o st or e h u ge volu m e s of in for m a t ion ( m or e t h a n 2 giga byt e s of da t a ) . You're unlikely t o hit t his m ark unless you're st oring large pict ures or ot her t ypes of digit al cont ent inside a dat abase. Most Access dat abases are several m ega- byt es in size ( about 1,000 t im es sm aller t han t he 2 GB lim it ) . You 'r e goin g t o sh a r e you r da t a ba se on a n e t - w or k , a n d m or e t h a n a doze n pe ople n e e d t o u se it a t on ce . I t 's difficult t o correct ly int erpret t his lim it . I t 's perfect ly fine for hundreds of people t o use your dat abase from t im e t o t im e, but problem s occur when a group of people are all j ockeying t o m ake changes t o t he sam e dat abase file at t he exact sam e inst ant . You need t o t est your dat abase t o figure out whet her you can cross t his lim it wit hout int roducing problem s. Chapt er 18 has m ore inform at ion about sharing Access wit h groups of people. You n e e d t o u se you r da t a ba se t o pow e r a W e b a pplica t ion . A Web applicat ion let s lot s of people access t he dat abase at once. Access probably can't keep up under t he st rain. I n t his sit uat ion, you're bet t er off wit h a server- side dat abase like SQL Server ( and a crack program m ing t eam t o help you out ) .

file:///C|/html/0596527608/access2007tm-PREF-3.html (4 of 20) [1/7/2007 7:05:23 AM]

Introduction

Access 2007 breaks t his pat t ern and int roduces som e of t he m ost dram at ic changes Office fans have seen since Office 95. The m ost obvious change is t he t horoughly revam ped user int erface ( t he windows, t oolbars, m enus, and keyboard short cut s you use t o int eract wit h Access) . Aft er spending far t oo long t rying t o sim plify t he haphazard, t oolbar- choked int erfaces in m ost Office applicat ions, Microsoft finally worked up t he courage t o redesign it all from scrat ch.

The Ribbon The Access 2007 ribbon is a super- t oolbar t hat replaces t he various t oolbars and m enus in previous versions.

Note: Access doesn't show the ribbon until you create a database. If you can't stand the suspense any longer, and you want to be able to look at the ribbon on your monitor as you read the next couple of pages, follow the instructions in Section 1.2.1 to create a blank database.

The ribbon's divided int o t ask- specific t absHom e, Creat e, Ext ernal Dat a, and so on. I nit ially, Access st art s out wit h four t abs ( alt hough ot her t abs appear when you perform specific t asks) . When you launch Access, you st art at t he Hom e t ab. Click Creat e ( as shown in Figure I - 2) , and you get access t o a slew of powerful com m ands t hat let you add new dat abase com ponent s.

Figu r e I - 2 . The ribbon's full of craftsmanlike detail. When you hover over a button, you don't see a paltry twoor threeword description in a yellow box. Instead, you see a friendly pop-up box with a complete minidescription. Here, the mouse is hovering

file:///C|/html/0596527608/access2007tm-PREF-3.html (5 of 20) [1/7/2007 7:05:23 AM]

Introduction

over the Table command.

Tip: Want to reclaim the screen real estate that the ribbon occupies? Just double-click the current tab, and the ribbon collapses, leaving only the row of tab titles visible. Double-click the tab again to pop the buttons back into sight. Section 1.4.2 has more about this feature.

Here's a quick snapshot of t he four basic ribbon t abs: ●







H om e gat hers t oget her a variet y of com m on com m ands, including t he fam iliar copy- and- past e t ools and form at t ing com m ands for t weaking font s and colors. You'll also find handy feat ures like sort ing, searching, and filt ering, all of which you'll t ackle in Chapt er 3. Cr e a t e has com m ands for insert ing all t he different dat abase obj ect s you'll learn about in t his book ( see Sect ion 1.2 for t he lowdown) . These include t he t ables t hat st ore dat a, t he queries t hat search it , t he form s t hat help you edit it , and t he report s t hat help you print it . Ex t e r n a l D a t a has com m ands for im port ing dat a int o Access and export ing it t o ot her program s. You'll also find feat ures for int egrat ing wit h Microsoft Share- Point Server. You'll use t hese com m ands in Part Six. D a t a ba se Tools feat ures t he pro t ools you'll use t o analyze a dat abase, link t ables, and scale up t o SQL Server. You'll also find t he com m ands for insert ing Visual Basic code, which you'll explore in det ail in Part Five.

I t 's wort h spending som e t im e get t ing accust om ed t o t he t ab- based ribbon. Try clicking one t ab aft er t he ot her, rifling back and fort h t hrough t he four sect ions t o see what t hey hold. You'll learn m ore about all t hese com m ands as you m ake your way t hrough t his book.

Tip: If you have a scroll mouse, you can breeze through the tabs even faster by moving the mouse pointer over the ribbon, and then moving the scroll wheel up or down.

One nice ribbon t ab feat ure is t hat t hey never changein ot her words, you don't see com m ands m yst eriously m oving around or winking out of exist ence. Microsoft designed t he ribbon t o be predict able, so com m ands always rem ain in t he sam e place. However, com m ands will change t heir arrangem ent a bit if you resize t he Access window, so t hat t hey bet t er use t he available space ( Figure I - 3) .

Figu r e I - 3 . This super-skinny Access window doesn't have much room for ribbon buttons. All the same commands file:///C|/html/0596527608/access2007tm-PREF-3.html (6 of 20) [1/7/2007 7:05:23 AM]

Introduction

that you saw in Figure I-2 are still in the ribbon, but now you see only small icons with no text. When you're in doubt about a button, hover over it to see its name.

NOSTALGIA CORNER Why Reinvent the Wheel? Som e Access vet erans are underst andably skept ical about t he new Access int erface. Aft er all, we've had t o suffer t hrough som e painful experim ent s. Past versions of Access have int roduced kooky ideas like personalized m enus t hat always seem t o hide j ust t he com m and you need, pop- up side panels t hat appear when you least expect t hem , and float ing t oolbars t hat end up st rewn across t he screen. I n realit y, all t he Office applicat ions have been st ruggling t o keep up wit h m ore t han a decade's wort h of new feat ures. The m enus in m ost Office program s haven't changed since Word 2.0 hit t he scene in t he early 1990s. I n t hose days, a basic m enu and a single t oolbar were j ust t he t icket , because t he num ber of com m ands was relat ively sm all. Today, t he Office program s are drowning in feat uresand t hey're cram m ed int o so m any different nooks and crannies t hat even pros don't know where t o look. That 's where t he new ribbon fit s in. Not only can you easily underst and and navigat e it , it provides one- st op shopping for everyt hing you need t o do. Microsoft 's user int erface designers have a new m ant ra: I t 's all in t he ribbon. I n ot her words, if you need t o find a feat ure, t hen look for it in one of t he t abs at t he t op of t he Access window. As you get accust om ed t o t his new syst em , you'll find it not only helps you quickly use your favorit e feat ures, it also helps you discover new feat ures j ust by browsing.

Using the Ribbon with the Keyboard I f you're a diehard keyboard lover, you'll be happy t o hear t hat you can t rigger ribbon com m ands wit h t he keyboard. The t rick's using keyboard accelerat ors, a series of keyst rokes t hat st art s wit h t he Alt key ( t he sam e keys you used t o use t o get t o a m enu) . When using a keyboard accelerat or, you don't hold down all t he keys at t he sam e t im e. ( As you'll soon see, som e of t hem have enough let t ers t o t ie your fingers up bet t er t han t he rowdiest gam e of Twist er.) I nst ead, you hit t he keys one aft er t he ot her. The t rick t o keyboard accelerat ors is t o underst and t hat once you hit t he Alt key, you do t wo t hings, in t his order:

file:///C|/html/0596527608/access2007tm-PREF-3.html (7 of 20) [1/7/2007 7:05:23 AM]

Introduction

Pick t h e cor r e ct r ibbon t a b. 2. I n t h a t t a b, ch oose a com m a n d. Before you can t rigger a specific com m and, you m ust select t he right t ab ( even if you're already t here) . Every accelerat or requires at least t wo key presses aft er you hit t he Alt key. You'll need even m ore if you need t o dig t hrough a subm enu. By now, t his whole process probably seem s hopelessly im pract ical. Are you really expect ed t o m em orize dozens of different accelerat or key com binat ions? Fort unat ely, Access is ready t o help you out wit h a new feat ure called KeyTips. Here's how it works: Once you press t he Alt key, let t ers m agically appear over every t ab in t he ribbon. Once you hit a key t o pick a t ab, let t ers appear over every but t on in t hat t ab. You can t hen press t he corresponding key t o t rigger t he com m and. Figure I - 4 shows how it works.

Figu r e I -4. Top: When you press Alt, Access pins KeyTips next to every tab, over the Office menu, and over the buttons in the Quick Access toolbar (more about the Office menu and the Quick Access toolbar in a moment). file:///C|/html/0596527608/access2007tm-PREF-3.html (8 of 20) [1/7/2007 7:05:23 AM]

Introduction

Bottom: If you follow up with A (for the Database Tools tab), you'll see letters next to every command in that tab. Now you can hit another key to run a command (for example, W moves your data to SQL Server). Don't bother trying to match letters with tab or button namesthe ribbon's got so many features packed into it that in many cases,

file:///C|/html/0596527608/access2007tm-PREF-3.html (9 of 20) [1/7/2007 7:05:24 AM]

Introduction

the letters don't mean anything at all.

Note: In some cases, a command may have two letters, and you need to press both keys, one after the other. You can back out of KeyTips mode at any time without triggering a command by pressing the Alt key again.

Som e ot her short cut keys don't use t he ribbon. These key com binat ions st art wit h t he Ct rl key. For inst ance, Ct rl+ C copies highlight ed t ext , and Ct rl+ S saves your current work. Usually, you find out about a short cut key by hovering over a com m and wit h t he m ouse. Hover over t he Past e but t on in t he ribbon's Hom e t ab, and you see a t oolt ip t hat t ells you it s t im esaving short cut key is Ct rl+ V. And if you've worked wit h a previous version of Access, you'll find t hat Access 2007 keeps m ost of t he sam e short cut keys.

NOSTALGIA CORNER Access 2003 Menu Shortcuts I f you've worked wit h a previous version of Access, you m ay have t rained yourself t o use m enu short cut skey com binat ions t hat open a m enu and pick out t he com m and you want . When you press Alt + E in Access 2003, t he Edit m enu pops open ( in t he m ain m enu) . You can t hen press t he S key t o choose t he Past e Special com m and. At first glance, it doesn't look like t hese keyboard short cut s am ount t o m uch in Access 2007. Aft er all, Access 2007 doesn't even have a m ain m enu! Fort unat ely, Microsoft went t o a lit t le ext ra t rouble t o m ake life easier for longt im e Access aficionados. You can st ill use your m enu short cut s, but t hey work in a slight ly different way. I f you hit Alt + E in Access 2007, a t oolt ip appears over t he t op of t he ribbon ( Figure I - 5) t hat let s you know you've st art ed t o ent er an Access 2003 m enu short cut . I f you go on t o press S, t hen you wind up at t he fam iliar Past e Special dialog box, because Access knows what you're t rying t o do. I t 's alm ost as t hough Access has an invisible m enu at work behind t he scenes. Of course, t his feat ure can't help you out all t he t im e. I t doesn't work if you're t rying t o use one of t he few com m ands t hat don't exist any longer. And if you need t o see t he m enu t o rem em ber what key t o press next , you're out of luck. Access j ust gives you t he t oolt ip.

Figu r e I - 5 . By pressing Alt+E, you've triggered the "imaginary" Edit menu. You can't actually file:///C|/html/0596527608/access2007tm-PREF-3.html (10 of 20) [1/7/2007 7:05:24 AM]

Introduction

see it (because it doesn't exist in Access 2007). However, the tooltip lets you know that Access is paying attention. You can now complete your action by pressing the next key for the menu command.

The Office Menu One sm all part of t he t radit ional Access m enu's left in Access 2007sort of. The t radit ional File m enu t hat let s you open, save, and print files has been t ransform ed int o t he Office m enu. You get t here using t he Office but t on, which is t he big, round logo in t he window's t op- left corner ( Figure I - 6) .

Figu r e I - 6 . The Office menu's bigger and easier to read

file:///C|/html/0596527608/access2007tm-PREF-3.html (11 of 20) [1/7/2007 7:05:24 AM]

Introduction

than a traditional menu. When you click it, it displays a list of menu commands (on the left) and a list of the databases you used recently (on the right).

You generally use t he Office m enu for t hree t hings: ● ● ●

Opening, creat ing, and saving your dat abase. You'll do plent y of t his in Chapt er 1. Print ing your work ( Chapt er 3) and sending it off t o ot her people by em ail ( Chapt er 19) . Configuring how Access behaves. Choose Access Opt ions at t he bot t om of t he m enu t o get t o t he Access Opt ions dialog box, an all- in- one hub for configuring Access set t ings.

There's one m enu quirk t hat t akes a bit of get t ing used t o. Som e Office m enu com m ands hide subm enus t hat have m ore com m ands. Take t he Print com m and. You can choose Print from t he Office m enu t o fire off a quick print out of your work. But if you click t he right - point ing arrow at t he edge of t he Print com m and ( or if you hover over it for a m om ent ) , t hen you see a subm enu wit h m ore opt ions, as shown in Figure I - 7.

Figu r e I - 7 . Print's both a clickable menu

file:///C|/html/0596527608/access2007tm-PREF-3.html (12 of 20) [1/7/2007 7:05:24 AM]

Introduction

command and a submenu. To see the submenu, you need to hover over Print (without clicking), or click the arrow at the right edge (shown here). The ribbon also has a few buttons that work this way.

The Quick Access Toolbar Keen eyes will have not iced t he t iny bit of screen real est at e t hat sit s on t he Office but t on's right side, j ust above t he ribbon ( Figure I - 8) . This bit of screen holds a series of t iny icons, like t he t oolbars in older versions of Access. This area's t he Quick Access t oolbar ( or QAT t o Access nerds) .

Figu r e I - 8 . The Quick Access toolbar puts the Save, Undo, and Redo commands right at your fingertips. Access singles out these commands because

file:///C|/html/0596527608/access2007tm-PREF-3.html (13 of 20) [1/7/2007 7:05:24 AM]

Introduction

people use them more frequently than any other commands. But as you'll learn in the Appendix, you can add anything you want here.

I f t he Quick Access t oolbar were not hing but a specialized short cut for t hree com m ands, it wouldn't be wort h t he bot her. However, t he nift y t hing about t he Quick Access t oolbar is t hat you can cust om ize it . I n ot her words, you can rem ove com m ands you don't use, and can add your own favorit es. The Appendix shows how. Microsoft 's deliberat ely kept t he Quick Access t oolbar very sm all. I t 's designed t o give a carefully cont rolled out let for t hose cust om izat ion urges. Even if you go wild st ocking t he Quick Access t oolbar wit h your own com m ands, t he rest of t he ribbon rem ains unchanged. ( And t hat m eans a co- worker or spouse can st ill use your com put er wit hout suffering a m igraine.)

The New Features in Access 2007 Access 2007's m ost im pressive enhancem ent is t he new int erface. But t he new look isn't t he only significant change. When Microsoft decided t o rework Access 2007, t hey creat ed a developm ent t eam t hat was seven t im es larger t han t he t eam t hat creat ed Access 2003. All t his ext ra m anpower allowed t hem t o m ake a num ber of long- await ed changes. Here are som e of t he highlight s: ●

A n e w a n d im pr ove d da t a ba se e n gin e . Longt im e Access pros know t hat Access uses t he Jet engine t o m anage operat ions ( like insert ing and updat ing dat a) behind t he scenes. Jet 's part of t he Microsoft operat ing syst em , so it 's rarely changed. But Access 2007 now has it s own cust om ized version of Jet , which let Access creat ors add new feat ures and finet une perform ance. The new dat abase engine goes hand- in- hand wit h a new dat abase file form at , as you'll see in Sect ion 1.2.2.

Note: Don't worry, Access 2007 is 100 percent backward compatible with earlier versions. That means you can keep using old-style Access 2003 databases in Access 2007, although you can't use a few features (like attachments and complex data, described next) until you upgrade to the new file format. ●





At t a ch m e n t s. One of t he nift iest new feat ures in Access is t he At t achm ent dat a t ype, which let s you st ore ent ire files in your dat abase, including pict ures, docum ent s, and spreadsheet s. ( Movies, m usic, and ot her heft y m edia files need not apply, as all Access dat abases have a 2 GB dat abase size lim it .) You'll learn how t o use at t achm ent s in Sect ion 2.3.8. Ea sy- t o- de sign for m s a n d r e por t s. Creat ing an at t ract ive dat a- ent ry form or print report used t o t ake a lot of fiddling. I n Access 2007, it 's m uch easier t hanks t o aut om at ic layout a feat ure t hat groups relat ed pieces of inform at ion t oget her in neat colum ns or t ables. There's even a new Layout view t hat let s you add form at t ing and see t he result s im m ediat ely. Com ple x da t a . Com plex dat a's an opt ional new feat ure t hat let s you st ore several values in one field ( or dat a " slot " ) . Com plex dat a can sim plify your life when you need t o link t ables t oget her. For exam ple, using com plex dat a, you can associat e several aut hors wit h a single book. The key reason for int roducing com plex dat a is t o support t he SharePoint int egrat ion feat ure ( next on t his list ) .

file:///C|/html/0596527608/access2007tm-PREF-3.html (14 of 20) [1/7/2007 7:05:24 AM]

Introduction

Note: Complex data isn't for everyone. Some database experts may find it an unnecessary and potentially confusing frill. In Chapter 5 you'll learn how to link tables, and you'll decide whether complex data is a useful shortcut you want to use. ●

Sh a r e Poin t in t e gr a t ion . SharePoint services are a popular set of feat ures designed t o help t eam s of people share inform at ion and collaborat e in an organizat ion. These feat ures are built int o t he Windows Server 2003 operat ing syst em . Using Access 2007, you can m anage and m odify inform at ion t hat 's st ored in a SharePoint list .

Note: You won't want to use SharePoint if you're content with the tools Access provides. However, you'll love the SharePoint integration features if you're already using SharePoint to store information or if you need to share data with lots of people, and an ordinary Access database just can't keep up. You'll learn more about how Access and SharePoint can work together in Chapter 21. ●

Be t t e r se cu r it y w h e n de a lin g w it h code . As you'll learn in Part Five, dat abase pros use m acros and handwrit t en program m ing code rout ines t o pull off t ricky t asks. However, Access is not oriously suspicious of any code, because it has no way t o verify t hat code won't do som et hing dangerous ( like delet ing your files) . As a result , Access has an aggravat ing habit of disabling all your code j ust t o be safe. I n Access 2007, you can use t he new t rust cent er t o specify what dat abases you're ready t o t rust , based on who creat ed t hem or where t hey're st ored. Access 2007 is also sm art er about recognizing safe code ( code t hat can't possibly cause dam age) , which it allows even in unt rust ed dat abases.

About This Book Despit e t he m any im provem ent s in soft ware over t he years, one feat ure hasn't im proved a bit : Microsoft 's docum ent at ion. I n fact , wit h Office 2007, you get no print ed user guide at all. To learn about t he t housands of feat ures included in t his soft ware collect ion, Microsoft expect s you t o read t he online help. Occasionally, t hese help screens are act ually helpful, like when you're looking for a quick descript ion explaining a m yst erious new funct ion. On t he ot her hand, if you're t rying t o learn how t o, say, creat e an at t ract ive chart , you'll find not hing bet t er t han t erse and occasionally crypt ic inst ruct ions. This book is t he m anual t hat should have accom panied Access 2007. I n t hese pages, you'll find st ep- by- st ep inst ruct ions and t ips for using alm ost every Access feat ure, including t hose you haven't ( yet ) heard of.

About the Outline This book is divided int o seven part s, each cont aining several chapt ers. ●













Pa r t On e : St or in g I n for m a t ion in Ta ble s. I n t his part , you'll build your first dat abase and learn how t o add and edit t ables t hat st ore inform at ion. Then you'll pick up t he real- world skills you need t o st op m ist akes before t hey happen, browse around your dat abase, and link t ables t oget her. Pa r t Tw o: M a n ipu la t in g D a t a w it h Qu e r ie s. I n t his part , you'll build queriesspecialized com m ands t hat can hunt down t he dat a you're int erest ed in, apply changes, and sum m arize vast am ount s of inform at ion. Pa r t Th r e e : Pr in t in g Re por t s. This part shows you how t o use report s t o t ake t he raw dat a in your t ables and form at it int o neat print out s, com plet e wit h fancy form at t ing and subt ot als. Pa r t Fou r : Bu ildin g a Use r I n t e r fa ce w it h For m s. I n t his part , you'll build form scust om ized windows t hat m ake dat a ent ry easy, even for Access newbies. Pa r t Five : Pr ogr a m m in g Acce ss. Now t hat you've m ast ered t he essent ials of dat abases, you're ready t o delve int o t he black art of Access program m ing. I n t his part , you'll use m acros and Visual Basic program m ing t o aut om at e com plex t asks and solve com m on challenges. Pa r t Six : Sh a r in g Acce ss w it h t h e Re st of t h e W or ld. I n t his part , you'll learn how t o pull your dat a out of ( or put your dat a int o) ot her t ypes of files, like t ext docum ent s and Excel spreadsheet s. You'll also see how t o use Access t o int eract wit h som e of Microsoft 's m ost powerful server soft ware: t he dat abase engine SQL Server and t he collaborat ion soft ware SharePoint Server. Pa r t Se ve n : Appe n dix . This book wraps up wit h an appendix t hat shows how t o cust om ize t he Quick Access t oolbar t o get easy access t o your favorit e com m ands.

About

These

Arrows

file:///C|/html/0596527608/access2007tm-PREF-3.html (15 of 20) [1/7/2007 7:05:24 AM]

Introduction

Throughout t his book, you'll find sent ences like t his one: " Choose Creat e Tables Table." This m et hod's a short hand way of t elling you how t o find a feat ure in t he Access ribbon. I t t ranslat es t o t he following inst ruct ions: " On t he ribbon, click t he Cr e a t e t ab. On t he t ab, look for t he Ta ble s sect ion. I n t he Tables box, click t he Ta ble but t on." ( Look back t o Figure I - 2 t o see t he but t on you're looking for.) As you saw back in Figure I - 3, t he ribbon adapt s it self t o different screen sizes. Depending on your Access window's size, t he but t on you need t o click m ay not include any t ext . I nst ead, it shows up as a sm all icon. I n t his sit uat ion, you can hover over t he m yst ery but t on t o see it s nam e before deciding whet her or not t o click it . I f you resize t he Access window so t hat it 's really sm all, you m ight run out of space for a sect ion alt oget her. I n t hat case, you get a single but t on t hat has t he sect ion's nam e. Click t his but t on, and t he m issing com m ands appear in a drop- down panel ( Figure I 9) .

Figu r e I - 9 . In this example, Access doesn't have the room to display the Home tab's Views, Records, or Find sections, so they're all replaced with buttons. If you click any of these buttons, then a panel appears with the content you're looking for.

file:///C|/html/0596527608/access2007tm-PREF-3.html (16 of 20) [1/7/2007 7:05:24 AM]

Introduction

Contextual tabs Alt hough nice, predict able t abs are a great idea, som e feat ures obviously m ake sense only in specific circum st ances. Say you st art designing a t able. You m ay have a few m ore feat ures t han when you're ent ering dat a. Access handles t his sit uat ion by adding one or m ore cont ext ual t abs t o t he ribbon, based on your current t ask. These t abs have addit ional com m ands t hat are lim it ed t o a specific scenario ( Figure I - 10) .

Figu r e I -10. When you're designing a form, a new contextual tab appears, named Datasheet, under the heading Table Tools. Contextual tabs always appear on the ribbon's right side.

When dealing wit h cont ext ual t abs, t he inst ruct ions in t his book always include t he t it le of t he t ab sect ion ( it 's Table Tools in Figure I - 10) . Here's an exam ple: " Choose Table Tools | Dat asheet Fields & Colum ns New Fields." Not ice t hat t his inst ruct ion's first part includes t he cont ext ual t ab t it le ( Table Tools) and t he t ab nam e ( Dat asheet ) , separat ed by t he | charact er.

Drop-down buttons From t im e t o t im e you'll encount er but t ons in t he ribbon t hat have short m enus at t ached t o t hem . Depending on t he but t on, t his m enu appears as soon as you click t he but t on, or it appears only if you click t he but t on's drop- down arrow, as shown in Figure I 11.

file:///C|/html/0596527608/access2007tm-PREF-3.html (17 of 20) [1/7/2007 7:05:24 AM]

Introduction

Figu r e I -11. Access lets you switch between several different views of your database. Click the bottom part of the View button to see the menu of choices shown here, or click the top part to switch to the next view in the list, with no questions asked.

When dealing wit h t his sort of but t on, t he last st ep of t he inst ruct ions in t his book t ells you what t o choose from t he drop- down Views View Design View." That t ells you t o select t he Hom e t ab, m enu. For exam ple, say you're direct ed t o " Hom e look for t he Views sect ion, click t he drop- down part of t he View but t on ( t o reveal t he m enu wit h ext ra opt ions) , and t hen choose Design View from t he m enu.

Note: Be on the look out for drop-down arrows in the ribbonthey're tricky at first. You need to click the arrow part of the button to see the full list of options. If you click the other part of the button, then you don't see the list. Instead, Access fires off the standard command (the one Access thinks is the most common choice), or the command you used most recently.

Ordinary menus As you've already seen, t he ribbon has t aken t he spot light from t radit ional t oolbars and m enus. However, in a couple of cases, you'll st ill use t he fam iliar Windows m enu, like when you use t he Visual Basic edit or ( in Chapt er 16) . I n t his case, t he arrows

file:///C|/html/0596527608/access2007tm-PREF-3.html (18 of 20) [1/7/2007 7:05:24 AM]

Introduction

refer t o m enu levels. The inst ruct ion " Choose File click t he Open com m and."

Open" m eans " Click t he File m enu heading. Then, inside t he File m enu,

You'll find t he sam e t hing when you use t he Office m enu. I nst ruct ions for t he Office m enu look som et hing like t his: " Choose Open." That t ranslat es t o " Click t he Office but t on in t he window's t op- left corner t o show t he Office m enu. Office but t on Next , choose Open from t he m enu."

About Shortcut Keys Every t im e you t ake your hand off t he keyboard t o m ove t he m ouse, you lose a few m icroseconds of t im e. That 's why m any experienced com put er fans use keyst roke com binat ions inst ead of t oolbars and m enus wherever possible. Ct rl+ S, for one, is a keyboard short cut t hat saves your current work in Access ( and m ost ot her program s) . When you see a short cut like Ct rl+ S in t his book, it 's t elling you t o hold down t he Ct rl key, and, while it 's down, press t he let t er S, and t hen release bot h keys. Sim ilarly, t he finger- t angling short cut Ct rl+ Alt + S m eans hold down Ct rl, t hen press and hold Alt , and t hen press S ( so t hat all t hree keys are held down at once) .

About Clicking This book gives you t hree kinds of inst ruct ions t hat require you t o use your com put er's m ouse or t rackpad. To click m eans t o point t he arrow cursor at som et hing on t he screen and t henwit hout m oving t he cursor at allpress and release t he left - side clicker but t on on t he m ouse ( or lapt op t rackpad) . To double- click, of course, m eans t o click t wice in rapid succession, again wit hout m oving t he cursor at all. And t o drag m eans t o m ove t he cursor while holding down t he but t on.

Examples As you read t his book, you'll see a num ber of exam ples t hat dem onst rat e Access feat ures and t echniques for building good dat abases. Many of t hese exam ples are available as Access dat abase files in a separat e download. Just surf t o www. m issingm anuals.com , click t he link for t his book, and t hen click t he " Missing CD" link t o visit a page where you can download a zip file t hat includes t he exam ples, organized by chapt er.

About MissingManuals.com At www.m issingm anuals.com , you'll find news, art icles, and updat es t o t he books in t he Missing Manual and For St art ers series. But t he Web sit e also offers correct ions and updat es t o t his book ( t o see t hem , click t he book's t it le, and t hen click Errat a) . I n fact , you're invit ed and encouraged t o subm it such correct ions and updat es yourself. I n an effort t o keep t he book as up t o dat e and accurat e as possible, each t im e we print m ore copies of t his book, we'll m ake any confirm ed correct ions you've suggest ed. We'll also not e such changes on t he Web sit e, so t hat you can m ark im port ant correct ions int o your own copy of t he book, if you like. I n t he m eant im e, we'd love t o hear your own suggest ions for new books in t he Missing Manual and For St art ers lines. There's a place for t hat on t he Web sit e, t oo, as well as a place t o sign up for free em ail not ificat ion of new t it les in t he series.

Safari® Enabled

When you see a Safari® Enabled icon on t he cover of your favorit e t echnology book, t hat m eans t he book is available online t hrough t he O'Reilly Net work Safari Bookshelf. Safari offers a solut ion t hat 's bet t er t han e- books. I t 's a virt ual library t hat let s you easily search t housands of t op t ech books, cut and past e code sam ples, download chapt ers, and find quick answers when you need t he m ost accurat e, current inform at ion. Try it for free at ht t p: / / safari.oreilly.com .

file:///C|/html/0596527608/access2007tm-PREF-3.html (19 of 20) [1/7/2007 7:05:24 AM]

Introduction

file:///C|/html/0596527608/access2007tm-PREF-3.html (20 of 20) [1/7/2007 7:05:24 AM]

Part I: Storing Information in Tables

Part I: Storing Information in Tables Ch a pt e r 1 : Cr e a t in g You r Fir st D a t a ba se Ch a pt e r 2 : Bu ildin g Sm a r t e r Ta ble s Ch a pt e r 3 : M a st e r in g t h e D a t a sh e e t : Sor t in g, Se a r ch in g, Filt e r in g, a n d M or e Ch a pt e r 4 : Block in g Ba d D a t a Ch a pt e r 5 : Lin k in g Ta ble s w it h Re la t ion sh ips

file:///C|/html/0596527608/access2007tm-PART-I.html [1/7/2007 7:05:26 AM]

Chapter 1. Creating Your First Database

1. Creating Your First Database Alt hough Microsoft won't adm it it , Access can be int im idat ingint im idat ing enough t o t rigger a cold sweat in t he m ost confident office worker. Even t hough Microsoft has spent m illions m aking Access easier t o use, m ost people st ill see it as t he m ost com plicat ed Office program on t he block. They're probably right . Access seem s m ore daunt ing t han any ot her Office program because of t he way t hat dat abases work. Quit e sim ply, dat abases need st rict rules. Ot her program s aren't as obsessive. For exam ple, you can fire up Word, and st art t yping a let t er st raight away. Or you can st art Excel, and launch right int o a financial report . But Access isn't nearly as freewheeling. Before you can ent er a st it ch of inform at ion int o an Access dat abase, you need t o creat e t hat dat abase's st ruct ure. And even aft er you've defined t hat st ruct ure, you'll probably want t o spend m ore t im e creat ing ot her useful t ools, like handy search rout ines and friendly form s t hat you can use t o sim plify dat a lookup and dat a ent ry. All of t his set up t akes effort , and a good underst anding of how dat abases work. I n t his chapt er, you'll conquer any Access resist ance you have and learn t o creat e a sim ple but funct ional dat abase. Along t he way, you'll get acquaint ed wit h t he slick new Access user int erface, and you'll learn exact ly what you can st ore in a dat abase. You'll t hen be ready t o t ackle t he fine art of dat abase design, covered in m ore det ail t hroughout t his book.

file:///C|/html/0596527608/access2007tm-CHP-1.html [1/7/2007 7:05:27 AM]

Section 1.1. Understanding Access Databases

1.1. Understanding Access Databases As you already know, a dat abase is a collect ion of inform at ion. I n Access, every dat abase is st ored in a single file. That file cont ains dat abase obj ect s, which are sim ply t he com ponent s of a dat abase. Dat abase obj ect s are t he m ain players in an Access dat abase. Alt oget her, you have six different t ypes of dat abase obj ect s: ●



● ● ● ●

Ta ble s st ore inform at ion. Tables are t he heart of any dat abase, and you can creat e as m any t ables as you need t o st ore different t ypes of inform at ion. A fit ness dat abase could t rack your daily running log, your invent ory of exercise equipm ent , and t he num ber of high- prot ein whey m ilkshakes you down each day, as t hree separat e t ables. Qu e r ie s let you quickly perform an act ion on a t able. Usually, t his act ion involves ret rieving a choice bit of inform at ion ( like t he 10 t op- selling food it em s at Ed's Roadside Dinner, or all t he purchases you m ade in a single day) . However, you can also use queries t o apply changes. For m s are at t ract ive windows t hat you creat e, arrange, and colorize. Form s provide an easy way t o view or change t he inform at ion in a t able. Re por t s help you print som e or all of t he inform at ion in a t able. You can choose where t he inform at ion appears on t he print ed page, how it 's grouped and sort ed, and how it 's form at t ed. M a cr os are m ini- program s t hat aut om at e cust om t asks. Macros are a sim ple way t o get cust om result s wit hout becom ing a program m er. M odu le s are files t hat cont ain Visual Basic code. You can use t his code t o do j ust about anyt hingfrom updat ing 10,000 records t o firing off an em ail. ( Chapt er 16 has t he full st ory on Visual Basic.)

Access gurus refer t o all t hese dat abase ingredient s as obj ect s because you m anage t hem all in essent ially t he sam e way. I f you want t o use a part icular obj ect , t hen you add it t o your dat abase, give it a nam e, and t hen fine- t une it . Lat er on, you can view your obj ect s, renam e t hem , or delet e ones you don't want anym ore.

Tip: Designing a database is the process of adding and configuring database objects. For those keeping score, an Access database can hold up to 32,768 separate objects.

I n t his chapt er, you'll consider only t he m ost fundam ent al t ype of dat abase obj ect : t ables. But first , you need t o learn a bit m ore about dat abases and t he Access environm ent .

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-1.html [1/7/2007 7:05:29 AM]

Section 1.2. Getting Started

1.2. Getting Started I t 's t im e t o begin your j ourney and launch Access. You'll st art at a spiffy Get t ing St art ed page ( Figure 1- 1) .

Figu r e 1 - 1 . The Getting, Started page is a bit of a cross between a Windows program and a Web page. Use the links on the left to browse through different categories of templates (ready-togo databases that you can download and fill with your own information). Or check out the links on the bottom, which show you the latest Access news and tips.

FREQUENTLY ASKED QUESTION Using Someone Else's Database

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-2.html (1 of 16) [1/7/2007 7:05:44 AM]

Section 1.2. Getting Started

Can I use an Access dat abase I didn't design? Alt hough every dat abase follows t he sam e t wo- st ep process ( first som ebody creat es it , and t hen people fill it wit h inform at ion) , t he sam e person doesn't need t o perform bot h j obs. I n fact , in t he business world, different people oft en work separat ely on t hese t wo t asks. For exam ple, a sum m er st udent whiz kid at a beer st ore m ay build a dat abase for t racking orders ( t ask # 1) . The sales depart m ent can t hen use t he dat abase t o ent er new orders ( t ask # 2) , while ot her em ployees look up orders and fill t hem ( also t ask # 2) . Warehouse st aff can m ake sure st ock levels are OK ( again, t ask # 2) , and t he resident account ant can keep an eye on t ot al sales ( t ask # 2) . I f t ask # 1 ( creat ing t he dat abase) is done well, t ask # 2 ( using t he dat abase) can be ext rem ely easy. I n fact , if t he dat abase is well designed, people who have lit t le under- st anding of Access can st ill use it t o ent er, updat e, and look up inform at ion. Am azingly, t hey don't even need t o know t hey're running Access at all! You'll learn m ore about sharing Access wit h groups of people in Chapt er 18.

The Get t ing St art ed page looks a lit t le dizzying at first glance, but it really serves j ust t hree purposes: ● ● ●

I t sh ow s you r e ce n t con t e n t fr om M icr osoft 's Office On lin e W e b sit e . For exam ple, you can read helpful art icles about Access, find t im esaving t ips, or download updat es. All links open in a separat e browser window. I t le t s you ope n a da t a ba se you u se d r e ce n t ly. Look for t he Open Recent Dat abase sect ion on t he right , which gives you a list . I t le t s you cr e a t e a n e w da t a ba se . You can st art off wit h an em pt y dat abase ( use t he Blank Dat abase but t on) , or you can t ry t o find a ready- m ade t em plat e t hat fit s t he bill.

UP TO SPEED Templates: One Size Fits Some Tem plat es are prebuilt dat abases. Tem plat es aim t o save you t he work of creat ing your dat abase, and let you j um p st raight t o t he fine- t uning and dat a- ent ry st age. As you m ight expect , t here's a price t o be paid for t his convenience. Even if you find a t em plat e t hat st ores t he t ype of inform at ion you want t o t rack, you m ight find t hat t he pre- defined st ruct ure isn't quit e right . For exam ple, if you choose t o use t he Hom e I nvent ory t em plat e t o t rack all t he st uff in your basem ent , you m ight find t hat it 's m issing som e inform at ion you want t o use ( like t he proj ect ed resale value of your st uff on eBay) and includes ot her det ails you don't care about ( like t he dat e you acquired each it em ) . To m ake t his t em plat e work, you'll need t o change t he design of your t able, which involves t he sam e Access know- how as creat ing one. I n t his book, you'll learn how t o build your own dat abases from t he ground up and cust om ize every square inch of t hem . Once you're an Access m ast er, you can spend m any fun hours playing wit h t he prebuilt t em plat es and adapt ing t hem t o suit your needs.

You m ay t hink t hat it would be nice t o cust om ize t he Get t ing St art ed page. Access does let you do so, but it 's not all t hat easyand it 's recom m ended only for organizat ions t hat want t o st andardize t he Get t ing St art ed page t o bet t er suit t heir em ployees. A business could add links t o a com pany Web sit e or a com m only used dat abase t em plat e. I f you're int erest ed in t his feat ure, you'll need anot her t ool: t he freely downloadable Access Developer's Toolkit , which you can search for at ht t p: / / m sdn.m icrosoft .com . ( This t ool wasn't yet released at t he t im e of t his writ ing.) The Get t ing St art ed page is only t he front door t o t he feat ures in Accesst here's lot m ore in st ore once you get rolling. You won't be able t o t ry out ot her part s of t he Access unt il you creat e a new dat abase, and t he next sect ion shows you how.

1.2.1. Creating a New Database I n t his chapt er, you'll slap t oget her a fairly st raight forward dat abase. The exam ple's designed t o st ore a list of prized bobblehead dolls. ( For t hose not in t he know, a bobblehead doll is a t oy figure wit h an out size head on a spring, hence t he signat ure " bobbling" m ot ion. Bobblehead dolls usually resem ble a fam ous celebrit y, polit ician, at hlet e, or fict ional charact er.)

UP TO SPEED Access Goes Online

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-2.html (2 of 16) [1/7/2007 7:05:44 AM]

Section 1.2. Getting Started

One of t he Get t ing St art ed page's neat est feat ures is t he way it get s live cont ent from t he Web. This process happens so seam lessly t hat you don't even know it 's t aking place. When you st art Access, it cont act s Microsoft 's highpowered Web servers behind t he scenes, and request s t he lat est inform at ion for t he box of links at t he bot t om of t he Get t ing St art ed page. From t im e t o t im e, you'll see t he cont ent in t his box change. One day, you m ay see a link for an art icle about m acro viruses, while t he next day you'll find an art icle wit h t im esaving t ips. ( When you click a link, t he art icle loads up in t he Access Help window, but don't be fooledt he cont ent 's st ill j ust a Web page t hat 's pulled off t he Office Online sit e.) A sim ilar m agic t akes place when you browse t hrough t he t em plat es ( by clicking one of t he cat egories under t he From Microsoft Office Online heading) . Once again, Access heads back t o t he Webt his t im e, t o get a list of suit able t em plat es. This Web- based syst em let s you benefit from recent developm ent s and new cont ent , and you don't have t o upgrade your Access soft ware. Of course, it goes wit hout saying t hat you won't see any updat es if your com put er can't connect t o t he I nt ernet . ( I nst ead, you'll be left looking at st ale cont ent indefinit ely.) I f you want t o browse a m uch larger cat alog of Access art icles and resources, you can head t o t he Office Online sit e on your own ( out side Access) , by surfing t o ht t p: / / office.m icrosoft .com in your favorit e browser.

Tip: You can get the Bobblehead database, and all the databases in this book, on the Web. Check out Section 3.4.2.3 in the Introduction for more details.

Here's how t o creat e a blank new dat abase: 1. On t h e Ge t t in g St a r t e d pa ge , click t h e Bla n k D a t a ba se bu t t on . A side panel appears on t he right ( see Figure 1- 2) . 2. Type in a file n a m e . Access st ores all t he inform at ion for a dat abase in a single file wit h t he ext ension. accdb ( which st ands for Access dat abase) . Don't st ick wit h t he nam e Access picks aut om at ically ( like Dat abase1.accdb) . I nst ead, pick som et hing m ore suit able. I n t his exam ple, Bobblehead.accdb does t he t rick. As wit h any ot her file, Access files can cont ain a com binat ion of let t ers, spaces, num bers, parent heses, hyphens ( - ) , and t he underscore ( _) . I t 's generally safest t o st ay away from ot her special charact ers, som e of which aren't allowed.

Note: Depending on your computer settings, Windows may hide file extensions. Instead of seeing the Access database file MyScandalousWedding.accdb in file-browsing tools like Windows Explorer, you may just see the name MyScandalousWedding (without the . accdb part on the end). In this case, you can still tell the file type by looking at the icon. If you see a small Access icon next to the file name (which looks like a key), that's your signal that you're looking at an Access database. If you see something else (like a tiny paint palette), you need to make a logical guess about what type of file it is.

Figu r e 1 - 2 . The database

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-2.html (3 of 16) [1/7/2007 7:05:44 AM]

Section 1.2. Getting Started

Bobblehead. accdb will be placed in the folder C: \Documents and Settings \Matt\My Documents. You can edit the file name by clicking in the File Name box, and you can browse to a different folder by clicking the folder icon.

3. Ch oose a folde r . Like all Office program s, Access assum es you want t o st ore every file you creat e in your personal My Docum ent s folder. I f t his isn't t he case, click t he folder icon t o show t he File New Dat abase dialog box, browse t o t he folder you want ( Figure 1- 3) , and t hen click OK. 4. Click t h e Cr e a t e bu t t on ( a t t h e bot t om - r igh t of t h e Acce ss w in dow ) . Access creat es your dat abase file and t hen pops up a dat asheet where you can get t o work creat ing your first t able. Once you creat e or open a dat abase, t he Access window changes quit e a bit . An im pressive- looking t oolbar ( t he ribbon) appears at t he t op of your screen, and a navigat ion pane shows up on t he left . You're now in t he cont rol cent er where you'll perform all your dat abase t asks ( as shown in Figure 1- 4) . The I nt roduct ion covers t he basics of how t he ribbon works. ( Jum p t o Sect ion 3.2 for t he full det ails.) But first , it 's t im e t o consider how you can m ake use of your brand- new, em pt y dat abase by adding a t able.

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-2.html (4 of 16) [1/7/2007 7:05:44 AM]

Section 1.2. Getting Started

Figu r e 1-3. The File New Database dialog box lets you choose where you'll store a new Access database file. It also gives you the option to create your database in the format used by previous versions of Access (. mdb). To do so, you need to choose either the 2000 or 20022003 format options from the "Save as type" list, as shown here. If you're running Windows Vista, you'll notice that the File New Database

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-2.html (5 of 16) [1/7/2007 7:05:44 AM]

Section 1.2. Getting Started

dialog box has a whole different look, but all the same features.

Figu r e 1-4. The navigation pane on the left lets you see different items (or objects) in your database. You can use the navigation pane to jump from a list of products to a list of customers and back again. The ribbon along the top groups together every Access command. This ribbon's the mission control that lets you perform various tasks with your database.

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-2.html (6 of 16) [1/7/2007 7:05:44 AM]

Section 1.2. Getting Started

The document window in the middle takes up the rest of the window. This window's where you'll do your work, such as designing tables and entering data.

WORD TO THE WISE Sharing Databases with Older Versions of Access Older versions of Access don't use t he .accdb form at . I f you t ry t o open Bobblehead.accdb in Access 2003, you'll get not hing m ore t han a blank st are and an error m essage. Earlier versions of Access use t he .m db file form at ( which st ands for Microsoft dat abase) . Alt hough Access 2007 is happy using bot h .accdb and .m db files, previous versions of Access recognize only .m db. ( And j ust t o m ake life m ore int erest ing, t he .m db form at act ually has t hree versions: t he really, really old original form at , a ret ooled version t hat appeared wit h Access 2000, and t he im proved- yet - again version t hat Microsoft int roduced wit h Access 2002 and reused for Access 2003.) Here's what you need t o know t o choose t he right form at for your new dat abases. The st andard .accdb form at 's t he best choice if you don't need t o worry about com pat ibilit y, because it has t he best perform ance and a few ext ra feat ures. But if you need t o share dat abases wit h ot her versions of Access, skip t he new kid on t he block, and rely inst ead on t he t est ed- and- t rue . m db form at . To creat e an old- st yle .m db dat abase file in Access 2007, use t he " Save as t ype" opt ion shown in Figure 1- 3. You can choose t he Access 2002- 2003 file form at , or t he even older Access 2000 form at . ( I f you're set on going back any furt her, say t he Access 95 form at , your best bet 's a t im e m achine.)

1.2.2. Understanding Tables Tables are inform at ion cont ainers. Every dat abase needs at least one t ablewit hout it , you can't st ore any dat a. I n a sim ple dat abase, like t he Bobblehead dat abase, a single t able ( which we'll call Dolls) is enough. But if you find yourself want ing t o st ore several list s of relat ed inform at ion, t hen you need m ore t han one t able. I n t he dat abase BigBudget Wedding.accdb, you m ight want t o keep t rack of t he guest s t hat you invit ed t o your wedding, t he gift s t hat you request ed, and t he loot t hat you act ually received. I n Chapt er 5, you'll see plent y of exam ples of dat abases t hat use m ult iple t ables. Figure 1- 5 shows a sam ple t able.

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-2.html (7 of 16) [1/7/2007 7:05:44 AM]

Section 1.2. Getting Started

Figu r e 1 5 . In a table, each record occupies a separate row. Each field is represented by a separate column. In this table, it's clear that you've added six bobblehead dolls. You're storing information for each doll in five fields (ID, Character, Manufacturer, PurchasePrice, and DateAcquired).

Before you st art designing t his t able, you need t o know som e very basic rules: ●





A t a ble 's n ot h in g m or e t h a n a gr ou p of r e cor ds. A record's a collect ion of inform at ion about a single t hing. I n t he Dolls t able, for exam ple, each record represent s a single bobblehead doll. I n a Fam ily t able, each record would represent a single relat ive. I n a Product s t able, each record would represent an it em t hat 's for sale. You get t he idea. Ea ch r e cor d's su bdivide d in t o fie lds. Each field st ores a dist inct piece of inform at ion. For exam ple, in t he Dolls t able, one field st ores t he person on whom t he doll's based, anot her field st ores t he price, anot her field st ores t he dat e you bought it , and so on. Ta ble s h a ve a r igid st r u ct u r e . I n ot her words, you can't bend t he rules. I f you creat e four fields, every record m ust have four fields ( alt hough it 's accept able t o leave som e fields blank if t hey don't apply) .

UP TO SPEED Database Planning for Beginners Many dat abase gurus suggest t hat before you fire up Access, you should decide exact ly what inform at ion you want t o st ore by brainst orm ing. Here's how it works. First , det erm ine t he t ype of list you want by finishing t his sent ence " I need a list of…." ( One exam ple: " I need a list of all t he bobblehead dolls in m y basem ent ." ) Next , j ot down all your m ust - have pieces of inform at ion on a piece of paper. Som e det ails are obvious. For exam ple, for t he bobblehead doll collect ion, you'll probably want t o keep t rack of t he doll's nam e, price, and dat e you bought it . Ot her det ails, like t he year it was produced, t he com pany t hat creat ed it , and a short descript ion of it s appearance or condit ion m ay require m ore t hought . Once you've com plet ed t his process and ident ified all t he im port ant bit s of dat a you need, you're ready t o creat e t he corresponding t able in Access. The bobblehead doll exam ple dem onst rat es an im port ant t hem e of dat abase design: First you plan t he dat abase, and t hen you creat e it using Access. I n Chapt er 5, you'll learn a lot m ore about planning m ore com plex dat abases.

1.2.3. Creating a Simple Table When you first creat e a dat abase, it 's alm ost em pt y. But in order t o get you st art ed, Access creat es your first dat abase obj ect a t able nam ed Table1. The problem is, t his t able begins life com plet ely blank, wit h no defined fields ( and no dat a) . I f you followed t he st eps t o creat e a new dat abase ( Sect ion 1.2.1) , you're already at t he Dat asheet view ( Figure 1- 5) , which is where you ent er dat a int o a t able. All you need t o do is cust om ize t his t able so t hat it m eet s your needs.

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-2.html (8 of 16) [1/7/2007 7:05:44 AM]

Section 1.2. Getting Started

There are t wo ways t o cust om ize a t able: ●



D e sign vie w let s you precisely define all aspect s of a t able before you st art using it . Alm ost all dat abase pros prefer Design view, and you'll st art using it in Chapt er 2. D a t a sh e e t vie w is where you ent er dat a int o a t able. Dat asheet view also let s you build a t able on t he fly as you insert new inform at ion. You'll use t his approach in t his chapt er.

The following st eps show you how t o t urn a blank new t able ( like Table1) int o t he Dolls t able using t he Dat asheet view: 1. To de fin e you r t a ble , you n e e d t o a dd you r fir st r e cor d. I n t his case, t hat m eans m ent ally picking a bobblehead doll t o add t o t he list . For t his exam ple, you'll use a nift y Hom er Sim pson replica.

Note: It doesn't matter which doll you enter first. Access tables are unsorted, which means they have no underlying order. However, you can sort them any way you want when you need to retrieve information later on. 2. I n t h e da t a sh e e t 's Add N e w Fie ld colu m n , t ype t h e fir st pie ce of in for m a t ion for t h e r e cor d ( se e Figu r e 1 - 6 ) . Based on t he sim ple analysis you perform ed earlier ( Sect ion 1.2.3) , you know t hat you need t o ent er four fields of inform at ion for every doll. For t he Hom er Sim pson doll, t his inform at ion is: " Hom er Sim pson" ( t he nam e) , " Fict ional I ndust ries" ( t he m anufact urer) , $7.99 ( t he price) , and t oday's dat e ( t he purchase dat e) . Alt hough you could st art wit h any field, it m akes sense t o begin wit h t he nam e, which is clearly an ident ifying det ail.

Figu r e 1 - 6 . To fill in your first record, start by entering something in the first field of information (like the doll name "Homer Simpson"). Then, hit Tab to jump to the second column, and then enter the second piece of information. Ignore the ID column for nowAccess adds that to every table to

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-2.html (9 of 16) [1/7/2007 7:05:45 AM]

Section 1.2. Getting Started

identify your rows.

3. Pr e ss Ta b t o m ove t o t h e n e x t fie ld, a n d r e t u r n t o st e p 2 . Repeat st eps 2 and 3 unt il you've added every field you need, being careful t o put each separat e piece of inform at ion int o a different colum n.

UP TO SPEED Pu t t in g Big Va lu e s in N a r r ow Colu m n s A colum n can hold ent ire paragraphs of inform at ion, so you m ay find yourself running out of space once you st art t yping. This phenom enon isn't a problem ( aft er all, you can j ust scroll t hrough your field it self while you're edit ing it ) , but it is annoying. Most people prefer t o see t he ent ire cont ant s of a colum n at once. Fort unat ely, you don't need suffer in silence wit h cram ped colum ns. To expand a colum n, j ust posit ion your m ouse at t he right edge of t he colum n header. ( To expand a colum n nam ed Field1, m ove your m ouse t o t he right edge of t he Field1 box.) Then, drag t he colum n t o t he right t o resize it as big as you want . I f you're j ust a bit im pat ient , t here's a short cut . Double- click t he right edge of t he colum n t o resize it t o fit t he largest piece of inform at ion t hat 's in t he colum n ( provided t his doesn't st ret ch t he colum n beyond t he edge of t he Access window) . That way, you aut om at ically get all t he room you need.

I f you want t o get a lit t le fancier, include t he currency sym bol ( $) when you ent er t he price, and m ake sure you put t he dat a in a recognized dat e form at ( like January 1, 2008 or 01- 01- 2008) . These clues t ell Access what t ype of inform at ion you're put t ing in t he colum n. ( I n Chapt er 2, you'll learn how t o t ake com plet e cont rol of t he t ype of dat a in each colum n and avoid possible m isunderst andings.) Figure 1- 7 shows t he finalized record.

Note: If you hit Tab without entering any information, you'll move to the next row and start inserting a new record. If you make a mistake, you can backtrack using the arrow keys.

Figu r e 1 - 7 . The only problem with the example so far is that as you enter a new record, Access creates spectacularly useless field names. You'll see its choices at the top of each column (they'll have names like Field1, Field2, Field3, and

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-2.html (10 of 16) [1/7/2007 7:05:45 AM]

Section 1.2. Getting Started

so on). The problem with using these meaningless names is that they might lead you to enter a piece of information in the wrong place. You could all too easily put the purchase price in the date column. To prevent these slipups, you need to set better field names.

4. I t 's t im e t o fix you r colu m n n a m e s. D ou ble - click t h e fir st colu m n t it le ( lik e Fie ld1 ) . The field nam e swit ches int o Edit m ode. 5. Type in a n e w n a m e , a n d t h e n pr e ss En t e r . Re t u r n t o st e p 4 . Repeat t his process unt il you've cleaned up all t he field nam es. The proper field nam es for t his exam ple are Charact er, Manufact urer, PurchasePrice, and Dat e- Acquired. Figure 1- 8 shows how it works.

Figu r e 1-8. To choose better field names, doubleclick the column title. Next, type in the real field name, and then

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-2.html (11 of 16) [1/7/2007 7:05:45 AM]

Section 1.2. Getting Started

press Enter. Section 2.5.1 has more about field naming, but for now just stick to short, text-only titles that don't include any spaces, as shown here.

Tip: Don't be too timid about tweaking your table. You can always rename fields later, or even add entirely new fields. (It's also possible to delete existing fields, but that has the drawback of also clearing out all the data that's stored in that field.) 6. Ch oose Office bu t t on

Sa ve ( or u se t h e Ct r l+ S sh or t cu t ) t o sa ve you r t a ble .

Access asks you t o supply a t able nam e ( see Figure 1- 9) . 7. Type a su it a ble t a ble n a m e , a n d t h e n click OK. Congrat ulat ions! The t able's now a part of your dat abase.

Figu r e 1 - 9 . A good table name's a short text title that doesn't have any spaces (like Dolls here).

Note: Technically, you don't need to save your table right away. Access prompts you to save it when you close the datasheet (by clicking the X at the document window's top-right corner), or when you close Access.

As you can see, creat ing a sim ple t able in Access is alm ost as easy as laying out inform at ion in Excel or Word. I f you're it ching Table from t he ribbon. But before you get t o t ry again, you can creat e anot her t able in your dat abase by choosing Creat e t o t hat st age, it m akes sense t o t ake a closer look at how you edit your t able.

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-2.html (12 of 16) [1/7/2007 7:05:45 AM]

Section 1.2. Getting Started

1.2.4. Editing a Table You now have a fully funct ioning ( albeit sim ple) dat abase, com plet e wit h one t able, which in t urn cont ains one record. Your next st ep's filling your t able wit h useful inform at ion. This oft en- t edious process is dat a ent ry. To fill t he Dolls t able, you use t he sam e dat asheet you used t o define t he t able. You can perform t hree basic t asks: ● ●



Edit in g a r e cor d. Move t o t he appropriat e spot in t he dat asheet ( using t he arrow keys or t he m ouse) , and t hen t ype in a replacem ent . You m ay also want t o use Edit m ode, which is described in t he next sect ion. I n se r t in g a n e w r e cor d. Move down t o t he bot t om of t he t able, t o t he row t hat has an ast erisk ( * ) on t he left . This row doesn't act ually exist unt il you st art t yping in som e inform at ion. At t hat point , Access creat es t he row and m oves t he ast erisk down t o t he next row underneat h. You can repeat t his process endlessly t o add as m any rows as you want ( Access can handle m illions) . D e le t in g a r e cor d. You have several ways t o rem ove a record, but t he easiest is t o right - click t he m argin im m ediat ely t o t he left of t he record, and t hen choose Delet e Record. Access asks you t o confirm t hat you really want t o rem ove t he select ed record, because you can't reverse t he change lat er on.

WORD TO THE WISE When in Doubt, Don't Delete Most seasoned dat abase designers rarely delet e records from t heir dat abases. Every ounce of inform at ion is im port ant . For exam ple, im agine you have a dat abase t hat list s t he product s t hat a m ail- order origam i com pany has for sale. You m ight t hink it m akes sense t o delet e product s once t hey've been discont inued and can't be ordered anym ore. But it t urns out t hat it m akes sense t o keep t hese old product records around. For exam ple, you m ight want t o find out what product cat egories were t he best sellers over t he previous year. Or m aybe a m anufact urer issues a recall of asbest os- laced paper, and you need t o t rack down everyone who ordered it . To perform eit her of t hese t asks, you need t o keep your product records. This hang- ont o- everyt hing rule applies t o any kind of dat abase. For exam ple, im agine you're t racking st udent enrollm ent at a t op- flight culinary academ y. When a class is finished, you can't j ust delet e t he class record. You m ight need it t o find out if a st udent has t he right prerequisit es for anot her course, what t eachers she's had in t he past , and so on. The sam e is t rue for em ployees who ret ire, prom ot ions t hat end, it em s t hat you used t o own but you've sold, and so on. You need t hem all ( and you probably need t o keep t hem indefinit ely) . I n m any cases, you'll add ext ra fields t o your t able t o help you separat e old dat a from t he new. For exam ple, you can creat e a Discont inued field in t he Product s t able t hat ident ifies product s t hat aren't available anym ore. You can t hen ignore t hose product s when you build an order- placem ent form .

1.2.4.1. Edit mode You'll probably spend a lot of t im e working wit h t he dat asheet . So set t le in. To m ake your life easier, it helps t o underst and a few det ails. As you already know, you can use t he arrow keys t o m ove from field t o field or row t o row. However, you m ight have a bit of t rouble edit ing a value. When you st art t yping, Access erases any exist ing cont ent . To change t his behavior, you need t o swit ch int o Edit m ode by pressing t he F2 key; in Edit m ode, your t yping doesn't delet e t he st uff t hat 's already in t hat field. I nst ead, you get t o change or add t o it . To swit ch out of Edit m ode, you press F2 again. Figure 1- 10 shows a closeup look at t he difference.

Tip: You can also switch in and out of Edit mode by double-clicking a cell.

Figu r e 1 1 0 . Top: Normal mode. If you start typing now, you'll immediately erase the existing text file:///C|/html/0596527608/access2007tm-CHP-1-SECT-2.html (13 of 16) [1/7/2007 7:05:45 AM]

Section 1.2. Getting Started

("Hobergarten"). The fact that all the text in the field's selected is a big clue that you're about to wipe it out. Bottom: Edit mode. The cursor shows where you're currently positioned in the current field. If you start typing now, you'll insert text in between "Hober" and "garten".

Edit m ode also affect s how t he arrow keys work. I n Edit m ode, t he arrow keys m ove t hrough t he current field. For exam ple, ) t o m ove t o t he next cell, you need t o m ove all t he way t o t he end of t he current t ext , and t hen press t he right arrow ( key again. But in Norm al m ode, t he arrow keys always m ove you from cell t o cell.

1.2.4.2. Shortcut keys Power users know t he fast est way t o get work done is t o use t ricky keyboard com binat ions like Ct rl+ Alt + Shift + * . Alt hough you can't always easily rem em ber t hese com binat ions, a couple of t ables can help you out . Table 1- 1 list s som e useful keys t hat can help you whiz around t he dat asheet .

Ta ble 1 - 1 . Ke ys for M ovin g Ar ou n d t h e D a t a sh e e t Ke y

Re su lt

Tab ( or Ent er)

Moves t he cursor one field t o t he right , or down when you reach t he edge of t he t able. This key also t urns off Edit m ode if it 's current ly swit ched on.

Shift + Tab

Moves t he cursor one field t o t he left , or up when you reach t he edge of t he t able. This key also t urns off Edit m ode. Moves t he cursor one field t o t he right ( in Norm al m ode) , or down when you reach t he edge of t he t able. I n Edit m ode, t his key m oves t he cursor t hrough t he t ext in t he current field. Moves t he cursor one field t o t he left ( in Norm al m ode) , or up when you reach t he edge of t he t able. I n Edit m ode, t his key m oves t he cursor t hrough t he t ext in t he current field. Moves t he cursor up one row ( unless you're already at t he t op of t he t able) . This key also t urns off Edit m ode. Moves t he cursor down one row ( or it m oves you t o t he " new row" posit ion if you're at t he bot t om of t he t able) . This key also t urns off Edit m ode.

Hom e

Moves t he cursor t o t he first field in t he current row. This key brings you t o beginning of t he current field if you're in Edit m ode.

End

Moves t he cursor t o t he last field in t he current row. This key brings you t o end of t he current field if you're in Edit m ode.

Page Down

Moves t he cursor down one screenful ( assum ing you have a large t able of inform at ion t hat doesn't all fit in t he Access window at once) . This key also t urns off Edit m ode.

Page Up

Moves t he cursor up one screenful. This key also t urns off Edit m ode.

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-2.html (14 of 16) [1/7/2007 7:05:45 AM]

Section 1.2. Getting Started

Ct rl+ Hom e

Moves t he cursor t o t he first field in t he first row. This key doesn't do anyt hing if you're in Edit m ode.

Ct rl+ End

Moves t he cursor t o t he last field in t he last row. This key doesn't do anyt hing if you're in Edit m ode.

Table 1- 2. list s som e convenient keys for edit ing records.

Ta ble 1 - 2 . Ke ys for Edit in g Re cor ds Ke y

Re su lt

Esc

Cancels any changes you've m ade in t he current field. This key works only if you use it in Edit m ode. Once you m ove t o t he next cell, change is applied. ( For addit ional cancellat ion cont rol, t ry t he Undo feat ure, described next .)

Ct rl+ Z

Reverses t he last edit . Unfort unat ely, t he Undo feat ure in Access isn't nearly as powerful as it is in ot her Office program s. For exam ple, Access allows you t o reverse only one change, and if you close t he dat asheet , you can't even do t hat . You can use Undo right aft er you insert a new record t o rem ove it , but you can't use t he Undo feat ure t o reverse a delet e operat ion.

Ct rl+ "

Copies a value from t he field t hat 's im m ediat ely above t he current field. This t rick's handy when you need t o ent er a bat ch of records wit h sim ilar inform at ion. Figure 1- 11 shows t his oft en- overlooked t rick in act ion.

Ct rl+ ;

I nsert s t oday's dat e int o t he current field. The dat e form at 's based on com put er set t ings, but expect t o see som et hing like 2412- 2007. You'll learn m ore about how Access works wit h dat es in Sect ion 2.3.5.

Ct rl+ Alt + Space

I nsert s t he default value for t he field. You'll learn how t o designat e a default value in Sect ion 4.1.2.

Figu r e 1-11. An Access user has been on an eBay buying binge and needs to add several dolls at once. With a quick Ctrl +" keystroke, the acquire date from the previous record's pasted into the current field.

1.2.4.3. Cut, copy, and paste

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-2.html (15 of 16) [1/7/2007 7:05:45 AM]

Section 1.2. Getting Started

Access, like virt ually every Windows program , let s you cut and past e bit s of inform at ion from one spot t o anot her. This t rick's easy using j ust t hree short cut keys: Ct rl+ C t o copy, Ct rl+ X t o cut ( sim ilar t o copy, but t he original cont ent 's delet ed) , and Ct rl + V t o past e. When you're in Edit m ode, you can use t hese keys t o copy what ever you've select ed. I f you're not in Edit m ode, t he copying or cut t ing operat ion grabs all t he cont ent in t he field.

GEM IN THE ROUGH Copying an Entire Record in One Step Usually, you'll use copy and past e wit h lit t le bit s and pieces of dat a. However, Access has a lit t le- known abilit y t hat let s you copy an ent ire record. To pull it off, follow t hese st eps: 1. Click t he m argin t o t he left of t he record you want t o copy. 2. This select s t he record. ( I f you want t o copy m ore t han one adj acent record, hold down Shift , and t hen drag your m ouse up or down unt il t hey're all select ed.) 3. Right - click t he select ion, and t hen choose Copy. 4. This copies t he cont ent t o t he clipboard. 5. Scroll t o t he bot t om of t he t able unt il you see t he new- row m arker ( t he ast erisk) . 6. Right - click t he m argin j ust t o t he left of t he new- row m arker, and t hen choose Past e. Prest oan exact duplicat e. ( Trut h be t old, one piece of dat a doesn't m at ch exact ly. Access updat es t he I D colum n for your past ed record, giving it a new num ber. That 's because every record needs t o have a unique I D. You'll learn why in Sect ion 2.4.1.)

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-2.html (16 of 16) [1/7/2007 7:05:45 AM]

Section 1.3. Saving and Opening Access Databases

1.3. Saving and Opening Access Databases Unlike ot her program s, Access doesn't require t hat you save your work. I t aut om at ically saves any changes you m ake. When you creat e a new dat abase ( Sect ion 1.2.1) , Access saves your dat abase file. When you add a t able or anot her obj ect t o t he dat abase, Access saves t he dat abase again. And when you ent er new dat a or edit exist ing dat a, Access saves t he dat abase alm ost inst ant aneously. This aut om at ic save process t akes place behind t he scenes, and you probably won't not ice anyt hing. But don't be alarm ed when you exit Access and it doesn't prom pt you t o save changes, as all changes are saved t he m om ent you m ake t hem .

1.3.1. Making Backups The aut om at ic save feat ure can pose a problem if you m ake a change m ist akenly. I f you're fast enough, you can use t he Undo feat ure t o reverse your last change ( Figure 1- 12) . However, t he Undo feat ure reverses only your m ost recent edit , so it 's no help if you edit a series of records and t hen discover t he problem . I t also doesn't help if you close your t able and t hen reopen it .

Figu r e 1-12. The Undo command appears in the Quick Access toolbar at the top left of the Access window (circled), so it's always available.

For t hese reasons, it 's a good idea t o m ake frequent dat abase backups. To m ake a dat abase backup, you sim ply need t o copy your dat abase file t o anot her folder, or m ake a copy wit h anot her nam e ( like Bobblehead_Backup1.accdb) . You can perform t hese t asks wit h Windows Explorer, but Access gives you an even easier opt ion. Just choose Office but t on Back Up Dat abase, and Access creat es a copy of your dat abase for you, in t he locat ion you choose ( Figure 1Manage 13) .

Note: It's still up to you to remember to back up your database. Access doesn't include an automatic backup feature, but you can use

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-3.html (1 of 11) [1/7/2007 7:05:52 AM]

Section 1.3. Saving and Opening Access Databases

another tool to periodically copy your database file. One example is the Windows Task Scheduler that's included with most versions of Windows. (You can read a quick no-nonsense Task Scheduler tutorial at www.pctechguide.com/tutorials/ScheduleTasks.htm.)

Figu r e 1-13. When you choose Office button Manage Back Up Database, Access fills in a suggested file name that incorporates the current date. That way, if you have several backup files, you can pick out the one you want.

GEM IN THE ROUGH Shrinking a Database

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-3.html (2 of 11) [1/7/2007 7:05:52 AM]

Section 1.3. Saving and Opening Access Databases

When you add inform at ion t o a dat abase, Access doesn't always pack t he dat a as com pact ly as possible. I nst ead, Access is m ore concerned wit h get t ing inform at ion in and out of t he dat abase as quickly as it can. Aft er you've been working wit h a dat abase for a while, you m ight not ice t hat it s size bloat s up like a weekold fish in t he sun. I f you want t o t rim your dat abase back t o size, you can use a feat ure called com pact ing. Manage Com pact and Repair Dat abase. The am ount of space To do so, j ust choose Office but t on you reclaim varies widely, but it 's not uncom m on t o have a 10 MB dat abase shrink down t o a quart er of it s size. The only problem wit h t he dat abase com pact ing feat ure is t hat you need t o rem em ber t o use it . I f you want t o keep your dat abases as sm all as possible at all t im es, you can swit ch on a set t ing t hat t ells Access t o com pact t he current dat abase every t im e you close it . Here's how: 1. Open t he dat abase t hat you want t o aut om at ically com pact . 2. Access Opt ions. Access opens t he Access Opt ions window where you can Choose Office but t on m ake a num ber of configurat ion changes. 3. I n t he list on t he left , choose Current Dat abase. 4. I n t he page on t he right , t urn on t he " Com pact on Close" checkbox. 5. Click OK t o save your changes. You can set t he " Com pact on Close" set t ing on as few or as m any dat abases as you want . Just rem em ber, it 's not swit ched on when you first creat e a new dat abase.

1.3.2. Saving a Database with a Different Name or Format I f you decide you want t o save your dat abase wit h a different nam e, in a different place, or using an older Access file form at , Save As, and t hen use one of t he opt ions in you can use t he t rust y Save As com m and. Begin by choosing Office but t on Figure 1- 14. Keep in m ind t hat , once Access creat es t he new dat abase file, t hat file's t he one it keeps using. I n ot her words, when you creat e a t able or edit som e dat a, Access updat es t he new file. ( I f you want t o go back t o t he old file, you eit her need t o open it in Access, or use Save As again.)

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-3.html (3 of 11) [1/7/2007 7:05:52 AM]

Section 1.3. Saving and Opening Access Databases

Figu r e 1-14. Make sure you click the rightpointing arrow next to the Save As menu command to see this submenu of choices. (Just clicking Save As performs the default option, which saves a copy of the currently selected database object, not your entire database.) Then, choose one of the options under the "Save the database in another format" heading.

1.3.3. Opening a Database Once you've creat ed a dat abase, it 's easy t o open it lat er. You can use any of t hese approaches: ●

Double- click a dat abase file. ( You can browse t o it using My Com put er, Windows Explorer, or j ust plop in on your deskt op.) Rem em ber, Access dat abases have t he file ext ension .accdb or .m db.

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-3.html (4 of 11) [1/7/2007 7:05:52 AM]

Section 1.3. Saving and Opening Access Databases ●

Launch Access, and t hen look for your dat abase in t he Open Recent Dat abase sect ion on t he right of t he Get t ing St art ed page. ( The sam e list 's available t hrough t he Office m enu, as shown in Figure 1- 15.)



Launch Access, choose Office but t on

Open, and t hen browse for your Access dat abase file.

Figu r e 1-15. The Office menu's Recent Documents list has the same list of files as the Open Recent Database section on the Getting Started page. But if you already have a database open, the Recent Documents list's more convenient, because you don't need to head back to the Getting Started page.

When you open a dat abase, you'll not ice som et hing a lit t le bizarre. Access pops up a m essage bar wit h a scary- sounding securit y warning ( Figure 1- 16) .

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-3.html (5 of 11) [1/7/2007 7:05:52 AM]

Section 1.3. Saving and Opening Access Databases

Figu r e 1-16. This security warning tells you that Access doesn't trust your databasein other words, it's opened your file in a special safe mode that prevents your database from performing any risky operations.

The securit y warning's a bit confusing, because right now your dat abase doesn't even at t em pt do anyt hing risky. However, once you st art building dat abases wit h code rout ines ( as described in Part Five) or when you st art using act ion queries ( Chapt er 8) , it 's a different st ory. At t hat point , you m ay want t o reconfigure Access so it recognizes your files and learns t o be a bit m ore t rust ing.

FREQUENTLY ASKED QUESTION What's with the .laccdb File? I see an ext ra file wit h t he ext ension .laccdb. What gives? So far, you've fam iliarized yourself wit h t he .accdb file t ype. But if you're in t he habit of browsing around wit h Windows Explorer, you m ay not ice anot her file t hat you didn't creat e, wit h t he crypt ic ext ension .laccdb. Along wit h Bobblehead. accdb, you m ay spot t he m yst erious Bobblehead.laccdb. Access creat es a .laccdb file when you open a dat abase file and rem oves it when you close t he dat abase, so you'll see it only while you ( or som eone else) is browsing t he dat abase. Access uses t he .laccddb t o t rack who's current ly using t he dat abase. The l st ands for lock, and it 's used t o m ake sure t hat if m ore t han one person's using t he dat abase at once, people can't m ake changes t o t he sam e record at t he sam e t im e ( which could cause all m anner of headaches) .

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-3.html (6 of 11) [1/7/2007 7:05:52 AM]

Section 1.3. Saving and Opening Access Databases

You'll learn m ore about how Access works wit h m ult iple users in Chapt er 18, but for now it 's safe t o ignore t he .laccddb file. You don't need t o include it in your backups.

I n t he m eant im e, you're probably wondering what you should do about t he m essage bar. You have t wo opt ions: ● ●

Click t he X at t he right side of t he m essage bar t o banish it . ( I t 'll reappear t he next t im e you open t he dat abase.) Tell Access t hat it can t rust your dat abases by designat ing a t rust ed locat iona folder on your hard drive where you st ore your dat abase files. You'll learn how t o set up a t rust ed locat ion in Sect ion 15.2.4.

1.3.4. Opening More Than One Database at Once Open com m and, Access closes t he current dat abase, and t hen opens t he one you Every t im e you use t he Office but t on chose. I f you want t o see m ore t han one dat abase at a t im e, you need t o fire up m ore t han one copy of Access at t he sam e t im e. ( Com put er geeks refer t o t his act ion as st art ing m ore t han one inst ance of a program .) I t 's alm ost em barrassingly easy. I f you double- click anot her dat abase file while Access is already open, t hen a second Access window appears in t he t askbar for t hat dat abase. You can also launch a second ( or t hird, or fourt h…) inst ance of Access from t he St art m enu, and t hen use Office but t on Open t o load up a different dat abase in each one.

1.3.5. Opening a Database Created in an Older Version of Access Open com m and t o open an Access dat abase t hat som ebody creat ed wit h a previous You can use t he Office but t on version of Access. ( See t he box " Sharing Dat abases wit h Older Versions of Access" in Sect ion 1.2.2 for m ore about different Access file form at s.)

POWER USERS' CLINIC Changing the Folder Access Uses for Databases Access always assum es you want t o st ore dat abases in t he My Docum ent s folder. And t hough you can choose a different locat ion every t im e you save or open a dat abase, if t here's anot her folder you need t o visit frequent ly, t hen it m akes sense t o m ake t hat your st andard dat abase st orage locat ion. You can configure Access t o use t his folder wit h j ust a few st eps: 1. Choose Office but t on

Access Opt ions. The Access Opt ions window appears.

2. I n t he list on t he left , choose Popular. 3. I n t he page on t he right , look for t he " Creat ing dat a- bases" heading. Underneat h, you'll find a " Default dat abase folder" t ext box. Type in t he folder you want t o use ( like C: \ MyDat abases) , or click Browse t o navigat e t o it . When you're finished, click OK t o save your changes.

Access handles old dat abase files different ly, depending on j ust how old t hey are. Here's how it works:

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-3.html (7 of 11) [1/7/2007 7:05:52 AM]

Section 1.3. Saving and Opening Access Databases

● ● ●

I f you open an Access 2002- 2003 file, you don't get any not ificat ion or warning. Access keeps t he current form at , and you're free t o m ake any changes you want . I f you open an Access 2000 file, you're also in for sm oot h sailing. However, if you change t he design of t he dat abase, t he new part s you add m ay not be accessible in Access 2000. I f you open an older Access file ( like one creat ed for Access 97, 95, or 2.0) , Access asks whet her you want t o convert t he dat abase or j ust open it ( see Figure 1- 17) .

Figu r e 1-17. Access gives you a choice when you open a database file that was created in Access 97, 95, or 2.0. If you choose to convert the database (click Yes), Access copies the existing database into a new database file, in Access 20022003 format. You can then edit this copy normally. If you choose to open the file:///C|/html/0596527608/access2007tm-CHP-1-SECT-3.html (8 of 11) [1/7/2007 7:05:52 AM]

Section 1.3. Saving and Opening Access Databases

database (click No), Access opens the original file without making a copy. You can still edit existing data and add new data, but you can't change the database's design.

Tip: You can always tell the current database's format by looking at the text in brackets in the Access window's title bar. If you open an Access 2002-2003 file, the title bar might read "Bobblehead: Database (Access 2002-2003 file format)".

When you open an old- school Access dat abase, you'll not ice som et hing else has changed. When you open a t able, it won't appear in a t abbed window ( like t he ones shown in Figure 1- 20) . I nst ead, t he t able opens in an ordinary window t hat can float wherever it want s inside t he m ain Access window. This seem s fine at first , unt il you open several t ables at once. Then, you're st uck wit h som e real clut t er, as shown in Figure 1- 18.

Figu r e 1-18. In an oldstyle Access database, different windows can overlap

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-3.html (9 of 11) [1/7/2007 7:05:52 AM]

Section 1.3. Saving and Opening Access Databases

each other. It's not long before the table you want is buried at the bottom of a stack of windows.

This som ewhat unfriendly behavior is designed t o be m ore like previous versions of Access. But don't worryyou can get back t o t he slick t abs even if you don't convert your dat abase t o t he new form at . All you need t o do is set a single configurat ion opt ion for your dat abase: 1. Ch oose Office bu t t on

Acce ss Opt ion s. Th e Acce ss Opt ion s w in dow a ppe a r s.

2. I n t h e list on t h e le ft , ch oose Cu r r e n t D a t a ba se . 3. Un de r t h e Applica t ion Opt ion s h e a din g, look for t h e D ocu m e n t W in dow s Opt ion s se t t in g, w h e r e you ca n ch oose Ove r la ppin g W in dow s ( t h e Acce ss 2 0 0 3 st a n da r d) or Ta bbe d W in dow s ( t h e w a ve of t h e fu t u r e ) . 4. Click OK. 5. Close a n d ope n you r da t a ba se so t h e n e w se t t in g t a k e s e ffe ct . For a ret ro t ouch, you can use t he sam e set t ing t o m ake a brand new Access dat abase use overlapping windows inst ead of t abs.

1.3.6. Creating Another Database New. Access t akes you back t o Creat ing a new dat abase is t he easiest t ask yet . You sim ply need t o choose Office but t on t he Get t ing St art ed page, where you can creat e a blank dat abase by clicking t he fam iliar Blank Dat abase but t on, as described earlier ( Sect ion 1.2.1) .

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-3.html (10 of 11) [1/7/2007 7:05:52 AM]

Section 1.3. Saving and Opening Access Databases

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-3.html (11 of 11) [1/7/2007 7:05:52 AM]

Section 1.4. The Navigation Pane

1.4. The Navigation Pane I t 's t im e t o st ep back and t ake a look at what you've accom plished so far. You've creat ed t he Bobblehead dat abase, and added a single dat abase obj ect : a t able nam ed Dolls. You've filled t he Dolls t able wit h several records. You don't have t he fancy windows, report s, and search rout ines t hat m ake a dat abase work really sm oot hly, but you do have t he m ost im port ant ingredient organized dat a. One issue you haven't t ackled yet is how you m anage t he obj ect s in your dat abase. For exam ple, if you have m ore t han one t able, you need a way t o m ove back and fort h bet ween t he t wo. That t ool's t he navigat ion pane, shown in Figure 1- 19.

Figu r e 1-19. Unhappy with the space consumed by the navigation pane? Click the Open/ Close button in the topright corner (top), and the navigation bar slides out of the way to give more room for the datasheet (bottom). Click the button again to expand it back into view.

1.4.1. Browsing Tables with the Navigation Pane The navigat ion pane shows t he obj ect s ( Sect ion 1.2) t hat are part of your dat abase, and it let s you m anipulat e t hem . However, you don't necessarily see all your dat abase obj ect s at all t im es. The navigat ion pane has several different viewing m odes, so you can hom e in on exact ly what int erest s you. When you first creat e a dat abase, t he navigat ion pane shows only t he t ables in your dat abase. That 's good enough for nowaft er all, your dat abase doesn't cont ain anyt hing but t he t ables you've creat ed. ( You'll learn how t o cust om ize t he navigat ion pane in Chapt er 14.)

To really t ry out t he navigat ion pane, you need a dat abase wit h m ore t han one t able. To give it a whirl, choose Creat e Table from t he ribbon t o add a new blank t able. Follow all t he st eps in Sect ion 1.2.3 t o define t he t able and insert a record or t wo.

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-4.html (1 of 4) [1/7/2007 7:05:56 AM]

Section 1.4. The Navigation Pane

Tip: Not sure what table to create? Try creating a Collectors table that tracks all the friends you know who share the same bobbleheaded obsession. Now try to come up with a few useful fields for this table (while remembering that there's no need to go crazy with the details yet), and then compare your version to the example in Figure 1-20.

Once you've added t he new t able, you see bot h t he new t able and t he old in t he navigat ion pane at t he sam e t im e. I f you want t o open a t able, t hen, in t he navigat ion pane, j ust double- click it . I f you have m ore t han one dat asheet open at once, t hen Access organizes t hem int o t abs ( see Figure 1- 20) .

Figu r e 1 2 0 . Using the navigation pane, you can open as many tables at once as you want. Access gives each datasheet a separate tabbed window. To move from one window to another, you just click the corresponding tab. If you're feeling a bit crowded, just click the X at the far right of the tab strip to close the current datasheet.

I f you open enough t ables, event ually all t he t abs you need won't fit . I n t his sit uat ion, Access adds t iny scroll but t ons t o t he left and right of t he t ab st rip. You can use t hese but t ons t o m ove t hrough all t he t abs, but it t akes longer.

GEM IN THE ROUGH Collapsing the Ribbon

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-4.html (2 of 4) [1/7/2007 7:05:56 AM]

Section 1.4. The Navigation Pane

Most people are happy t o have t he ribbon sit at t he t op of t he Access window, wit h all it s but t ons on hand. However, serious dat a crunchers dem and m axim um space for t heir dat a. They'd rat her look at anot her record of inform at ion t han a pum ped- up t oolbar. I f t his preference describes you, t hen you'll be happy t o find out you can collapse t he ribbon, which shrinks it down t o a single row of t ab t it les, as shown in Figure 1- 21. To do so, j ust double- click any t ab t it le. Even when t he ribbon's collapsed, you can st ill use all it s feat ures. Just click a t ab. I f you click Hom e, t he Hom e t ab pops up over your worksheet . As soon as you click t he but t on you want in t he Hom e t ab ( or click som ewhere else in t he Access window) , t he ribbon collapses it self again. The sam e t rick works if you t rigger a com m and in t he ribbon using t he keyboard, as described in Sect ion 3.2.1. I f you use t he ribbon only occasionally, or if you prefer t o use keyboard short cut s, it m akes sense t o collapse t he ribbon. Even when collapsed, t he ribbon com m ands are available; it j ust t akes an ext ra click t o open t he t ab. On t he ot her hand, if you m ake frequent t rips t o t he ribbon, or if you're learning about Access and you like t o browse t he ribbon t o see t he available feat ures, don't bot her collapsing it . The ext ra space t hat you'll lose is well wort h it .

Figu r e 1-21. Do you want to use every square inch of screen space for your data? You can collapse the ribbon (as shown here) by doubleclicking any tab. Click a tab to pop it open temporarily, or doubleclick a tab to bring the ribbon back for good. And if you want to perform the same trick without raising your fingers from the keyboard, then you can use the

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-4.html (3 of 4) [1/7/2007 7:05:56 AM]

Section 1.4. The Navigation Pane

shortcut key Ctrl +F1.

1.4.2. Managing Database Objects So far, you know how t o open a t able using t he navigat ion pane. However, opening t ables isn't all you can do wit h t he navigat ion pane. You can act ually perform t hree m ore sim ple t asks wit h any dat abase obj ect t hat shows up in t he navigat ion pane: ● ●



Re n a m e it . Right - click t he obj ect , and t hen choose Renam e. Then, t ype in t he new nam e, and t hen press Ent er. Go t his rout e if you decide your Dolls t able would be bet t er off nam ed DollsI nMyWorldRenownedCollect ion. Cr e a t e a copy. Right - click t he obj ect , and t hen choose Copy. Right - click anywhere in t he navigat ion pane, and t hen choose Past e. Access prom pt s you t o supply t he new copy's nam e. The copy- an- obj ect feat ure's useful if you want t o t ake an exist ing t able and t ry redesigning it , but you're not ready t o rem ove t he original copy j ust yet . D e le t e it . Right - click t he obj ect , and t hen choose Delet e. Access asks you t o confirm t his operat ion, because you can't reverse it .

Access gives you a few m ore opt ions for t ransferring dat abase obj ect s and t ucking t hem out of sight . You'll consider t hese feat ures lat er in t he book.

TIMESAVING TIP Creating a Shortcut to a Table You probably already know t hat you can place a Windows short cut on your deskt op t hat point s t o your dat abase file. To do so, Short cut , and t hen follow t he inst ruct ions t o pick your dat abase file and choose j ust right - click your deskt op, choose New a short cut nam e. Now, any t im e you want t o j um p back int o your dat abase, you can double- click your short cut . You probably don't know t hat you can creat e a short cut t hat opens a dat abase and navigat es direct ly t o a specific t able. I n fact , t his m aneuver's even easier t han creat ing a plainvanilla short cut . Just follow t hese st eps: 1. Resize t he Access window so it doesn't t ake up t he full screen, and t hen m inim ize any ot her program s. This way, you can see t he deskt op behind Access, which is essent ial for t his t rick. 2. Find t he t able you want t o use in t he navigat ion pane. Drag t his t able out of Access and over t he deskt op. 3. Release t he m ouse but t on. Access creat es a short cut wit h a nam e like " Short cut t o Dolls in Bobblehead. accdb" . Double- click t his short cut t o load t he Bobblehead dat abase and open a dat asheet right away for t he Dolls t able.

file:///C|/html/0596527608/access2007tm-CHP-1-SECT-4.html (4 of 4) [1/7/2007 7:05:57 AM]

Chapter 2. Building Smarter Tables

2. Building Smarter Tables I n t he previous chapt er, you learned how t o dish out dat abases and pop t ables int o t hem wit hout breaking a sweat . However, t here's bad news. The t ables you've been creat ing so far aren't up t o snuff. Most significant ly, you haven't explicit ly t old Access what t ype of inform at ion you int end t o st ore in each field of your t able. A dat abase t reat s t ext , num bers, dat es, and ot her t ypes of inform at ion different ly. I f you st ore num eric inform at ion in a field t hat expect s t ext , t hen you can't do calculat ions lat er on ( like find t he average value of your bobblehead dolls) , and you can't cat ch m ist akes ( like a bobblehead wit h a price value of " fourscore and t went y" ) . To prevent problem s like t hese, you need t o define t he dat a t ype of each field in your t able. This is t he cent ral t ask you'll t ackle in t his chapt er. Once you've m ast ered dat a t ypes, you're ready t o consider som e of t he finer point s of dat abase design.

file:///C|/html/0596527608/access2007tm-CHP-2.html [1/7/2007 7:05:58 AM]

Section 2.1. Understanding Data Types

2.1. Understanding Data Types All dat a's not creat ed equal. Consider t he Dolls t able you creat ed in Chapt er 1 ( Sect ion 1.2.3) . I t s fields act ually cont ain several different t ypes of inform at ion: ● ● ●

Te x t . The Charact er and Manufact urer fields. N u m be r s. The I D and PurchasePrice fields. D a t e s. The Dat eAcquired field.

You m ay nat urally assum e t hat t he PurchasePrice field always includes num eric cont ent , and t he Dat eAcquired field always includes som et hing t hat can be int erpret ed as a dat e. But if you haven't set t he dat a t ypes correct ly, Access doesn't share your assum pt ions, and doesn't follow t he sam e rules. When you creat e a new field in Dat asheet view, Access m akes an educat ed guess about t he dat a t ype by exam ining t he inform at ion you've j ust t yped in. I f you t ype 44, t hen Access assum es you're creat ing a num ber field. I f you t ype Jan 6, 2007, t hen Access recognizes a dat e. However, it 's easy t o confuse Access, which leads t o t he problem s shown in Figure 21.

Figu r e 2 1 . Here, Access doesn't recognize the date format used for the DateAcquired field when it was created. As a result, Access treats that field as ordinary text. You can enter dates in several different formats (which makes the DateAcquired information harder to read and impossible

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-1.html (1 of 2) [1/7/2007 7:06:00 AM]

Section 2.1. Understanding Data Types

to sort). You also let in completely nonsensical entries, like "fourscore bananas."

I n order t o prevent invalid ent ries, you need t o t ell Access what each field should cont ain. Once you set t he rules, Access enforces t hem rigorously. You put t hese requirem ent s in place using anot her windowt he Design view of your t able.

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-1.html (2 of 2) [1/7/2007 7:06:00 AM]

Section 2.2. Design View

2.2. Design View When you creat e a new dat abase, Access st art s you off wit h a single t able and shows t hat t able in Dat asheet view. ( As you learned last chapt er, Dat asheet view is t he grid- like view where you can creat e a t able and ent er dat a.) To swit ch t o Design View view, right - click t he t ab nam e ( like " Dolls: Table" ) , and t hen choose Design View. ( Or you can use t he Hom e View com m and, or t he View but t ons at t he bot t om of t he Access window. Figure 2com m and, t he Table Tools | Dat asheet 2 shows all your opt ions. All of t hese com m ands do t he sam e t hing, so pick whichever approach seem s m ost convenient .)

Note: If you've opened an old Access 2003 database, you won't see any tabs. Instead, you'll get a bunch of overlapping windows. You can remedy this problem and get your tabs back by following the instructions in Section 1.3.6. Or, if you want to keep the overlapping windows, just use the view buttons or the ribbon to change views (instead of the right-click-the-tab-title approach described above).

Figu r e 2-2. Right-click the tab name to see this menu. You can switch to Design view (choose Design View) and back again (choose Datasheet View). Alternatively, you can use the tiny view buttons in the window's bottom-right corner to jump back and forth. (Don't worry about the other two view buttons. You'll use those to analyze your data in a pivot table, as

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-2.html (1 of 5) [1/7/2007 7:06:05 AM]

Section 2.2. Design View

described in Chapter 9.)

I f you swit ch t o Design view on a brand- new t able t hat you haven't saved yet , Access asks you for a t able nam e. Access t hen saves t he t able before swit ching you t o Design view.

Tip: For a handy shortcut, you can create a new table and automatically start in Design view. To do this, choose Create

Tables

Table Design. However, when you take this route, your table doesn't include the very important ID column, so you need to add one, as described in Section 2.4.1.

While Dat asheet view shows t he cont ent in your t able, Design view shows only it s st ruct ure ( see Figure 2- 3) . You can use Design view t o add, rearrange, and rem ove fields, but you can't use it t o add new records. I n t he Dolls t able, you can use Design view t o add a Quant it y field t o keep t rack of doll duplicat es. However, you can't add your newly purchased Bono bobblehead wit hout swit ching back t o t he Dat asheet view. Design view isn't int ended for dat a ent ry. At first , Design view seem s quit e int im idat ing. To sim plify what you're looking at , you should st art by closing t he Propert y Sheet box on t he window's right side. ( The Propert y Sheet let s you set a few highly t echnical t able set t ings, none of which Propert y Sheet . I f you want t o bring it back you need t o consider right now.) To banish it , choose Table Tools | Design lat er, t hen j ust repeat t he sam e com m and.

2.2.1. Organizing and Describing Your Fields Design view allows you t o rearrange t he order of your fields, add new ones, renam e t he exist ing ones, and m ore. You can also do all t hese t hings in Dat asheet view, but Access gurus usually find it 's easier t o work in Design view, because you won't be dist ract ed by t he dat a in t he t able.

Figu r e 2-3. Design view lists the fields in your table, putting each in a separate row. Fields here are listed from top to bottom, but they appear in datasheet view ordered from left to right. Next to each field is its data type file:///C|/html/0596527608/access2007tm-CHP-2-SECT-2.html (2 of 5) [1/7/2007 7:06:05 AM]

Section 2.2. Design View

and an optional description. Underneath the field list, the Field Properties section shows more information about the currently selected field. Here, the navigation pane has been collapsed (Section 1.4) to provide extra space.

Here are a few sim ple ways you can change t he st ruct ure of your t able in Design view: ● ● ●

Add a n e w fie ld t o t h e e n d of you r t a ble . Scroll t o t he last row of t he field list , and t hen t ype in a new field nam e. This act ion's equivalent t o adding a new field in Dat asheet view. Add a n e w fie ld be t w e e n e x ist in g fie lds. Move t o t he field t hat 's j ust under t he place where you want t o add t he new field. Right - click t he field, and t hen choose I nsert Rows. Then, t ype a field nam e in t he new, blank row. M ove a fie ld. Drag t he gray square im m ediat ely t o t he left of t he field you want t o m ove, t o t he new posit ion.

Note: Remember, fields' order isn't all that important, because you can change the order in which you view the fields in Datasheet view. However, most people find it's easier to design a table if you organize the fields from the very start.





D e le t e a fie ld. Right - click t he gray square im m ediat ely t o t he left of t he field you want t o rem ove, and t hen choose Delet e Rows. Keep in m ind t hat when you rem ove a field, you also wipe out any dat a t hat was st ored in t hat field. This act ion isn't reversible, so Access prom pt s you t o confirm it 's really what you want t o do. Add a de scr ipt ion for a fie ld. Type in a sent ence or t wo in t he Descript ion colum n next t o t he appropriat e field. ( You m ight use " The celebrit y or fict ional charact er t hat t his bobblehead resem bles" as t he descript ion for t he Charact er field in t he Dolls t able, as shown in Figure 2- 4.)

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-2.html (3 of 5) [1/7/2007 7:06:05 AM]

Section 2.2. Design View

Figu r e 2-4. Descriptions can help you remember what's what if you need to modify a table later on. Descriptions are a great idea if more than one person maintains the same database, in which case you need to make sure your fields are as clear as possible. Descriptions also appear in the status bar when you're entering information in a table (see Figure 2-5).

Figu r e 2 - 5 . The status bar text tells you what goes in this column,

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-2.html (4 of 5) [1/7/2007 7:06:05 AM]

Section 2.2. Design View

based on the field description. Sadly, this feature isn't as useful as it seems, because most people never think to look down in the status bar.

2.2.2. How Updates Work in Design View Access doesn't im m ediat ely apply t he changes you m ake in Design view. I nst ead, it wait s unt il you close t he t able or swit ch back t o Dat asheet view. At t hat point , Access asks whet her you want t o save t he t able. ( The answer, of course, is Yes.) Som et im es, you m ay apply a change t hat causes a bit of a problem . You could t ry t o change t he dat a t ype of a field so t hat it st ores num bers inst ead of t ext . ( The box in Sect ion 2.3.1, " Changing t he Dat a Type Can Lose I nform at ion," discusses t his problem in m ore det ail.) I n t his sit uat ion, you won't discover t he problem unt il you close t he t able or swit ch back t o t he Dat asheet view, which m ight be a lit t le lat er t han you expect . I f you've m ade a pot ent ially problem at ic change and you j ust can't t ake t he suspense, you're bet t er off applying your updat e im m ediat ely, so you can see if t here's a problem before you go any furt her. To do so, click t he Quick Access t oolbar's Save but t on ( it 's t he disket t e icon in t he Access window's t op- left corner) , or j ust use t he keyboard short cut Ct rl+ S. Access applies your change, and t hen saves t he t able. I f it runs int o a problem , Access t ells you about it ( and let s you choose how you want t o fix it ) before you do anyt hing else wit h t he t able.

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-2.html (5 of 5) [1/7/2007 7:06:05 AM]

Section 2.3. Access Data Types

2.3. Access Data Types Design view's a m uch m ore powerful place for defining a t able t han Dat asheet view. As you'll see t hroughout t his chapt er, Design view allows you t o t weak all sort s of det ails t hat are hidden in Dat asheet view ( or j ust awkward t o change) . One of t hese is t he dat a t ype of your fielda set t ing t hat t ells Access what t ype of inform at ion you're planning t o st ore. To change t he dat a t ype, m ake a select ion in t he Dat a Type colum n next t o t he appropriat e field ( Figure 2- 6) . Here's where you separat e t he t ext from num bers ( and ot her dat a t ypes) . The t rick's choosing t he best dat a t ype from t he long list Access providesyou'll get m ore help in t he following sect ion.

Figu r e 2 - 6 . To choose a data type, click the Data Type column next to the appropriate field. A drop-down list box appears, with 11 choices.

Depending on t he dat a t ype you choose, t here are ot her field propert ies t hat you can adj ust t o nail down your dat a t ype even m ore precisely. I f you use a t ext dat a t ype, t hen you use field propert ies t o set t he m axim um lengt h. I f you choose a decim al value, t hen you use field propert ies t o set t he num ber of decim al places. You set field propert ies in t he Field Propert ies part of t he Design view, which appears j ust under t he field list . You'll learn m ore about field propert ies t hroughout t his chapt er ( and you'll consider t hem again in Chapt er 4) . The m ost im port ant decision you'll m ake for any field is choosing it s dat a t ype. The dat a t ype t ells Access what sort of inform at ion you plan t o st ore in t hat field. Access uses t his inform at ion t o rej ect values t hat don't m ake sense ( see Figure 2- 7) , t o perform proper sort ing, and t o provide ot her feat ures like calculat ions, sum m aries, and filt ering.

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-3.html (1 of 20) [1/7/2007 7:06:26 AM]

Section 2.3. Access Data Types

Figu r e 2-7. This currency field absolutely does not allow text. Access lets you fix the problem by entering a new value (the right choice) or changing the field data type to text so that it allows anything (the absolutely wrong choice).

Note: A field can have only one data type. You can't create a field that can store two or three different data types, because Access wouldn't have enough information to manage the field properly. (Instead, in this situation, you probably need two separate fields.)

As you learned earlier, t here are t hree basic t ypes of dat a in t he world: t ext , num bers, and dat es. However, Access act ually provides a whopping 11 dat a t ypes, which include m any m ore specialized choices. Before you pick t he right dat a t ype, it 's a good idea t o review all your choices. Table 2- 1 shows an overview of t he first 10 m enu opt ions in t he Dat a Type list . ( The Lookup wizard choice isn't included, because it isn't a real dat a t ype. I nst ead, t his m enu opt ion launches t he Lookup wizard, which let s you set a list of allowed values. You'll learn m ore about t his in Sect ion 4.4.1 in Chapt er 4.)

Ta ble 2 - 1 . Acce ss D a t a Type s D a t a Type

D e scr ipt ion

Ex a m ple s

Text

Num bers, let t ers, punct uat ion, and sym bols, up t o a m axim um of 255 charact ers ( an average- sized paragraph) .

Nam es, addresses, phone num bers, and product descript ions. This dat a t ype's t he m ost com m on.

Mem o

Large am ount s of unform at t ed t ext , up t o 65,536 charact ers ( an average- sized chapt er in a novel) .

Art icles, m em os, let t ers, arrest warrant s, and ot her short docum ent s.

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-3.html (2 of 20) [1/7/2007 7:06:26 AM]

Section 2.3. Access Data Types

Num ber

A variet y of different kinds of num bers, including negat ive num bers and t hose t hat have decim al places.

Any t ype of num ber except dollar values. St ores m easurem ent s, count s, and percent ages.

Currency

Sim ilar t o Num ber, but opt im ized for num bers t hat represent values of m oney.

Prices, paym ent s, and expenses.

Dat e/ Tim e

A calendar dat e or t im e of day ( or bot h) . Don't use t his field for t im e int ervals ( t he num ber of m inut es in a song, t he lengt h of your workout session) inst ead, use t he Num ber dat a t ype.

Birt hdat es, order dat es, ship dat es, appoint m ent s, and UFO sight ing t im es.

Yes/ No

Holds one of t wo values: Yes or No. ( You can also t hink of t his as True or False.)

Fields wit h exact ly t wo opt ions, like m ale/ fem ale or approved/ unapproved.

Hyperlink

A URL t o a Web sit e, an em ail address, or a file pat h.

www.Fant asyPet s.com , noreplies@ant isocial.co.uk, f: \ Docum ent s\ Report .doc.

At t achm ent

One or m ore separat e files. The cont ent from t hese files is copied int o t he dat abase.

Pict ures, Word docum ent s, Excel spreadsheet s, sound files, and so on.

Aut oNum ber

St ores a num ber t hat Access generat es when you insert a new record. Every record aut om at ically get s a unique num ber t hat ident ifies it .

Used t o uniquely ident ify each record, especially for a prim ary key ( Sect ion 2.4) . Usually, t he field's nam ed I D.

OLE Obj ect

Holds em bedded binary dat a, according t o t he Windows OLE ( obj ect linking and em bedding) st andard. Rarely used, because it leads t o dat abase bloat and ot her problem s. The At t achm ent field's alm ost always a bet t er choice.

Som e t ypes of pict ures and docum ent s from ot her program s. Most ly used in old- school Access dat abases. Nowadays, dat abase designers use t he At t achm ent dat a t ype inst ead of t he OLE Obj ect dat a t ype.

The following sect ions describe each dat a t ype except for OLE Obj ect , which is a holdover from t he dark ages of Access dat abases. Each sect ion also describes any im port ant field propert ies t hat are unique t o t hat dat a t ype.

2.3.1. Text Text is t he all- purpose dat a t ype. I t accept s any com binat ion of let t ers, num bers, and ot her charact ers. So you can use a t ext field for a word or t wo ( like " Mary Poppins" ) , a sent ence ( " The candidat e is an English nanny given t o flight s of song." ) , or anyt hing else ( " @# $d sf_&! " ) .

WORD TO THE WISE Changing the Data Type Can Lose Information The best t im e t o choose t he dat a t ypes for your fields is when you first creat e t he t able. That way, your t able's com plet ely em pt y, and you won't run int o any problem s. I f you add a few records, and t hen decide t o change t he dat a t ype in one of your fields, life becom es a lit t le m ore com plicat ed. You can st ill use Design view t o change t he dat a t ype, but Access needs t o go t hrough an ext ra st ep and convert t he exist ing dat a t o t he new dat a t ype. I n m any cases, t he conversion process goes sm oot hly. I f you have a t ext field t hat cont ains only num bers, you won't have a problem changing t he dat a t ype from Text t o Num ber. But in ot her cases, t he t ransit ion isn't quit e so seam less. Here are som e exam ples of t he problem s you m ight run int o: ● ● ●

You change t he dat a t ype from Text t o Dat e, but Access can't int erpret som e of your values as dat es. You change t he dat a t ype from Text t o Num ber, but som e of your records have t ext values in t hat field ( even t hough t hey shouldn't ) . You change t he dat a t ype from Text t o Num ber. However, your field cont ains fract ional num bers ( like 4.234) , and you forget t o change t he Field Size propert y ( Sect ion 2.3.3.1) . As a result , Access assum es you want t o use only whole num bers, and chops off all your decim al places.

The best way t o m anage t hese problem s is t o m ake a backup ( Sect ion 1.3.1) before you m ake any drast ic changes, and be on t he lookout for changes t hat go wrong. I n t he first t wo cases in t he list above, Access warns you t hat it needs t o rem ove som e values because t hey don't fit t he dat a t ype rules ( see Figure 2- 8) . The t hird problem 's a lit t le m ore insidiousAccess gives you a warning, but it doesn't act ually t ell you whet her or not a problem occurred. I f you suspect t rouble, swit ch t o Design view, and t hen check out your dat a before going any furt her.

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-3.html (3 of 20) [1/7/2007 7:06:26 AM]

Section 2.3. Access Data Types

Figu r e 2 - 8 . Don't say you weren't warned. Here, Access lets you know (in its own slightly obscure way) that it can't make the change you wantmodifying the data type of field from Text to Datewithout throwing out the values in four records. The best course of action is to click No to cancel the change and then take a closer look at your table in Datasheet view to track down the problematic values.

Note: Because text fields are so lax, you can obviously enter numbers, dates, and just about anything else in them. However, you should use text only when you're storing some information that can't be dealt with using another data type, because Access always treats the contents of a text field as plain, ordinary text. In other words, if you store the number 43.99 in a text field, Access doesn't realize you're dealing with numbers, and it doesn't let you use it in a calculation.

Som et im es it seem s t hat t he Text dat a t ype's j ust t oo freewheeling. Fort unat ely, you can apply som e st rict er rules t hat deny cert ain charact ers or force t ext values t o m at ch a preset pat t ern. For exam ple, Access usually t reat s phone num bers like t ext , because t hey represent a series of charact ers like 123- 4444 ( not t he single num ber 1,234,444) . However, you don't want t o let people put let t ers in a phone num ber, because t hey obviously don't belong. To put t his rest rict ion int o act ion, you can use input m asks ( Sect ion 4.2) and validat ion ( Sect ion 4.3) , t wo feat ures discussed in Chapt er 4.

2.3.1.1. Text length Every t ext field has a m axim um lengt h. This t rait com es as a great surprise t o m any people who aren't used t o dat abases. Aft er all, wit h t oday's gargant uan hard drives, why worry about space? Can't your dat abase j ust expand t o fit what ever dat a you want t o st uff inside? The m axim um lengt h m at t ers because it det erm ines how densely Access can pack your records t oget her. For perform ance reasons, Access needs t o m ake sure t hat an ent ire record's st ored in one spot , so it always reserves t he m axim um am ount of space a record m ight need. I f your t able has four fields t hat are 50 charact ers apiece, Access can reserve 200 charact ers wort h of space on your hard drive for each record. On t he ot her hand, if your fields have a m axim um 100 charact ers each, Access holds on t o t wice as m uch space for each record, even if you aren't act ually using t hat space. The ext ra space isn't a m aj or issue ( you probably have plent y of room on your com put er) , but t he m ore spread out a dat abase, t he slower your searches. The st andard m axim um lengt h is 50, a good st art ing point . The box " Maxim um Lengt h Guidelines" ( Sect ion 2.3.2.1) has som e m ore recom m endat ions. To set t he m axim um lengt h, ent er a num ber in t he Field Size box, in t he Field Propert ies sect ion ( Figure 2- 9) . The largest m axim um you're allowed is 255 charact ers. I f you need t o st ore a large paragraph or an ent ire art icle's wort h of inform at ion, t hen you need t he Mem o dat a t ype inst ead ( Sect ion 2.3.1.1) .

Tip: It's worthwhile being a little generous with maximum lengths to avoid the need to modify the database later on.

2.3.2. Memo Microsoft designed t he Mem o dat a t ype t o st ore large quant it ies of t ext . I f you want t o place a chapt er from a book, an ent ire newspaper art icle, or j ust several paragraphs int o a field, you need t he Mem o dat a t ype. The nam e's a lit t le oddalt hough a m em o field could cert ainly st ore t he inform at ion from an int er- office m em orandum , it 's j ust as useful any t im e you have large blocks of t ext . When creat ing a m em o field, you don't need t o supply a m axim um lengt h, because Access st ores t he dat a in a m em o field different ly from ot her dat a t ypes. Essent ially, it st uffs m em o dat a int o a separat e sect ion, so it can keep t he rest of t he record as com pact and efficient as possible, but accom m odat e large am ount s of t ext .

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-3.html (4 of 20) [1/7/2007 7:06:26 AM]

Section 2.3. Access Data Types

Figu r e 2 - 9 . To set a maximum length, choose your field, and then click the Field Size box in the Field Properties list (shown here). (All the field properties you need in this chapter are on the General tab.) When you click a field property box, that field property's description appears on the right.

A m em o field t ops out at 65,536 charact ers. To put it in perspect ive, t hat 's about t he sam e size as t his chapt er. I f you need m ore space, t hen add m ore t han one m em o field.

Note: Technically, the 65,536 character limitation's a limitation in the Access user interface, not the database. If you program an application that uses your database, it could store far moreup to a gigabyte's worth of information in a memo field.

I f you need t o edit a large am ount of t ext while you're working on t he dat asheet , t hen you can use t he Zoom box ( Figure 210) . Just m ove t o t he field you want t o edit , and t hen press Shift + F2.

2.3.2.1. Formatted text Like a t ext field, t he m em o field st ores unform at t ed t ext . However, you can also st ore rich t ext in a m em o fieldt ext t hat has different font s, colors, t ext alignm ent , and so on. To do so, set t he Text Form at set t ing t o Rich Text ( rat her t han Plain Text ) . To form at part of your t ext , you sim ply need t o select it and t hen choose a form at t ing opt ion from t he ribbon's Hom e

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-3.html (5 of 20) [1/7/2007 7:06:26 AM]

Section 2.3. Access Data Types

Font Hom e Rich Text sect ions. However, m ost of t he t im e you won't t ake t his approach, because it 's difficult t o edit large am ount s of t ext in t he dat asheet 's narrow colum ns. I nst ead, use Shift + F2 t o open a Zoom box, and t hen use t he m inibar ( Figure 2- 11) .

Figu r e 2-10. If you have lengthy text in a field, it's hard to see it all at once without a lot of scrolling. By opening a Zoom box (Shift +F2), you can see more content and edit it more easily. You'll need to click OK (to accept your edits) or Cancel (to abandon them) to get back to the datasheet.

UP TO SPEED Maximum Length Guidelines

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-3.html (6 of 20) [1/7/2007 7:06:26 AM]

Section 2.3. Access Data Types

Here are som e recom m ended m axim um lengt hs: ● ● ● ●







Fir st n a m e s a n d la st n a m e s. 25 charact ers handles a first nam e, while 50 charact ers each plays it safe for a long, hyphenat ed last nam e. M iddle in it ia l. One charact er. ( Som et im es com m on sense is right .) Em a il a ddr e ss. Go wit h 50 charact ers. Em ail addresses closer t o 100 charact ers have t urned up in t he wild ( Google " world's longest em ail address" for m ore) , but t hey're unlikely t o reach your dat abase. Cit ie s, st a t e s, cou n t r ie s, a n d ot h e r pla ce s. Alt hough a Maori nam e for a hill in New Zealand t ops out at over 80 charact ers ( see ht t p: / / en.wikipedia.org/ wiki/ Longest _word_in_English) , 50 is enough for m ost pract ical purposes. St r e e t a ddr e ss. A st reet address consist s of a num ber, followed by a space, t hen t he st reet nam e, anot her space, and t he st reet abbreviat ion ( like Rd or St ) . Fift y charact ers handles it , as long as you put post al codes, cit ies, and ot her post al det ails in ot her fields. Ph on e n u m be r s, post a l code s, cr e dit ca r d n u m be r s, a n d ot h e r fix e d- le n gt h t e x t . Count t he num ber charact ers and ignore t he placeholders, and set t he m axim um t o m at ch. I f you want t o st ore t he phone num ber ( 123) 456- 7890, m ake t he field 10 charact ers long. You can t hen st ore t he phone num ber as 1234567890, but use an input m ask ( Sect ion 4.2) t o add t he parent heses, spaces, and dash when you display it . This approach is bet t er because it avoids t he headaches t hat result from ent ering sim ilar phone num bers in different ways. D e scr ipt ion or com m e n t s. 255 charact ers fit s t hree or four average sent ences of inform at ion. I f you need m ore, consider t he m em o dat a t ype inst ead ( Sect ion 2.3.1.1) .

Figu r e 2 1 1 . To show the minibar (sadly, of the non-alcoholic variety), select some text, and then hover over it with the mouse. The minibara compact toolbar with formatting optionsgradually fades into view. The minibar's sometimes a little finicky, and you may need to reselect the text more than once to get it to appear.

Tip: There's another, even easier way to get formatted text into a memo field. Create the text in a word processing program (like Word), format it there, and then copy and paste it into the field. All the formatting comes with it.

As neat as t his feat ure m ay seem at first glance, it 's rarely wort h t he t rouble. Dat abase purist s believe t hat t ables should st ore raw inform at ion and let ot her program s ( or fancy form s) decide how t o form at it . The problem is t hat once you've creat ed your form at t ed t ext , it can be quit e a chore t o m aint ain it . Just im agine having t o change t he font in 30,000 different records.

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-3.html (7 of 20) [1/7/2007 7:06:26 AM]

Section 2.3. Access Data Types

I f you really do want t o st ore form at t ed cont ent , t hen consider linking your dat abase t o a separat e docum ent , like a Word file. I n Access, you can do t his in t wo ways: ●



Cr e a t e a fie ld t h a t poin t s t o t h e file . For exam ple, c: \ m yfile\ BonoBobblehead- Descript ion.docx) . For t his t rick, use t he Text or Hyperlink dat a t ype ( Sect ion 2.3.7) . Em be d t h e file in side you r da t a ba se . This way, it 's im possible t o lose t he file ( or end up point ing t o t he wrong locat ion) . However, you'll need t o pull t he file out every t im e you want t o updat e it . To do t his, you need t o use t he At t achm ent dat a t ype ( Sect ion 2.3.8) .

2.3.3. Number The Num ber dat a t ype includes a wide variet y of different ly sized num bers. You can choose t o allow decim al num bers, and you can use negat ive values ( j ust precede t he value wit h a m inus sign) . You should use t he Num ber dat a t ype for every t ype of num eric inform at ion you haveexcept currency am ount s, in which case t he Currency dat a t ype ( Sect ion 2.3.4) is a bet t er m at ch. When you use num eric fields, you don't include inform at ion about t he unit s you're using. You m ay have a field t hat represent s a Weight in pounds, a Height in Met ers, or an Age in Years. However, t hese fields cont ain only a num ber. I t 's up t o you t o know what t hat num ber signifies. I f you t hink ot her people m ay be confused, consider explaining t he unit s in t he descript ion ( Sect ion 2.2.1) , or incorporat e it int o t he field nam e ( like Height I nMet ers) .

Note: Your field should never, ever contain values like "44 pounds." Access treats this value as a text value, so if you make this mistake, you can't use all the important number crunching and validation tools you'll learn about later in this book.

2.3.3.1. Number size As wit h a t ext field, when you creat e a num ber field, you need t o set t he Field Size propert y t o m ake sure Access reserves t he right am ount of space. However, wit h num bers your opt ions are a lit t le m ore com plicat ed t han t hey are for ordinary t ext . Essent ially, num bers are divided int o several subgroups, depending on whet her or not t hey support fract ional values ( num bers t o t he right of a decim al point ) and how m any byt es of space Access uses t o st ore t hem .

Note: A byte's a group of eight bits, which is the smallest unit of storage in the computer world. For example, a megabyte's approximately one million bytes.

Table 2- 2 list s t he different Field Size opt ions you can choose for t he Num ber dat a t ype, and explains when each one m akes m ost sense. I nit ially, Access chooses Long I nt eger for all fields, which gives a fair bit of space but doesn't allow fract ional values.

Ta ble 2 - 2 . Fie ld Size Opt ion s for t h e N u m be r D a t a Type Fie ld Size

Con t a in s

W h e n t o Use I t

Byt e

An int eger ( whole num ber) from 0 t o 255. Requires j ust one byt e of space.

This size is risky, because it fit s only very sm all num bers. Usually, it 's safer t o use I nt eger for sm all num bers and give yourself a lit t le m ore breat hing room .

I nt eger

An int eger ( whole num ber) from 32,768 t o 32,767. Requires t wo byt es of space.

Useful if you need sm all num bers wit h no decim al part .

Long I nt eger

An int eger ( whole num ber) from 2,147,483,648 t o 2,147,483,647. Requires four byt es of space.

The Access st andard. A good choice wit h plent y of room . Use t his t o st ore j ust about anyt hing wit hout hit t ing t he m axim um , as long as you don't need decim als.

Single

Posit ive or negat ive num bers wit h up t o 38 zeroes and 7 decim al places of accuracy. Requires four byt es of space.

The best choice if you need t o st ore fract ional num bers or num bers t hat are t oo large t o fit in a Long I nt eger.

Double

Posit ive or negat ive num bers wit h up t o 308 zeroes and 15 decim al places of accuracy. Requires eight byt es of space.

Useful if you need ridiculously big num bers.

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-3.html (8 of 20) [1/7/2007 7:06:27 AM]

Section 2.3. Access Data Types

Decim al

Posit ive or negat ive num bers wit h up t o 28 zeroes and 28 decim al places of accuracy. Requires eight byt es of space.

Useful for fract ional num bers t hat have lot s of digit s t o t he right of t he decim al point .

Note: Table 2-2 doesn't include Replication ID, because you use that option only with the Number data type (Section 2.3.9).

2.3.3.2. Number formatting The Field Size det erm ines how Access st ores your num ber in t he t able. However, you can st ill choose how it 's present ed in t he dat asheet . For exam ple, 50, 50.00, 5E1, $50.00, and 5000% are all t he sam e num ber behind t he scenes, but people int erpret t hem in dram at ically different ways. To choose a form at , you set t he Form at field propert y. Your basic built - in choices include: ● ●

● ● ● ●

Ge n e r a l N u m be r . Displays unadorned num bers, like 43.4534. Any ext ra zeroes at t he end of a num ber are chopped off ( so 4.10 becom es 4.1) . Cu r r e n cy a n d Eu r o. Bot h opt ions display num bers wit h t wo decim al places, t housands separat ors ( t he com m a in $1,000.00) , and a currency sym bol. These choices are used only wit h t he Currency dat a t ype ( Sect ion 2.3.4) . Fix e d. Displays num bers wit h t he sam e num ber of decim al places, filling in zeroes if necessary ( like 432.11 and 39.00) . A long colum n of num bers lines up on t he decim al point , which m akes your t ables easier t o read. St a n da r d. Sim ilar t o Fixed, except it also uses t housands separat ors t o help you quickly int erpret large num bers like 1,000,000.00. Pe r ce n t . Displays fract ional num bers as percent ages. For exam ple, if you ent er 0.5, t hat t ranslat es t o 50% . Scie n t ific. Displays num bers using scient ific not at ion, which is ideal when you need t o handle num bers t hat range widely in size ( like 0.0003 and 300) . Scient ific not at ion displays t he first non- zero digit of a num ber, followed by a fixed num ber of digit s, and t hen indicat es what power of t en t hat num ber needs t o be m ult iplied by t o generat e t he specified num ber. For exam ple, 0.0003 becom es 3.00 x 10 - 4 , which displays as 3.00E- 4. The num ber 300, on t he ot her hand, becom es 3.00 x 10 2 , or 3E2.

Tip: When using Fixed, Standard, Percent, or Scientific, you should also set the Decimal Places field property to the number of decimal places you want to see. Otherwise, you always get two.



A cu st om for m a t st r in g. This is a crypt ic code t hat t ells Access exact ly how t o form at a num ber. You need t o t ype t he form at st ring you need int o t he Form at box. For exam ple, if you t ype in t he weird- looking code # ,# # 0, ( including t he com m a at t he end) Access hides t he last t hree digit s of every num ber, so 1 m illion appears as 1,000 and 15,000 as 15.

Note: Custom number formats aren't terribly common in Access (they're more frequently used with Excel). Later on, you'll learn about expressions (Section 7.1.1), which let you do pretty much the same thing.

2.3.4. Currency Currency's a slight variat ion on t he Num ber dat a t ype t hat 's t ailored for financial calculat ions. Unlike t he Num ber dat a t ype, here you can't choose a Field Size for t he Currency dat a t ypeAccess has a one- size- fit s- all policy t hat requires eight byt es of st orage space.

Note: The Currency data type's better than the Number data type because it uses optimizations that prevent rounding errors with very small fractions. The Currency data type's accurate to 15 digits to the left of the decimal point, and four digits to the right.

You can adj ust t he num ber of decim al places Access shows for currency values on t he dat asheet by set t ing t he Decim al Places field propert y. Usually, it 's set t o 2. The form at t ing t hat Access uses t o display currency values is det erm ined by t he Regional and Language Opt ions set t ings on your com put er ( Sect ion 2.3.5) . However, t hese set t ings m ight produce result s you don't want for exam ple, say you run an art isanal cereal business in Denm ark t hat sells all it s product s overseas in U.S. dollars ( not kroner) . You can cont rol exact ly how currency values are form at t ed by set t ing t he Form at field propert y, which gives you t he following opt ions: ●

Cu r r e n cy. This opt ion is t he st andard choice. I t uses t he form at t ing based on your com put er's regional set t ings.

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-3.html (9 of 20) [1/7/2007 7:06:27 AM]

Section 2.3. Access Data Types

● ●

Eu r o. This opt ion always uses t he Euro currency sym bol ( ) A cu st om for m a t st r in g. This opt ion let s you get any currency sym bol you want ( as described below) . You need t o t ype t he form at st ring you need int o t he Form at box.

There's a sim ple recipe for cooking up form at st rings wit h a cust om currency sym bol. St art by adding t he charact er for t he currency sym bol ( t ype in what ever you want ) and t hen add # ,# # # .# # which is Access code for " give m e a num ber wit h t housands separat ors and t wo decim al places." For exam ple, t he Danish cereal com pany could use a form at st ring like t his t o show t he U.S. currency sym bol: $#,###.##

Whereas a U.S. com pany t hat needs t o display a Danish currency field ( which form at s prices like kr 342.99) would use t his: kr #,###.##

Note: Enterprising users can fiddle around with the number format to add extra text, change the number of decimal places (just add or remove the number signs), and remove the thousands separators (just take out the comma).

2.3.5. Date/Time Access uses t he Dat e/ Tim e dat a t ype t o st ore a single inst ant in t im e, com plet e wit h t he year, m ont h, day, and t im e down t o t he second. Behind t he scenes, Access st ores dat es as num bers, which let s you use t hem in calculat ions. Alt hough Access always uses t he sam e am ount of space t o st ore dat e inform at ion in a field, you can hide som e com ponent s of it . You can choose t o display j ust a dat e ( and ignore any t im e inform at ion) or j ust t he t im e ( and ignore any dat e inform at ion) . To do t his, you sim ply need t o set t he Form at field propert y. Table 2- 3 shows your opt ions.

Ta ble 2 - 3 . D a t e / Tim e For m a t s For m a t

Ex a m ple

General Dat e

2/ 23/ 2008 11: 30: 15 PM

Long Dat e

February 23, 2008 11: 30: 15 PM

Medium Dat e

23- Feb- 08

Short Dat e

2/ 23/ 2008

Long Tim e

11: 30: 15 PM

Medium Tim e

11: 30 PM

Short Tim e

23: 30

Note: Both the General Date and Long Date show the time information only if it's not zero.

The form at affect s only how t he dat e inform at ion's displayedit doesn't change how you t ype it in. Access is int elligent enough t o int erpret dat es correct ly when you t ype any of t he following: ● ● ● ● ●

2008- 23- 2 ( t he int ernat ional year- m ont h- day st andard always works) 2/ 23/ 2008 ( t he m ost com m on approach, but you m ight need t o flip t he m ont h and day on non- U.S. com put ers) 23- Feb- 08 Feb 23 ( Access assum es t he current year) 23 Feb ( dit t o)

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-3.html (10 of 20) [1/7/2007 7:06:27 AM]

Section 2.3. Access Data Types

To add dat e and t im e inform at ion, j ust follow t he dat e wit h t he t im e, as in 23- Feb- 08 5: 06 PM. Make sure t o include t he AM/ PM designat ion at t he end, or use a 24hour clock. I f it 's t oo m uch t rouble t o t ype in a dat e, t hen consider using t he calendar sm art t ag inst ead. The sm art t ag is an icon t hat appears next t o t he field whenever you m ove t o it , as shown in Figure 2- 12.

Figu r e 2-12. Access automatically pops up the calendar smart tag for all date fields. Click the calendar icon to pop up a mini calendar where you can browse to the date you want. However, you can't use the calendar to enter time information.

UP TO SPEED Dating Your Computer Windows has regional set t ings for your com put er, which affect t he way Microsoft program s display t hings like dat es and currencies. I n Access, t he regional set t ings det erm ine how t he different dat e form at s appear. I n ot her words, on a fact ory- direct U.S. com put er, t he Short Dat e form at shows up as 2/ 23/ 2008. But on a Brit ish com put er, it m ay appear as 23/ 2/ 2008. Eit her way, t he inform at ion t hat 's st ored in t he dat abase is t he sam e. However, t he way it appears in your dat asheet changes. You can change t he regional set t ings, and t hey don't have t o correspond t o where you liveyou can set t hem for your com pany headquart ers on anot her cont inent , for inst ance. But keep in m ind t hat t hese set t ings are global, so if you alt er t hem , you affect all your program s. To m ake a swit ch, head t o Cont rol Panel. ( I n Windows XP, click t he St art m enu and choose Set t ings Cont rol Panel. I n Windows Vist a, click St art and look for t he Cont rol Panel opt ion on t he right side.) Once you've opened t he Cont rol Panel, doubleclick Regional and Language Opt ions, which brings up a dialog box. The first t ab has all t he set t ings you want . The m ost im port ant set t ing's in t he first box, which has a drop- down list you can use t o pick t he region you want t o use, like English ( Unit ed St at es) or Swedish ( Finland) . You can fine- t une t he set t ings in your region, t oo. This m akes sense only if you have part icular preferences about how dat es should be form at t ed t hat don't m at ch t he st andard opt ions. Click t he Cust om ize but t on next t o t he region box t o bring up a new dialog box, and t hen click t he Dat e t ab ( shown in Figure 2- 13) .

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-3.html (11 of 20) [1/7/2007 7:06:27 AM]

Section 2.3. Access Data Types

Figu r e 2 - 1 3 . The Regional and Language Options dialog box lets you customize how dates appear on your computer. Use the drop-down lists to specify the date separator; order of month, day, and year components in a date; and how Access should interpret two-digit years. You can mix and match these settings freely, although you could wind up with a computer that's completely counterintuitive to other people.

2.3.5.1. Custom date formats I f you're not happy wit h t he seven st andard dat e opt ions t hat Access provides, you can craft your own dat e form at st ring and t ype in t he Form at propert y. This form at st ring t ells Access how t o present t he dat e and t im e inform at ion. A dat e form at st ring is built out of pieces. Each piece represent s a single part of t he dat e, like t he day, m ont h, year, m inut e, hour, and so on. You can com bine t hese pieces in what ever order you want . For exam ple, consider t he following form at st ring: yyyy-mm-dd

This st ring t ranslat es as t he following inst ruct ions: Display t he four- digit year, followed by a dash, followed by a t wo- digit m ont h num ber, followed by anot her dash, followed by a t wo- digit day num ber. You're free t o put t hese com ponent s in any order you like, but t his exam ple defines t hem according t o t he I SO dat e st andard. You can also cont rol how t o display t he year, day, and m ont h com ponent s. You can use m ont h abbreviat ions or full nam es inst ead of a m ont h num ber ( j ust replace t he m m code wit h som et hing different ) . I f you apply t his form at st ring t o a field t hat cont ains t he dat e January 1, 2008, t hen you see t his in t he dat asheet : 2008-01-01

Rem em ber t hat regardless of what inform at ion you choose t o display or hide, Access st ores t he sam e dat e inform at ion in your dat abase. Table 2- 4 shows t he basic placeholders t hat you can use for a dat e or t im e form at st ring.

Ta ble 2 - 4 . D a t e a n d Tim e For m a t t in g Code s

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-3.html (12 of 20) [1/7/2007 7:06:27 AM]

Section 2.3. Access Data Types

Code

D e scr ipt ion

D ispla ys ( for t h e D a t e Ja n u a r y 1 , 2 0 0 8 ) …

d

The day of t he m ont h, from 1 t o 31, wit h t he num bers bet ween 1 and 9 appearing wit hout a leading 0.

7

dd

The day of t he m ont h, from 01 t o 31 ( leading 0 included for 1 t o 9) .

07

ddd

A t hree- let t er abbreviat ion for t he day of t he week.

Fri

dddd

The full nam e of t he day of t he week.

Friday

m

The num ber value, from 1 t o 12, of t he m ont h ( no leading 0 used) .

1

mm

The num ber value, from 01 t o 12, of t he m ont h ( leading 0 used for 01 t o 09) .

01

mmm

A t hree- let t er abbreviat ion for t he m ont h.

Jan

mmmm

The full nam e of t he m ont h.

January

yy

A t wo- digit abbreviat ion of t he year.

08

yyyy

The year wit h all four digit s.

2008

h

The hour, from 0 t o 23 ( no leading 0 used) .

13

hh

The hour, from 00 t o 23 ( leading 0 used for 00 t o 09) .

13

:m

The m inut e, from 0 t o 59 ( no leading 0 used) .

5

:mm

The m inut e, from 0 t o 59 ( leading 0 used for 00 t o 09) .

05

:s

The second, from 0 t o 59 ( no leading 0 used) .

5

: ss

The second, from 0 t o 59 ( leading 0 used for 00 t o 09) .

05

AM/ PM

Tells Access t o use a 12- hour clock, wit h an AM or PM indicat ion.

PM

am / pm

I ndicat es a 12- hour clock, wit h an am or pm indicat ion.

pm

A/ P

Tells Access t o use a 12- hour clock, wit h an A or P indicat ion.

p

a/ p

Tells Access t o use a 12- hour clock, wit h an a or p indicat ion.

p

2.3.6. Yes/No A Yes/ No field is a sm all m iracle of efficiency. I t 's t he leanest of Access dat a t ypes, because it allows only t wo possible values: Yes or No. When using a Yes/ No field, im agine t hat your field poses a yes or no quest ion by adding an im aginary quest ion m ark at t he end of your field nam e. You could use a field nam ed I nSt ock t o keep t rack of whet her or not a product 's in st ock. I n t his case, t he yes or no quest ion is " in st ock?" Ot her exam ples include Shipped ( in a list of orders) , Male ( t o separat e t he boys from t he girls) , and Republican ( assum ing you're willing t o dist inguish bet ween only t wo polit ical orient at ions) . Alt hough every Yes/ No field is essent ially t he sam e, you can choose t o form at it slight ly different ly, replacing t he words " Yes" and " No" wit h On/ Off or True/ False. You'll find t hese t hree opt ions in t he Form at m enu. However, it doesn't m ake m uch difference because on t he dat asheet , Yes/ No fields are displayed wit h a checkbox, as shown in Figure 2- 14.

Figu r e 2-14. In this example, ForSale is a Yes/No

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-3.html (13 of 20) [1/7/2007 7:06:27 AM]

Section 2.3. Access Data Types

field. A checked checkbox represents Yes (or True or On). An unchecked checkbox represents No (or False or Off).

2.3.7. Hyperlink The Hyperlink dat a t ype com es in handy if you want t o creat e a clickable link t o a Web page, file, or em ail address. You can m ix and m at ch any com binat ion of t he t hree in t he sam e t able. Access handles hyperlinks a lit t le different ly in t he Dat asheet view. When you t ype t ext int o a hyperlink field, it 's colored blue and underlined. And when you click t he link, Access pops it open in your browser ( Figure 2- 15) .

Note: Access doesn't prevent you from entering values that aren't hyperlinks in a hyperlink data field. This trait leads to problems if you click the hyperlink. If you put the text "saggy balloons" in a hyperlink field and click it, then Access tries to send your browser to http://saggy balloons, which obviously doesn't work.

Figu r e 2-15. Click this hyperlink, and you'll head straight to the welcoming arms of Office Online.

One hyperlink field feat ure isn't im m ediat ely obvious. Hyperlink fields act ually st ore m ore t han one piece of inform at ion. Every hyperlink includes t hese t hree com ponent s:

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-3.html (14 of 20) [1/7/2007 7:06:27 AM]

Section 2.3. Access Data Types

● ● ●

The t ext you see in t he cell The dest inat ion you go t o when you click t he cell ( t he URL or file pat h) The t ext you see when you hover over t he link wit h your m ouse ( t he t oolt ip)

When you t ype a link int o t he dat asheet , all t hree of t hese are set t o t he sam e valuewhat ever you've j ust t yped in. I n ot her words, when you t ype ht t p: / / www.Fant asyPharm acologist s.com , t he t ext you see, t he URL link, and t he t oolt ip are all set t o hold t he sam e cont ent , which is t he URL ht t p: / / www.Fant asyPharm acologist s.com . Most of t he t im e, t his approach is good, because it let s you quickly size up a link. However, you aren't lim it ed t o t his st rat egy. I f you want t o set t hese t hree com ponent s t o have different values, m ove t o t he value, and t hen hit Ct rl+ K t o pop up t he Edit Hyperlink. Edit Hyperlink window ( see Figure 2- 16) . Or right - click it , and t hen choose Hyperlink

2.3.8. Attachment The At t achm ent dat a t ype's new in Access 2007. I t let s you add files t o your dat abase record in m uch t he sam e way t hat you t ack on at t achm ent s t o your em ail m essages. Access st ores t he files you add t o an at t achm ent field as part of your t able, em bedded inside your dat abase file. The At t achm ent dat a t ype's a good choice if you need t o insert a pict ure for a record, a short sound file, or even a docum ent from anot her Office applicat ion, like Word or Excel. You could creat e a People t able wit h a pict ure of each person in your cont act list , or a product cat alog wit h pict ures of t he wares you're selling. I n t hese cases, at t achm ent s have an obvious benefit because t hey're st ored inside your dat abase file, you'll never lose t rack of t hem .

Figu r e 2-16. Using the Edit Hyperlink window, you can change the text that appears in the cell (at the top of the window) and the page that Access opens when you click it (at the bottom). You can also create links that use email addresses (in which case Access opens the email file:///C|/html/0596527608/access2007tm-CHP-2-SECT-3.html (15 of 20) [1/7/2007 7:06:27 AM]

Section 2.3. Access Data Types

program that's configured on your computer) or links to file paths (use the folder browsing area to pick the file you want).

However, at t achm ent s aren't as graceful wit h large files, or files you need t o m odify frequent ly. I f you place a frequent ly m odified docum ent int o an Access dat abase, it isn't available on your hard drive for quick edit ing, print ing, and searching. I nst ead, you'll need t o fire up Access, and t hen find t he corresponding record before you can open your docum ent . I f you want t o m ake changes, t hen you'll also need t o keep Access open so it can t ake t he revised file and insert it back int o t he dat abase.

Warning: Think twice before you go wild with attachments. As you've already learned, an Access database is limited to two gigabytes of space. If you start storing large files in your tables, you just may run out of room. Instead, store large documents in separate files, and then record the file name in a text or hyperlink field.

When you use t he At t achm ent dat a t ype, m ake sure you set t he Capt ion field propert y, which det erm ines t he t ext t hat appears in t he colum n header for t hat field. ( Oft en, you'll use t he field nam e as t he capt ion.) I f you don't set a capt ion, t he colum n header shows a paper clip but no t ext . You'll recognize an at t achm ent field in t he dat asheet because it has a paper clip icon next t o it ( Figure 2- 17) . To at t ach a file or review t he list of at t ached files, double- click t he paper clip icon. You'll see t he At t achm ent s dialog box ( see Figure 2- 18) . Here's what you can do in t he At t achm ent s window: ● ●

Add a n e w a t t a ch m e n t . Click t he Add but t on. Then browse t o a new file, and t hen click OK. You'll see it appear at t he bot t om of t he list . D e le t e a n a t t a ch m e n t . Select t he at t achm ent in t he list , and t hen click Rem ove.

Figu r e 2-17. Attachments are flagged with a paper clip icon and a number in brackets, which tells you how many files are attached. In file:///C|/html/0596527608/access2007tm-CHP-2-SECT-3.html (16 of 20) [1/7/2007 7:06:27 AM]

Section 2.3. Access Data Types

this example, all the values in the Picture attachment field are empty except Count Chocula, which has two.

Figu r e 2 - 1 8 . The Attachments dialog box shows you all the files that are linked to your field.





Sa ve a copy of a n a t t a ch m e n t . Select t he at t achm ent , click Save, and t hen browse t o a locat ion on your com put er. Or, click Save All t o save copies of all t he at t achm ent s in t his field. I f you change t hese copies, you don't change t he at t achm ent in t he dat abase. Edit or vie w a n a t t a ch m e n t . Select t he at t achm ent , and t hen click Open. Access copies t he at t achm ent t o a t em porary folder on your com put er, where I nt ernet cont ent is cached. I f you save t he file, t hen Access not ices t he change, updat es t he at t achm ent aut om at ically, and t hen rem oves t he file. I f you close t he At t achm ent s window before you've closed t he file, t hen Access warns you t hat your updat es m ight not be reflect ed in t he dat abase. Figure 2- 19 shows what happens.

Unfort unat ely, t he At t achm ent dat a t ype doesn't give you a lot of cont rol. Here are som e of it s lim it at ions: ● ● ●

You can't rest rict t he num ber of at t achm ent s allowed in an at t achm ent field. All at t achm ent fields allow a pract ically unlim it ed num ber of at t achm ent s ( alt hough you can't at t ach t wo files wit h t he sam e nam e) . You also can't rest rict t he t ypes of files used for an at t achm ent . You can't rest rict t he size of t he files used for an at t achm ent .

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-3.html (17 of 20) [1/7/2007 7:06:27 AM]

Section 2.3. Access Data Types

Figu r e 2-19. Top: In this example, the file "The Story of the Count. doc" is still open. If you continue, then any changes you make (or any changes you've made so far and haven't saved) aren't reflected in the database. Bottom: If Access notices you've saved your file since you first opened it, then Access also asks if you want to update the database with the last saved version. (To avoid such headaches, attach only files that you don't plan to edit.)

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-3.html (18 of 20) [1/7/2007 7:06:27 AM]

Section 2.3. Access Data Types

2.3.9. AutoNumber An Aut oNum ber is a special sort of dat a t ype. Unlike all t he ot her dat a t ypes you've seen, you can't fill in t he value for an Aut oNum ber field. I nst ead, Access does it aut om at ically whenever you insert a new record. Access m akes sure t hat t he Aut oNum ber value is uniquein ot her words, it never gives t wo records t he sam e Aut oNum ber value.

Note: Every table can have up to one AutoNumber field.

Ordinarily, t he Aut oNum ber field looks like a sequence of num bersAccess t ends t o give t he first record an Aut oNum ber value of 1, t he second an Aut oNum ber of 2, and so on. However, t he t rut h isn't so st raight forward. Som et im es, Access skips a num ber. This skipping could happen when several people are using a dat abase at once, or if you st art adding a new record, and t hen cancel your act ion by pressing t he Esc key. You m ay also delet e an exist ing record, in which case Access never reuses t hat Aut oNum ber value. As a result , if you insert a new record and you see it 's assigned an Aut oNum ber value of 401, t hen you can't safely assum e t hat t here are already 400 records in t he t able. The act ual num ber's probably less. Trut hfully, an Aut oNum ber value doesn't represent anyt hing, and you probably won't spend m uch t im e looking at it . The Aut oNum ber field's sole purpose is t o m ake sure you have a unique way t o point t o each record in your t able. Usually, your Aut oNum ber field's also t he prim ary key for your t able, as explained in Sect ion 2.4.

2.3.9.1. Using AutoNumbers without revealing the size of your table Aut oNum ber values have one m inor problem : t hey give a clue about t he num ber of records in a t able. You m ay not want a cust om er t o know t hat your brand- new food and craft s com pany, Bet t er But t er Sculpt ures, hasn't cracked 12 cust om ers. So you'll be a lit t le em barrassed t o t ell him he's cust om er I D num ber 6. The best way t o solve t his problem is t o st art count ing at a higher num ber. You can fool Access int o generat ing Aut oNum ber values st art ing at a specific m inim um . For exam ple, inst ead of creat ing cust om er I Ds 1, 2, and 3, you could creat e t he I D values 11001, 11002, 11003. This approach also has t he advant age of keeping your I Ds a consist ent num ber of digit s, and it allows you t o dist inguish bet ween I Ds in different t ables by st art ing t hem at different m inim um s. Unfort unat ely, in order t o pull t his t rick off, you need t o fake Access out wit h a specially designed query, which you'll see in Sect ion 8.3.2. Alt ernat ively you can t ell Access t o generat e Aut oNum ber values in a different way. You have t wo choices: ●



Ra n dom Au t oN u m be r va lu e . To use random num bers, change t he New Values field propert y from I ncrem ent t o Random . Now you'll get long num bers for each record, like 212125691, 1671255778, and1388883525. You m ight use random Aut oNum ber t o creat e values t hat ot her people can't guess. ( For exam ple, if you have an Orders t able t hat uses random values for t he OrderI D field, you can use t hose values as confirm at ion num bers.) However, random Aut o- Num bers are rarely used in t he Access world. Re plica t ion I D s. Replicat ion I Ds are long, obscure codes like 38A94E7B- 2F95- 4E7D- 8AF1- DB5B35F9700C t hat are st at ist ically guarant eed t o be unique. To use t hem , change t he Field Size propert y from Long I nt eger t o Replicat ion I D. Replicat ion I Ds are really used only in one scenarioif you have separat e copies of a dat abase and you need t o m erge t he dat a t oget her in t he fut ure. The next sect ion explains t hat scenario.

Bot h of t hese opt ions t rade t he easy- t o- underst and sim plicit y of t he ordinary Aut oNum ber wit h som et hing a lit t le m ore awkward, so evaluat e t hem carefully before using t hese approaches in your t ables.

2.3.9.2. Using replication IDs I m agine you're working at a com pany wit h several regional sales offices, each wit h it s own dat abase for t racking cust om ers. I f you use an ordinary Aut oNum ber field, t hen you'll end up wit h several cust om ers wit h t he sam e I D, but at different offices. I f you ever want t o com pare dat a, you'll quickly becom e confused. And you can't com bine all t he dat a int o one dat abase for furt her analysis lat er on. Access gives you anot her choicea replicat ion I D. A replicat ion I D's a st range creat ionit 's an ext rem ely large num ber ( 16 byt es in all) t hat 's represent ed as a st ring of num bers and let t ers t hat looks like t his: 38A94E7B-2F95-4E7D-8AF1-DB5B35F9700C

This I D's obviously m ore cum bersom e t han an ordinary int eger. Aft er all, it 's m uch easier t o t hank som eone for subm it t ing Order 4657 t han Order 38A94E7B- 2F95- 4E7D- 8AF1- DB5B35F9700C. I n ot her words, if you use t he Aut oNum ber value for t racking or bookkeeping, t hen t he replicat ion I D's a bad idea.

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-3.html (19 of 20) [1/7/2007 7:06:27 AM]

Section 2.3. Access Data Types

However, t he replicat ion I D solves t he problem described earlier, where m ult iple copies of t he sam e dat abase are being used in different places. That 's because replicat ion I Ds are guarant eed t o be st at ist ically unique. I n ot her words, t here are so m any possible replicat ion I Ds t hat it 's absurdly unlikely t hat you'll ever generat e t he sam e replicat ion I D t wice. So even if you have dozens of separat e copies of your dat abase, and t hey're all m anaging hundreds of cust om ers, you can rest assured t hat each cust om er has a unique cust om er I D. Even bet t er, you can periodically fuse t he separat e t ables t oget her int o one m ast er dat abase. ( This process is called replicat ion, and it 's t he origin of t he t erm replicat ion I D. You'll learn m ore about t ransferring dat a from one dat abase t o anot her in Chapt er 19.)

Note: A replication ID is also called a GUID (short for "globally unique identifier"). In theory, the chance of two GUIDs being identical are one in 2128, which is small enough that you could set one billion people to work, ask them to create one billion GUIDs a year, and still be duplicatefree for the next decade or two. In practice, the real limitation's how good the random number generator is in Access.

Figure 2- 20 shows a t able t hat uses replicat ion I Ds.

Figu r e 2 - 2 0 . This figure shows 10 records in the FictionalCharacters table, each with a statistically unique AutoNumber value.

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-3.html (20 of 20) [1/7/2007 7:06:27 AM]

Section 2.4. The Primary Key

2.4. The Primary Key Design view also allows you t o set a t able's prim ary key, which is a field ( or a com binat ion of fields) t hat 's unique for each record. Every t able m ust have a prim ary key. To underst and why t he prim ary key's im port ant , you need t o consider a lit t le bit m ore about how dat abases work. The box " How Access Prevent s Duplicat e Records" in Sect ion 2.4.1 has t he full st ory. Choosing a prim ary key is t rickier t han it seem s. I m agine you have a list of friends ( and t heir cont act inform at ion) in a t able nam ed People. You m ay logically assum e t hat you can creat e a prim ary key using a com binat ion of first and last nam e.

UP TO SPEED How Access Prevents Duplicate Records I n order t o funct ion correct ly, a dat abase program like Access needs t o be able t o t ell t he difference bet ween each and every record in your t able. I n ot her words, you can't insert t wo records wit h exact ly t he sam e inform at ion. Dat abases are not oriously fussy, and t hey don't t olerat e t his sort of sloppiness. The challenge of prevent ing duplicat es isn't as easy as it seem s. Access is designed t o be blist eringly fast , and it can't afford t o double- check your new record against every ot her record in t he t able t o see if t here's a duplicat e. So inst ead, it relies on a prim ary key. As long as every record in a t able has a unique, never- duplicat ed prim ary key, you can't have t wo ident ical records. ( At worst , t hey'll be t wo alm ost ident ical records t hat have t he sam e inform at ion in all t heir ot her fields, but have different prim ary keys. And t his is perfect ly accept able t o Access.) I n an Em ployees t able, t he Social Securit y num ber could serve as t he prim ary key. This m et hod works well, because when you insert a new record, Access can check for duplicat es by breezing t hrough t he list of Social Securit y num bers, which is m uch fast er t han scanning t hrough t he ent ire t able.

Unfort unat ely, t hat j ust won't doaft er all, m any are t he address books t hat have t wo Sean Sm it hs. Your best solut ion's t o invent a new piece of inform at ion. You can label every individual in your cont act list wit h a unique I D num ber. Best of all, you can get Access t o aut om at ically creat e t his num ber for you ( and m ake sure t hat no t wo people get t he sam e num ber) , so you don't even need t o t hink about it . That way, if you have t wo Sean Sm it hs, each one has a different I D. And even if Ferris Wheel Sim pson decides t o change his first nam e, t he I D rem ains t he sam e. This approach is exact ly t he one Access uses when you creat e a t able using t he Dat asheet view. Consider t he Dolls t able you built in Chapt er 1. You'll not ice t hat it includes a field nam ed I D, which Access fills aut om at ically. You can't set t he I D value in a new record, or change it in an exist ing record. I nst ead, Access t akes com plet e cont rol, m aking sure each bobblehead has a different I D num ber. This behavior's alm ost always what you want , so don't t ry t o change it or delet e t he I D field.

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-4.html (1 of 3) [1/7/2007 7:06:30 AM]

Section 2.4. The Primary Key

However, t here's one except ion. I f you creat e a t able in Design view by choosing Creat e Tables Table Design, t hen Access assum es you know what you're doing, and it doesn't creat e an I D field for you. You need t o add an I D field ( or som et hing like it ) .

2.4.1. Creating Your Own Primary Key Field I f your dat abase doesn't have an I D field ( perhaps because you creat ed it using t he Creat e Tables Table Design com m and) , it 's up t o you t o creat e one and set t he prim ary key. Here's how t o do it : 1. Cr e a t e a n e w fie ld by t ypin g a n a m e in t h e Fie ld N a m e colu m n . For aut om at ically generat ed values, t he nam e I D is t he best choice. Som e people prefer t o be a lit t le m ore descript ive ( for exam ple, BobbleheadI D, Cust om erI D, and so on) , but it 's unnecessary. 2. I n t h e D a t a Type colu m n , ch oose Au t oN u m be r . By choosing t he Aut oNum ber dat a t ype, you m ake sure t hat Access generat e a unique I D value for every new record you insert . I f you don't want t his process t o happen, you can choose som et hing else ( like t he Text or Num ber dat a t ype) . You'll be responsible for ent ering your own unique value for each record, which is m ore work t hat it seem s. 3. Righ t - click t h e fie ld, a n d t h e n ch oose Pr im a r y Ke y. This choice designat es t he field as t he prim ary key for t he t able. Access doesn't allow duplicat e values in t his field.

Note: If you want to make a primary key that includes more than one field, then you need to take a slightly different approach. First, click the margin next to the field name, and then drag the mouse to select more than one field. Then, hold down Shift, and then right-click your selection. Now you can choose Primary Key.

UP TO SPEED Why It's Important to Be Unique

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-4.html (2 of 3) [1/7/2007 7:06:30 AM]

Section 2.4. The Primary Key

You won't com plet ely underst and why it 's so im port ant for each record t o have a unique I D num ber unt il you work wit h t he m ore advanced exam ples in lat er chapt ers. However, one of t he reasons is t hat ot her program s t hat use your dat abase need t o ident ify a record unam biguously. To underst and why t here's a problem , im agine t hat you've built a program for edit ing t he Dolls t able. This program st art s by ret rieving a list of all your t able's bobbleheads. I t displays t his list t o t he person using t he program , and let s her m ake changes. Here's t he cat chif a change is m ade, t he program needs t o be able t o apply t he change t o t he corresponding record in t he dat abase. And in order t o apply t he change, it needs som e unique piece of inform at ion t hat it can use t o locat e t he record. I f you've followed t he best design pract ices described above, t he unique " locat or" is t he bobblehead's I D.

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-4.html (3 of 3) [1/7/2007 7:06:30 AM]

Section 2.5. Six Principles of Database Design

2.5. Six Principles of Database Design Wit h great power com es great responsibilit y. As a dat abase designer, it 's up t o you t o craft a set of properly st ruct ured t ables. I f you get it right , you'll save yourself a lot of work in t he fut ure. Well- designed dat abases are easy t o enhance, sim pler t o work wit h, and lead t o far fewer m ind- bending problem s when you need t o ext ract inform at ion. Sadly, t here's no recipe for a perfect dat abase. I nst ead, a num ber of recom m endat ions can guide you on t he way. I n t his sect ion, you'll learn about a few of t he m ost im port ant .

Tip: Building a good database is an art that takes practice. For best results, read these guidelines, and then try building your own test databases.

2.5.1. 1. Choose Good Field Names Access doesn't im pose m any rules on what field nam es you can use. I t let s you use 64 charact ers of your choice. However, field nam es are im port ant . You'll be referring t o t he sam e nam es again and again as you build form s, creat e report s, and even writ e code. So it 's im port ant t o choose a good nam e from t he out set . Here are som e t ips: ● ● ●



● ●

Ke e p it sh or t a n d sim ple . The field nam e should be as short as possible. Long nam es are t iring t o t ype, m ore prone t o error, and can be harder t o cram int o form s and report s. Ca pit a lize Lik e Th is. I t 's not a set - in- st one rule, but m ost Access fans capit alize t he first let t er of every word ( known as Cam elCase) , and t hen cram t hem all t oget her t o m ake a field nam e. Exam ples include Unit sI nSt ock and Dat eOfExpirat ion. Avoid spa ce s. Spaces are allowed in Access field nam es, but t hey can cause problem s. I n SQL ( t he dat abase language you'll use t o search for dat a) , spaces aren't kosher. That m eans you'll be forced t o use square bracket s when referring t o field nam e t hat includes spaces ( like [ Num ber Of Guest s] ) , which get s annoying fast . I f you really m ust have spaces, t hen consider using underscores inst ead. Be con sist e n t . You have t he choice bet ween t he field nam es Product _Price and Product Price. Eit her approach is perfect ly reasonable. However, it 's not a good idea t o m ingle t he t wo approaches in t he sam e dat abasedoing so's a recipe for cert ain confusion. Sim ilarly, if you have m ore t han one t able wit h t he sam e sort of inform at ion ( for exam ple, a First Nam e field in an Em ployees t able and a Cust om ers t able) , use t he sam e field nam e. D on 't r e pe a t t h e t a ble n a m e . I f you have a Count ry field in a Cust om ers t able, it 's fairly obvious t hat you're t alking about t he Count ry where t he cust om er lives. The field nam e Cust om erCount ry would be overkill. D on 't u se t h e fie ld n a m e N a m e . Besides being a t ongue- t wist er, Nam e is an Access keyword. I nst ead, use Product Nam e, Cat egoryNam e, ClassNam e, and so on. ( This is one case where it 's OK t o violat e t he previous rule and incorporat e t he t able nam e in t he field nam e.)

You should also give careful t hought t o nam ing your t ables. Once again, consist ency is king. For exam ple, dat abase nerds spend hours arguing about whet her or not t o pluralize t able nam es ( like Cust om ers inst ead of Cust om er) . Eit her way's fine, but t ry t o keep all your t ables in line.

2.5.2. 2. Break Down Your Information Be careful t hat you don't include t oo m uch inform at ion in a single field. You want t o have each field st ore a single piece of inform at ion. Rat her t han have a single Nam e field in a t able of cont act s, it m akes m ore sense t o have a First Nam e and a Last Nam e field. There are m any reasons for breaking down inform at ion int o separat e fields. First of all, it st ops som e t ypes of errors. Wit h a Nam e field, t he nam e could be ent ered in several different ways ( like " Last , First " or " First Last " ) . Split t ing t he nam e avoids t hese issues, which can creat e headaches when you t ry t o use t he dat a in som e sort of aut om at ed t ask ( like a m ail m erge) . But m ore im port ant ly, you can m ore easily work wit h dat a t hat 's broken down int o sm all pieces. Once t he Nam e field's split int o First Nam e and Last Nam e, you can perform sort s or searches on j ust one of t hese t wo pieces of inform at ion, which you couldn't ot herwise do. Sim ilarly, you should split address inform at ion int o colum ns like St reet , Cit y, St at e, and Count ryt hat way, you can far m ore easily find out who lives in Nant ucket . Figure 2- 21 ( t op) shows an exam ple of proper separat ion. Figure 2- 21 ( bot t om ) shows a dangerous m ist akean at t em pt t o st ore m ore t han one piece of inform at ion in a single field.

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-5.html (1 of 5) [1/7/2007 7:06:36 AM]

Section 2.5. Six Principles of Database Design

Figu r e 2 2 1 . This example shows the right way to subdivide information in the Contacts table (top), and the wrong way (bottom). Notice that it's technically still possible to break the information down furtherthe street address information could theoretically be split into StreetNumber, StreetName, and StreetType. However, that added bit of complexity doesn't add anything, so database gurus rarely go to the extra trouble.

2.5.3. 3. Include All the Details in One Place Oft en, you'll use t he sam e t able in m any different t asks. You m ay use t he Dolls t able t o check for duplicat es ( and avoid purchasing t he sam e bobblehead t wice) , t o ident ify t he oldest part s of your collect ion, and t o det erm ine t he t ot al am ount of m oney you've spent in a given year ( for t ax purposes) . Each of t hese t asks needs a slight ly different com binat ion of inform at ion. When you're calculat ing t he t ot al m oney spent , you aren't int erest ed in t he Charact er field t hat ident ifies t he doll. When checking for a duplicat e, you don't need t he Dat eAcquired or Purchase- Price inform at ion. Even t hough you don't always need all t hese fields, it 's fairly obvious t hat it m akes sense t o put t hem all in t he sam e t able. However, when you creat e m ore det ailed t ables, you m ay not be as cert ain. I t 's not difficult t o im agine a version of t he Dolls t able t hat has 30 or 40 fields of inform at ion. You m ay use som e of t hese fields only occasionally. However, you should st ill include t hem all in t he sam e t able. All you'll see in t his book, you can easily filt er out t he inform at ion you don't need from t he dat asheet , as well as in your form s and print ed report s.

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-5.html (2 of 5) [1/7/2007 7:06:36 AM]

Section 2.5. Six Principles of Database Design

2.5.4. 4. Avoid Duplicating Information As you st art t o fill a t able wit h fields, it 's som et im es t em pt ing t o include inform at ion t hat doesn't really belong. This inclusion causes no end of headaches, and it 's a surprisingly easy t rap t o fall int o. Figure 2- 22 shows t his problem in act ion wit h a t able t hat t ries t o do t oo m uch.

Figu r e 2 2 2 . This table lists the available pets at an exotic animal breeder's. It also lists some helpful information about the life expectancy, temperament, and meal requirements of each type of animal. Initially, this design seems fairly reasonable. However, a problem appears when you have several of the same type of animals (in this case, three elephants). Now the elephantspecific details are repeated three separate times.

Duplicat e dat a like t hat shown in Figure 2- 22 is inefficient . You can easily im agine a t able wit h hundreds of sim ilar records, needlessly wast ing space repeat ing t he sam e values over and over again. However, t his concern's m inor com pared t o t he effort of updat ing t hat inform at ion, and t he possibilit y of inconsist ency. What happens if you want t o updat e t he life expect ancy inform at ion for every elephant based on new st udies? Based on t he current design of t he t able, you need t o change each record t hat has t he sam e inform at ion. Even worse, it 's all t oo easy t o change som e records but leave

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-5.html (3 of 5) [1/7/2007 7:06:36 AM]

Section 2.5. Six Principles of Database Design

ot hers unt ouched. The overall result 's inconsist ent dat ainform at ion in m ore t han one spot t hat doesn't agreewhich m akes it im possible t o figure out t he correct inform at ion. This problem occurs because t he inform at ion in t he Pet s t able doesn't all belong. To underst and why, you need t o delve a lit t le deeper int o dat abase analysis. As a rule, every t able in a dat abase st ores a single t hing. I n t he Pet s t able, t hat t hing is pet s. Every field in a t able is a piece of inform at ion about t hat t hing. I n t he Pet s t able, fields like Nam e, Anim al, and Weight all m ake sense. They describe t he pet in quest ion. But t he LifeSpan, Tem peram ent , and Diet fields aren't quit e right . They don't describe t he individual pet . I nst ead, t hey're j ust st andards for t hat species. I n ot her words, t hese fields aren't based on t he pet ( as t hey should be) t hey're based on t he anim al t ype. The only way t o solve t his problem is t o creat e t wo t ables: Pet s and Anim alTypes ( Figure 2- 23) .

Figu r e 2-23. Now the animalspecific information is maintained in one place, with no duplicates. It takes a little more work to get all the pet information you needfor example, to find out the life expectancy for Beatrice, you need to check out the Elephant record in the AnimalTypes tablebut the overall design's more logical.

I t t akes experience t o spot fields t hat don't belong. And in som e cases, breaking a t able down int o m ore and m ore sub- t ables isn't wort h t he t rouble. You could t heoret ically separat e t he address inform at ion ( cont ained in fields like St reet , Cit y, Count ry, and Post alCode) from a Cust om ers t able, and t hen place it int o a separat e Addresses t able. However, it 's relat ively uncom m on for t wo cust om ers t o share t he sam e address, so t his ext ra work isn't likely t o pay off. You'll consider how t o define form al relat ionships bet ween t ables like Pet s and Anim alTypes in Chapt er 5.

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-5.html (4 of 5) [1/7/2007 7:06:36 AM]

Section 2.5. Six Principles of Database Design

Tip: Many database gurus find the best way to plan a database is to use index cards. To do this, start by writing down all the various types of information you need in your database. Then, set aside an index card for each table you expect to use. Finally, take the fields on the scrap paper, and write them down on the appropriate index cards, one at a time, until everything's set into neat, related groups.

2.5.5. 5. Avoid Redundant Information Anot her t ype of dat a t hat j ust doesn't belong is redundant inform at ioninform at ion t hat 's already available elsewhere in t he dat abase, or even in t he sam e t able, som et im es in a slight ly different form . As wit h duplicat ed dat a, t his redundancy can cause inconsist encies. Calculat ed dat a's t he m ost com m on t ype of redundant inform at ion. An AverageOrderCost field in a Cust om ers t able is an exam ple. The problem here is t hat you can det erm ine t he price of an average order by searching t hrough all t he records in t he Orders t able for t hat cust om er, and averaging t hem . By adding an AverageOrderCost field, you int roduce t he possibilit y t hat t his field m ay be incorrect ( it m ay not m at ch t he act ual order records) . You also com plicat e life, because every t im e a cust om er places an order, you need t o recalculat e t he average, and t hen updat e t he cust om er record.

Note: Database gods do sometimes use calculated data as a performance-improving technique. However, this type of optimization's very rare in Access databases. It's more common in industrial-strength server-side databases that power large companies and Web sites.

Here are som e m ore exam ples of redundant inform at ion: ●



An Age a n d a D a t e OfBir t h fie ld ( in a Pe ople t a ble ) . Usually, you'll want t o include j ust a Dat eOfBirt h field. I f you have bot h, t hen t he Age field cont ains redundant inform at ion. But if you have only t he Age field, you're in t roubleunless you're ready t o keep t rack of birt hdays and updat e each record carefully, your inform at ion will soon be incorrect . A D iscou n t Pr ice fie ld ( in a Pr odu ct s t a ble ) . You should be able t o calculat e t he discount price as needed based on a percent age. I n a t ypical business, m arkups and m arkdowns change frequent ly. I f you calculat e 10 percent discount s and st ore t he revised prices in your dat abase, t hen you'll have a lot of work t o do when t he discount drops t o nine percent .

2.5.6. 6. Include an ID Field As you learned earlier, Access aut om at ically creat es an I D field when you creat e a t able in Dat asheet view and set s it t o be t he prim ary key for t he t able. But even now t hat you've graduat ed t o Design view, you should st ill add an I D field t o all your t ables. Make sure it uses t he Aut oNum ber dat a t ype so Access fills in t he num bers aut om at ically, and set it t o be t he prim ary key. I n som e cases, your t able m ay include a unique field t hat you can use as a prim ary key. Resist t he t em pt at ion. You'll always buy yourself m ore flexibilit y by adding an I D field. You never need t o change an I D field. Ot her inform at ion, even nam es and social insurance num bers, m ay change. And if you're using t able relat ionships, Access copies t he prim ary key int o ot her t ables. I f a prim ary key changes, you'll need t o t rack down t he value in several different places.

Note: It's a good idea to get into the habit of using ID fields in all your tables. In Chapter 5, you'll see the benefits when you start creating table relationships.

file:///C|/html/0596527608/access2007tm-CHP-2-SECT-5.html (5 of 5) [1/7/2007 7:06:36 AM]

Chapter 3. Mastering the Datasheet: Sorting, Searching, Filtering, and More

3. Mastering the Datasheet: Sorting, Searching, Filtering, and More I n Chapt er 1, you t ook your first look at t he dat asheet a st raight forward way t o browse and edit t he cont ent s of a t able. As you've learned since t hen, t he dat asheet isn't t he best place t o build a t able. ( Design view's a bet t er choice for dat abase cont rol freaks.) However, t he dat asheet is a great t ool for reviewing t he records in your t able, m aking edit s, and insert ing new dat a. Based on your experience creat ing t he Dolls t able ( Sect ion 1.2.3) , you probably feel pret t y confident breezing around t he dat asheet . However, m ost t ables are considerably larger t han t he exam ples you've seen so far. Aft er all, if you need t o keep t rack of only a dozen bobbleheads, t hen you really don't need a dat abaseyou'll be j ust as happy j ot t ing t he list down in any old spreadsheet , word processor docum ent , or scrap of unused Kleenex. On t he ot her hand, if you plan t o build a sm all bobblehead em pire ( suit able for t ouring in int ernat ional exhibit ions) , you need t o fill your t able wit h hundreds or t housands of records. I n t his sit uat ion, it 's not as easy t o scroll t hrough t he m ass of dat a t o find what you need. All of a sudden, t he dat asheet seem s m ore t han a lit t le overwhelm ing. Fort unat ely, Access is st ocked wit h dat asheet goodies t hat can sim plify your life. I n t his chapt er, you'll becom e a dat asheet expert , wit h t ricks like sort ing, searching, and filt ering at your fingert ips. You'll also learn a quick- and- dirt y way t o print a snapshot of t he dat a in your t able.

Note: It's entirely up to you how much time you spend using datasheets. Some Access experts prefer to create forms for all their tables (as described in Part Four). With forms, you can design a completely customized window for data entry. Designing forms takes more work, but it's a great way to satisfy your inner Picasso.

file:///C|/html/0596527608/access2007tm-CHP-3.html [1/7/2007 7:06:37 AM]

Section 3.1. Datasheet Customization

3.1. Datasheet Customization Get t ing t ired of t he drab dat asheet , wit h it s boring st ret ch of colum ns and plain t ext ? You can do som et hing about it . Access let s you t weak t he dat asheet 's appearance and organizat ion t o m ake it m ore pract ical ( or suit it t o your peculiar sense of st yle) . Som e of t hese cust om izat ionslike m odifying t he dat asheet font are sham eless frills. Ot her opt ions, like hiding or freezing colum ns, can genuinely m ake it easier t o work wit h large t ables.

Note: Access doesn't save formatting changes immediately (unlike record edits, which it stores as soon as you make them). Instead, Access prompts you to save changes the next time you close the datasheet. You can choose Yes to keep your customizations or No to revert to the table's last look and feel (which doesn't affect any edits you've made to the data in that table).

3.1.1. Formatting the Datasheet Access let s you form at t he dat asheet wit h eye- cat ching colors and font s. Do t hese opt ions m ake any difference t o t he way t he dat asheet works? Not really. But if your com put er deskt op looks m ore like a '60s revival part y t han an office t erm inal, t hen you'll enj oy t his feat ure. To find t he form at t ing feat ures, look at t he ribbon's Hom e

Font sect ion ( see Figure 3- 1) .

Figu r e 3-1. The Home Font section lets you change the text font and colors in the entire datasheet. The most practical frill is the ability to turn off some or all of the gridlines and use alternating row colors to highlight every other row, as shown here.

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-1.html (1 of 6) [1/7/2007 7:06:44 AM]

Section 3.1. Datasheet Customization

Every form at t ing change you m ake affect s t he ent ire t able. You m ay t hink it 's a nift y idea t o apply different form at t ing t o different colum ns, but Access doesn't let you. I f t his lim it at ion's frust rat ing you, be sure t o check out form s and report s lat er in t his book. Bot h are m ore com plicat ed t o set up, but give you m ore form at t ing power.

Note: There's one other way you can use the ribbon's Home

Font section. If you have a field that uses the Memo data type and you've

set your field to use rich text (Section 2.3.2.1), then you can select some text inside your field, and change its formatting using the ribbon.

GEM IN THE ROUGH Customizing All Your Datasheets Access let s you form at only one t able at a t im e. So if you find a form at t ing opt ion you really like, you'll need t o apply it separat ely t o every t able in your dat abase. However, you can set form at t ing opt ions so t hat t hey aut om at ically apply t o every t able in every dat abase by configuring Access it self. To pull t his t rick off, follow t hese st eps: 1. Choose Office but t on

Access Opt ions t o show t he Access Opt ions window.

2. Choose Dat asheet from t he list on t he left . 3. On t he right , you see t he st andard font , color, gridline, and colum n widt h opt ions, which you can change t o what ever you want . When you change t he dat asheet form at t ing set t ings in t he Access Opt ions window, you change t he default s t hat Access uses. These set t ings det erm ine t he form at t ing t hat Access uses for new t ables and any t ables t hat aren't cust om ized. When you cust om ize a t able, you override t he default set t ings, no m at t er what t hey are. I f you set Access t o use red t ext , but you form at a specific t able t o use green t ext , t he green t ext set t ing t akes precedence. However, if you set a yellow background in t he Access Opt ions window, and you don't cust om ize t hat det ail for your t able, t hen it aut om at ically acquires t he st andard yellow.

3.1.2. Rearranging Columns The fields in t he dat asheet are laid out from left t o right , in t he order you creat ed t hem . Oft en, you'll discover t hat t his order isn't t he m ost efficient for dat a ent ry. I m agine you've creat ed a Cust om ers t able for a novelt y past a com pany. When a new cust om er regist rat ion ends up on your desk, you realize t hat t he regist rat ion form st art s wit h t he nam e and address inform at ion, and t hen includes t he cust om er's past a preferences. Unfort unat ely, t he fields on t he dat asheet are laid out in a com plet ely different order. From right t o left , t hey're arranged like t his: I D, FreshPast aPreference, DriedPast aPreference, First Nam e, Last Nam e, St reet , Cit y, St at e, Count ry. ( This organizat ion isn't as crazy as it seem sit act ually m akes it easier for t he people filling past a orders t o quickly find t he inform at ion t hey want .) Because of t his ordering, you need t o skip back and fort h j ust t o ent er t he inform at ion from a single regist rat ion. Fort unat ely, you can solve t his problem wit hout redesigning t he t able. Drag t he colum ns you want t o m ove t o new posit ions, as shown in Figure 3- 2.

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-1.html (2 of 6) [1/7/2007 7:06:44 AM]

Section 3.1. Datasheet Customization

Figu r e 3 - 2 . To move a column, click the column header once to select that column. Then, drag the column header to its new location. In this example, the FirstName field is about to be relocated that it's just before the FreshPastaPreference field.

The best part of t his approach is t hat you don't need t o m odify t he dat abase's act ual st ruct ure. I f you swit ch t o Design view aft er m oving a few colum ns, you'll see t hat t he field order hasn't changed. I n ot her words, you can keep t he exact sam e physical order of fields ( in your dat abase file) but organize t hem different ly in Dat asheet view.

Tip: Rearranging columns is a relatively minor change. Don't worry about shifting columns around to suit a specific editing job and then switching them back later on. Your changes don't affect the data in the database. If you want to use a particular column order for a one-time job, simply refrain from saving your changes when you close the datasheet.

3.1.3. Resizing Rows and Columns As you cram m ore and m ore inform at ion int o a t able, your dat asheet becom es wider and wider. I n m any cases, you'll be frust rat ed wit h som e colum ns hogging m ore space t han t hey need and ot hers being im possibly narrow. As you'd expect , Access let s you t weak colum n widt hs. But you probably haven't realized how m any different ways you can do it : ● ●





Re size a sin gle colu m n . Move t he m ouse t o t he colum n's right edge. Drag t o t he left ( t o shrink t he colum n) or t o t he right ( t o m ake it larger) . Re size a colu m n t o fit it s con t e n t . Double- click t he colum n edge. Access m akes t he colum n j ust wide enough t o fit t he field nam e or t he largest value ( whichever's larger) . However, it doesn't m ake t he colum n so wide t hat it st ret ches beyond t he bounds of t he window. Re size se ve r a l a dj a ce n t colu m n s. Drag t he first colum n's header across t he colum ns unt il you've select ed t hem all. Then, drag t he right edge of your select ion t o t he left or t he right . All t he select ed colum ns shrink or expand t o fit t he available space, sharing it equally. Re size a colu m n w it h pin poin t a ccu r a cy. Right - click t he colum n header, and t hen choose Colum n Widt h. You'll see t he Colum n Widt h dialog t hat let s you set an exact widt h as a num ber ( Figure 3- 3) .

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-1.html (3 of 6) [1/7/2007 7:06:44 AM]

Section 3.1. Datasheet Customization

Figu r e 3 - 3 . The Column Width dialog box lets you set an exact width as a number. (The number doesn't actually have a concrete meaningit's supposed to be a width in characters, but because modern Access uses proportional fonts, different characters are different sizes.) You can also turn on the Standard Width checkbox to reset the width to the standard narrow size, or click Best Fit to expand the column to fit its content (just as when you double-click the edge of the column).

Note: Remember, a column doesn't need to be wide enough to show all its data at once. You can scroll through a lengthy text field using the arrow keys, and if that's too awkward, use the Shift+F2 shortcut to show the full contents of the current field in a Zoom box.

Just as you can resize colum ns, you can also resize rows. The difference is t hat Access m akes sure all rows have t he sam e size. So when you m ake one row t aller or short er, Access adj ust s all t he ot her rows t o m at ch. You'll m ainly want t o shrink a row t o cram m ore rows int o view at once. You'll want t o enlarge a row m ost ly t o show m ore t han one line of t ext in each t ext field ( see Figure 3- 4) .

Figu r e 3 - 4 . If a row's large enough, Access wraps the text inside it over multiple lines, as shown here with the Description column.

3.1.4. Hiding Columns Many t ables cont ain so m any colum ns t hat you can't possibly fit t hem all int o view at t he sam e t im e. This qualit y's one of t he drawbacks t o t he dat asheet , and oft en you have no choice but t o scroll from side t o side. However, in som e sit uat ions, you m ay not need t o see all t he fields at once. I n t his case, you can t em porarily hide t he colum ns t hat don't int erest you, t hereby hom ing in on t he im port ant det ails wit hout dist ract ion. I nit ially, every field you add t o a t able is out in t he open. To hide a colum n, select t he colum n by clicking t he colum n header. ( You can also select several adj acent colum ns by clicking t he colum n header of t he first , and t hen dragging t he m ouse across t he rest .) Then, right - click your select ion, and t hen choose Hide Colum ns. The colum n inst ant ly vanishes from t he dat asheet . ( This sudden disappearance can be a lit t le t raum at ic for Access newbies.) Fort unat ely, t he field and all it s dat a rem ain j ust out of sight . To pop t he colum n back int o view, right - click any colum n header and choose Unhide Colum ns. Access t hen shows t he Unhide Colum ns dialog box ( Figure 3- 5) .

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-1.html (4 of 6) [1/7/2007 7:06:44 AM]

Section 3.1. Datasheet Customization

Figu r e 3 - 5 . Using the Unhide Columns dialog box, you can choose to make hidden columns reappear, and (paradoxically) you can hide ones that are currently visible. Every column that has a checkmark next to it is visibleevery column that doesn't is hidden. As you change the visibility, Access updates the datasheet immediately. When you're happy with the results, click Close to get back to the datasheet.

Note: At the bottom of the field list, you'll see an entry named Add New Field. This "field" isn't really a fieldit's the placeholder that appears just to the right of your last field in datasheet view, which you can use to add new fields (Section 2.2.1). If you're in the habit of adding fields using Design view (Section 1.2.3), then you can hide this placeholder to free up some extra space.

I f you add a new record while colum ns are hidden, you can't supply a value for t hat field. The value st art s out eit her em pt y or wit h t he default value ( if you've defined one for t hat field, as described in Sect ion 4.1.2) . I f you've hidden a required field ( Sect ion 4.1.1) , you receive an error m essage when you t ry t o insert t he record. All you can do is unhide t he appropriat e colum n, and t hen fill in t he m issing inform at ion.

3.1.5. Freezing Columns Even wit h t he abilit y t o hide and resize colum ns, you'll probably need t o scroll from side t o side in a t ypical dat asheet . I n t his sit uat ion, you can easily lose your place. You m ight scroll t o see m ore inform at ion in t he Cont act s t able, but t hen forget exact ly which person you're looking at . Access has one m ore feat ure t hat can help you by m aking sure im port ant inform at ion is always visiblefrozen colum ns. A frozen colum n rem ains fixed in place at t he Access window's left side at all t im es. Even as you scroll t o t he right , all your frozen colum ns rem ain visible ( Figure 3- 6) . To freeze a colum n ( or colum ns) , select t hem , right - click t he colum n header, and t hen choose Freeze Colum ns.

Tip: If you want to freeze several columns that aren't next to each other, start by freezing the column that you want to appear at the very left. Then, repeat the process to freeze the column that you want to appear just to the right of the first column, and so on.

Figu r e 3-6. Top: In this example, the FirstName and LastName field are

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-1.html (5 of 6) [1/7/2007 7:06:44 AM]

Section 3.1. Datasheet Customization

frozen. They appear initially at the left. (The ribbon's collapsed in this figure to make more room, as described in Section 1.4.2.) Bottom: When you scroll to the side to see more information, the FirstName and LastName columns stay put.

Frozen colum ns m ust always be posit ioned at t he left size of t he dat asheet . I f you freeze a colum n t hat 's som ewhere else, Access m oves it t o t he left side and t hen freezes it . You can m ove it back aft er you unfreeze t he colum n using t he colum n reordering t rick in Sect ion 3.1.2. Keep in m ind t hat while a colum n's frozen, you can't drag it t o a different place. To unfreeze colum ns, right - click a colum n header, and t hen choose Unfreeze All Colum ns.

Note: Eventually, you'll discover that the customizations provided by the datasheet aren't enough, or you'll need to customize the same table different ways for different people. These signs tell you that you need to step up to forms, a more advanced data display option described in Part Four.

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-1.html (6 of 6) [1/7/2007 7:06:44 AM]

Section 3.2. Datasheet Navigation

3.2. Datasheet Navigation I n Chapt er 1, you learned t he basics of m oving around t he dat asheet . Using your m ouse and a few select keyst rokes, you can cover a lot of ground. ( Refer back t o Sect ion 1.2.4.2 for a review of t he different keys you can use t o j um p from place t o place and perform edit s.) However, you haven't seen a few t ricks yet . One's t he t im esaving record navigat ion but t ons at t he bot t om of t he dat asheet ( Figure 3- 7) .

Figu r e 3 - 7 . You could easily overlook the navigation buttons at the bottom of the datasheet. These buttons let you jump to the beginning and end of the table, or, more interestingly, head straight to a record at a specific position. To do this, type the record number (like "4") into the box (where it says "3 of 6" in this example), and then hit Enter. Of course, this trick works file:///C|/html/0596527608/access2007tm-CHP-3-SECT-2.html (1 of 13) [1/7/2007 7:06:55 AM]

Section 3.2. Datasheet Navigation

only if you have an approximate idea of where in the list your record's positioned.

Several m ore dat asheet feat ures help you orient yourself when dealing wit h large am ount s of dat a, including sort ing ( which orders t he records so you can see what you want ) , filt ering ( which cut s down t he dat a display t o include only t he records you're int erest ed in) , and searching ( which digs specific records out of an avalanche of dat a) . You'll t ry all t hese feat ures out in t he following sect ions.

3.2.1. Sorting I n som e cases, you can m ost easily m ake sense of a lot of dat a by put t ing it in order. You can organize a cust om er list by last nam e, a product cat alog by price, a list of wedding guest s by age, and so on. To sort your records, pick a colum n you want t o use t o order t he records. Click t he drop- down arrow at t he right edge of t he colum n header, and t hen choose one of t he sort opt ions at t he t op of t he m enu ( see Figure 3- 8) .

Figu r e 3 8 . This text field gives you the choice of sorting alphabetically from the beginning of the alphabet (A to Z) or backward from the end (Z to A). The menu also provides filtering options, which are described in Section 3.2.2.

Depending on t he dat a t ype of field, you'll see different sort ing opt ions, as explained in Table 3- 1. ( You can also apply t he sam e

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-2.html (2 of 13) [1/7/2007 7:06:55 AM]

Section 3.2. Datasheet Navigation

t ypes of sort using t he com m ands in t he ribbon's Hom e

Sort & Filt er sect ion.)

Ta ble 3 - 1 . Sor t in g Opt ion s for D iffe r e n t D a t a Type s D a t a Type

Sor t Opt ion s

Sort A t o Z Text , Mem o, and Hyperlink Sort Z t o A Sort Sm allest t o Largest Num ber, Currency, and Aut oNum ber Sort Largest t o Sm allest Sort Oldest t o Newest Dat e/ Tim e Sort Newest t o Oldest

D e scr ipt ion

Perform s an alphabet ic sort ( like t he dict ionary) , ordering let t er by let t er. The sort isn't case- sensit ive, so it t reat s " baloney" and " Baloney" t he sam e. Perform s a num eric sort , put t ing sm aller num bers at t he t op or bot t om .

Perform s a dat e sort , dist inguishing bet ween older dat es ( t hose t hat occur first ) and m ore recent dat es.

Sort Select ed t o Cleared Yes/ No

Separat es t he select ed from t he unselect ed values. Sort Cleared t o Select ed

I n an unsort ed t able, records are ordered according t o when t hey were creat ed, so t hat t he oldest records are at t he t op of t he dat asheet , and t he newest at t he bot t om . Sort ing doesn't change how Access st ores records, but it does change t he way t hey're displayed.

Tip: Use the Home

Sort & Filter

Clear All Sorts command to return your table to its original, unsorted order.

Sort ing is a one- t im e affair. I f you edit values in a sort ed colum n, t hen Access doesn't reapply t he sort . I m agine you sort a list of people by First Nam e. I f you t hen edit t he First Nam e value for one of t he records, changing " Frankie" t o " Chen," Access doesn't relocat e t he row t o t he C sect ion. I nst ead, t he changed row rem ains in it s original place unt il you resort t he t able. Sim ilarly, any new records you add st ay at t he end of t he t able unt il t he next sort ( or t he next t im e t he t able is opened) . This behavior m akes sense. I f Access relocat ed rows whenever you m ade a change, you'd quickly becom e disorient ed.

Note: The sorting order's one of the details that Access stores in the database file. The next time you open the table in Datasheet view, Access automatically applies your sort settings.

UP TO SPEED Numbers and Special Characters in Text Fields

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-2.html (3 of 13) [1/7/2007 7:06:55 AM]

Section 3.2. Datasheet Navigation

Text sort s can be a lit t le count erint uit ive, especially if you have a t ext field t hat includes num eric cont ent . Ordinarily, when you sort t wo num bers ( like 153 and 49) , t he num bers are arranged from sm allest t o largest ( 49, 153) . However, a t ext sort doesn't work t his way. When Access perform s a t ext sort , it exam ines t he t ext charact er by charact er, which m eans it sort s num bers based on t he first digit . I f t he first digit 's t he sam e, t hen it checks t he second digit , and so on. As a result , if you sort 49 and 153 alphabet ically, you get 153, 49, because 4 ( t he first digit in 49) is larger t han 1 ( t he first digit in 153) . Life get s even m ore int erest ing if you t hrow punct uat ion and ot her special charact ers int o t he m ix. Here's t he order in which Access sort s everyt hing ( in a st andard A- t o- Z sort ) : 1. Blank ( em pt y) values 2. Space 3. Special charact ers ( like punct uat ion) 4. Let t ers 5. Num bers

3.2.1.1. Sorting on multiple fields I f a sort finds t wo duplicat e values, t here's no way t o know what order t hey'll have ( relat ive t o one anot her) . I f you sort a cust om er list wit h t wo " Van Hauser" ent ries in it , t hen you can guarant ee t hat sort ing by last nam e will bring t hem t oget her, but you don't know who'll be on t op. I f you want m ore say in how Access t reat s duplicat es, t hen you can choose t o sort based on m ore t han one colum n. The t radit ional phone book, which sort s people by last nam e and t hen by first nam e, is a perfect exam ple of t his. People who share t he sam e last nam e are t hus grouped t oget her and ordered according t o t heir first nam e, like t his: … Smith, Smith, Smith, Smith, …

Star Susan Sy Tanis

I n t he dat asheet , sort s are cum ulat ive, which m eans you can sort based on several colum ns at t he sam e t im e. The only t rick's get t ing t he order right . The following st eps t ake you t hrough t he process: 1.

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-2.html (4 of 13) [1/7/2007 7:06:55 AM]

Section 3.2. Datasheet Navigation

Ch oose H om e

Sor t & Filt e r

Cle a r All Sor t s.

Access revert s your t able t o it s original, unsort ed order. 2. Use t h e dr op- dow n colu m n m e n u t o a pply t h e su b- sor t t h a t you w a n t for du plica t e s. I f you want t o perform t he phone book sort ( nam es are organized by last nam e, t hen first nam e) , you need t o t urn on sort ing for t he First Nam e field. Sect ion 3.2 explains t he sort ing opt ions you'll see, depending on t he dat a t ype. 3. Use t h e dr op- dow n colu m n m e n u t o a pply t h e fir st le ve l sor t . I n t he phone book sort , t his is t he Last Nam e field. You can ext end t hese st eps t o creat e sort s on m ore fields. I m agine you have a ridiculously large com pendium of nam es t hat includes som e people wit h t he sam e last and first nam e. I n t his case, you could add a t hird sort by m iddle init ial. To apply t his sort , you'd swit ch sort ing on in t his order: MiddleI nit ial, First Nam e, Last - Nam e. You'll get t his result : … Smith, Smith, Smith, Smith, …

Star Susan K Susan P Sy

3.2.2. Filtering I n a t able wit h hundreds or t housands of records, scrolling back and fort h in t he dat asheet is about as relaxing as a pneum at ic drill at 3: 00 a.m . Som et im es, you don't even need t o see all t he records at oncet hey're j ust a finger- t iring dist ract ion from t he dat a you're really int erest ed in. I n t his case, you should cut t he dat asheet down t o j ust t he records t hat int erest you, wit h filt ering. I n order t o filt er records, you specify a condit ion t hat record m ust m eet in order t o be included in t he online st ore m ight pick out food it em s from a full product cat alog, a shipping com pany m ight look for a dat ing service m ight hunt down bachelors who don't live wit h t heir parent s. When you apply a filt er all t he records t hat don't m at ch your requirem ent s. They're st ill in t he t ablet hey're j ust t ucked neat ly

dat asheet . For exam ple, an orders m ade last week, and condit ion, you end up hiding out of sight .

Access has several different ways t o apply filt ers. I n t he following sect ions, you'll st art wit h t he sim plest , and t hen m ove on t o t he m ore advanced opt ions.

3.2.2.1. Quick filters A quick filt er let s you choose what values you want t o include and which ones you want t o hide, based on t he current cont ent s of your t able. To apply a quick filt er, choose t he colum n you want t o use, and t hen click t he drop- down arrow at t he colum n header's right edge. You'll see a list of all t he dist inct values in t hat colum n. I nit ially, each value has a checkm ark next t o it . Clear t he checkm ark t o hide records wit h t hat value. Figure 3- 9 shows an exam ple where a sort and filt er are being used at t he sam e t im e.

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-2.html (5 of 13) [1/7/2007 7:06:55 AM]

Section 3.2. Datasheet Navigation

Figu r e 3-9. This list of eligible bachelors is sorted first by height (in descending largest-tosmallest order), and then filtered to include only those hopefuls who live in the state of New York. A checkmark indicates that records that have this value are included in the datasheet. Others are hidden from view.

Note: To remove all the filters on a column (and show every record in the datasheet), click the drop-down button at the right edge of the column header, and then choose "Clear filter."

Not all dat a t ypes support filt ering. Dat a t ypes t hat do include Num ber, Currency, Aut oNum ber, Text , Hyperlink, Dat e/ Tim e, and Yes/ No. Mem o fields don't support quick filt ers ( because t heir values are t ypically t oo large t o fit in t he drop- down list ) , but t hey do support ot her t ypes of filt ers. You can apply quick filt ers t o m ore t han one colum n. The order in which you apply t he filt ers doesn't m at t er, as all filt ers are cum ulat ive, which m eans you see only records t hat m at ch all t he filt ers you've set . You can even use quick filt ers in com binat ion Sort & Filt er wit h t he ot her filt ering t echniques described in t he following sect ions. To rem ove your filt ers, choose Hom e Rem ove Filt er.

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-2.html (6 of 13) [1/7/2007 7:06:55 AM]

Section 3.2. Datasheet Navigation

Tip: Quick filters work best if you have a relatively small number of distinct values. Limiting people based on the state they live in is a great choice, as is the political party they support or their favorite color. It wouldn't work as well if you wanted to cut down the list based on birth date, height, or weight, because there's a huge range of different possible values. (You don't need to give up on filtering altogetherrather, you just need to use a different type of filter.)

3.2.2.2. Filter by selection Filt er by select ion let s you apply a filt er based on any value in your t able. This choice is handy if you've found exact ly t he t ype of record you want t o include or exclude. Using filt er by select ion, you can t urn t he current value int o a filt er wit hout hunt ing t hrough t he filt er list . Here's how it works. First , find t he value you want t o use for filt ering in t he dat asheet . Right - click t he value, and t hen choose one of t he filt er opt ions at t he end of t he m enu ( see Figure 3- 10) .

Figu r e 3 10. Depending on the data type, you see slightly different filtering options. For a text field (like the City field shown here), you have the option to include only the records that match the current value (Equals "Chicago"), or those that don't (Does Not Equal "Chicago"). You also have some extra filtering options that

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-2.html (7 of 13) [1/7/2007 7:06:55 AM]

Section 3.2. Datasheet Navigation

go beyond what a quick filter can donamely, you can include or exclude fields that simply contain the text "Chicago." That filter condition applies to values like "Chicagoland" and "Little Chicago."

All dat a t ypes t hat support filt ering allow you t o filt er out exact m at ches. But m any also give you som e addit ional filt ering opt ions in t he right - click m enu. Here's what you'll see for different dat a t ypes: ● ● ●

Te x t - ba se d da t a t ype s. You can filt er values t hat m at ch exact ly, or values t hat cont ain a piece of t ext . N u m e r ic da t a t ype s. You can filt er values t hat m at ch exact ly, or num bers t hat are sm aller or larger t han t he current num ber. D a t e da t a t ype s. You can filt er values t hat m at ch exact ly, or dat es t hat are older or newer t han t he current dat e.

Finally, t o get even fancier, you can creat e a filt er condit ion using only part of a value. I f you have t he value " Great at dart s" in t he Descript ion field in your t able of hopeful bachelors, you can select t he t ext " dart s," and t hen right - click j ust t hat t ext . Now you can find ot her fields t hat cont ain t he word " dart s." This abilit y is what gives t he filt er " by select ion" feat ure it s nam e. Access m akes it easy t o swit ch filt ering on and off at a m om ent 's not ice. Figure 3- 11 shows how.

Figu r e 3-11. Right next to the navigation controls at the bottom of your datasheet is a Filtered/

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-2.html (8 of 13) [1/7/2007 7:06:55 AM]

Section 3.2. Datasheet Navigation

Unfiltered indicator that tells you when filtering's applied. You can also use this box to quickly switch your filter on and offclicking it once removes all filters, and clicking it again reapplies the most recent set of filters.

3.2.2.3. Filter by condition So far, t he filt ers you use have t aken t he current values in your t able as a st art ing point . But if you're feeling confident wit h filt ers, you m ay be ready t o t ry a m ore advanced approach: filt ering by condit ion. When you use a filt er by condit ion, you can define exact ly t he filt er you want . I m agine you want t o find all t he rare wine vint ages in your cellar wit h a value of m ore t han $85. Using t he filt er- by- select ion approach, you need t o st art by finding a wine wit h a value of $85, which you can use t o build your condit ion. But what if t here isn't any wine in your list t hat has a price of exact ly $85, or what if you j ust can't seem t o find it ? A quicker approach is defining t he filt er condit ion by hand. Here's how it works. First , click t he drop- down arrow at t he right edge of t he colum n header. But inst ead of choosing one of t he quick filt er opt ions, look for a subm enu wit h filt ering opt ions. This m enu's nam ed according t o t he dat a, so t ext fields include a Text Filt ers opt ion, num ber fields have a Num ber Filt ers opt ion, and so on. Figure 3- 12 shows an exam ple.

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-2.html (9 of 13) [1/7/2007 7:06:55 AM]

Section 3.2. Datasheet Navigation

Figu r e 3 1 2 . Top: With a numeric field like this PurchasePrice field, filtering by condition lets you look at values that fall above a certain minimum. Bottom: Once you've chosen the type of filter you want, you need to supply the information for that filter. If you choose Greater Than, then you need to supply the minimum number. Records that are equal to or larger than this value are shown in the datasheet.

Here's a quick overview t hat describes t he ext ra opt ions you get using filt er by condit ion, depending on your dat a t ype: ● ● ●

Te x t - ba se d da t a t ype s. All t he sam e opt ions as filt er by select ion, plus you can find values t hat st art wit h specific t ext , or values t hat end wit h cert ain t ext . N u m e r ic da t a t ype s. All t he sam e opt ions as filt er by select ion, plus you can find values t hat are in a range, m eaning t hey're great er t han a set m inim um but sm aller t han a set m axim um . D a t e da t a t ype s. All t he sam e opt ions as filt er by select ion, plus you can find dat es t hat fall in a range, and you can chose from a huge list of built - in opt ions, like Yest erday, Last Week, Next Mont h, Year t o Dat e, First Quart er, and so on.

3.2.3. Searching Access also provides a quick search feat ure t hat let s you scan your dat asheet for specific inform at ion. Whereas filt ering helps you

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-2.html (10 of 13) [1/7/2007 7:06:55 AM]

Section 3.2. Datasheet Navigation

pull out a bat ch of im port ant records, searching's bet t er if you need t o find a single det ail t hat 's lost in t he m ount ains of dat a. And while filt ering changes t he dat asheet view by hiding som e records, searching leaves everyt hing as is. I t j ust t akes you t o t he dat a you want t o see.

POWER USERS' CLINIC Filters vs. Queries I f you use filt ers frequent ly, you're sure t o run int o a problem . Access st ores only one set of filt erst he filt ers you're current ly using. I n ot her words, once you apply a different filt er, your original filt er's gone and you need t o reapply from scrat ch t he next t im e you need it . I n m ost cases, reapplying a filt er isn't difficult . But if you've spent a considerable am ount of effort craft ing t he perfect set of filt er condit ions, and you know you want t o use t hem lat er, it 's frust rat ing. I f you find yourself in t his sit uat ion, you're overusing filt ers. I nst ead of relying on filt ers t o show t he inform at ion you're int erest ed in, you'd be bet t er off creat ing a separat e, reusable query. Like filt ers, queries let you see a subset of your dat a based on cert ain condit ions. Unlike filt ers, queries can cont ain m uch m ore sophist icat ed logic, t hey can leave out colum ns you're not int erest ed in, and Access saves t hem as separat e dat abase obj ect s so you can always reuse t hem lat er. You'll st art using queries in Chapt er 6.

The quickest way t o search is t hrough t he search box next t o t he record navigat ion cont rols ( see Figure 3- 13) . Just t ype in t he t ext you want t o find. As you t ype, t he first m at ch in t he t able is highlight ed aut om at ically. You can press Ent er t o search for subsequent m at ches.

Figu r e 3 1 3 . Here, a search is being performed for the word "bobblehead." If you find a match, you can keep searchingjust press Enter again to jump to the next match. In this example, pressing Enter sends Access to the next record's Description field.

When perform ing a search, Access scans t he t able st art ing from t he first field in t he first record. I t t hen goes left t o right ,

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-2.html (11 of 13) [1/7/2007 7:06:55 AM]

Section 3.2. Datasheet Navigation

exam ining every field in t he current record. I f it reaches t he end wit hout a m at ch, t hen it cont inues t o t he next record and checks all of it s values, and so on. When it reaches t he end of t he t able, it st ops. I f you want t o change t he way Access perform s a search, you'll need t o use t he Find feat ure inst ead: 1. Ch oose H om e

Sor t & Filt e r

Fin d. ( Or , j u st u se t h e sh or t cu t Ct r l+ F.)

The Find and Replace dialog box appears ( Figure 3- 14) .

Figu r e 3-14. The Find and Replace dialog box is the perfect tool for hunting for lost information.

2. Spe cify t h e t e x t you 'r e se a r ch in g for in t h e Fin d W h a t box , a n d t h e n se t a n y ot h e r se a r ch opt ion s you w a n t t o u se : ❍ ❍ ❍







Fin d W h a t . The t ext you're looking for. Look I n . Allows you t o choose bet ween searching t he ent ire t able or j ust a single field. M a t ch . let s you specify whet her values need t o m at ch exact ly. Use Whole Field t o require exact m at ches. Use St art of Field if you want t o m at ch beginnings ( so " bowl" m at ches " bowling" ) , or Any Part of Field if you want t o m at ch t ext anywhere in a field ( so " bowl" m at ches " League of ext raordinary bowlers" ) . Se a r ch . Set s t he direct ion Access looks: Up, Down, or All ( which loops from t he end of t he t able t o beginning, and keeps going unt il it has t raversed t he ent ire t able) . M a t ch Ca se . I f select ed, finds only m at ches t hat have ident ical capit alizat ion. So " banana" doesn't m at ch " BANANA." Se a r ch Fie lds a s For m a t t e d. I f select ed, m eans Access searches t he value as it appears on t he dat asheet . For exam ple, t he num ber 44 m ay appear in a Currency field as $44.00. I f you search for 44, you always find what you're looking for. But if you search for t he form at t ed represent at ion $44.00, you get a m at ch only if you have Search Fields as Form at t ed swit ched on. I n ext rem ely large t ables ( wit h t housands of records) , searches m ay be fast er if you swit ch off Search Fields as Form at t ed.

Note: In order to turn off Search Fields as Formatted, you must choose to search a single field in the Look In box. If you are searching the entire table, then you must search the formatted values. 3. Click Fin d N e x t . Access st art s searching from t he current posit ion. I f you're using t he st andard search direct ion ( Down) , Access m oves from left t o right in t he current record, and t hen down from record t o record unt il it finds a m at ch.

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-2.html (12 of 13) [1/7/2007 7:06:55 AM]

Section 3.2. Datasheet Navigation

When Access finds a m at ch, it highlight s t he value. You can t hen click Find Next t o look for t he next m at ch, or Cancel t o st op searching.

GEM IN THE ROUGH Find and Replace The search feat ure doubles as a powerful ( but som ewhat dangerous) way t o m odify records. I nit ially, when t he Find and Replace dialog box appears, it shows t he Find t ab. However, you can click t he Replace t ab t o be able t o find specific values and replace t hem wit h different t ext . All t he set t ings for a replace operat ion are t he sam e as for a find operat ion, except you have an addit ional t ext box, called Replace Wit h, t o supply t he replacem ent t ext . The safest way t o perform a replace operat ion is t o click t he Find Next but t on t o j um p t o t he next m at ch. At t his point , you can look at t he m at ch, check t hat you really do want t o m odify it , and t hen click Replace t o change t he value and j um p t o t he next m at ch. Repeat t his procedure t o m ove caut iously t hrough t he ent ire t able. I f you're a wild and crazy skydiving sort who prefers t o live life on t he edge, you can use t he Replace All but t on t o change every m at ching value in t he ent ire t able in a single st ep. Alt hough t his procedure's ridiculously fast , it 's also a lit t le risky. Replace operat ions can't be reversed ( t he Undo feat ure's no help here because it can reverse only a single record change) , so if you end up changing m ore t han you int end, t here's no easy way back. I f you're st ill seduced by t he ease of a Replace All, consider creat ing a backup of your dat abase file ( Sect ion 1.3.1) before going any furt her.

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-2.html (13 of 13) [1/7/2007 7:06:55 AM]

Section 3.3. Advanced Editing

3.3. Advanced Editing I n Chapt er 1, you learned t he essent ials of edit ing, including how t o add, delet e, and m odify records. However, Access has a few finer point s t hat you haven't seen yet . I n t he following sect ions, you'll t ackle t wo great conveniences in Accesst he spell checker and Aut oCorrect and you'll learn a sim ple way t o insert special charact ers in your fields.

3.3.1. The Spell Checker The spell checking funct ionalit y in Access is alm ost exact ly t he sam e as in ot her Office applicat ions like Wordit uses t he sam e dict ionary, cat ches t he sam e sort s of errors, and gives you t he opt ion t o ignore t hings it doesn't recognize, or add t hem t o t he dict ionary. The difference is t hat when you perform a spell check wit h Access, it exam ines only t he cont ent in t ext and m em o fields. Num bers, dat es, and everyt hing else get a pass. Of course, m any of your fields are likely t o cont ain t ext you don't want t o spell checklike nam es, places, or product t it les. You have t wo ways t o handle t his. You can perform a spell check on a single field, t hereby ignoring everyt hing else. Or, you can st art a dat asheet - wide spell check, but choose t o ignore cert ain fields on t he fly. Here's how it works: 1. M ove t o t h e fie ld w h e r e you w a n t t o st a r t t h e spe ll ch e ck . I f you want t o check t he ent ire dat asheet from st art t o finish, t hen m ove t o t he first field in t he first record. I f you want t o check part of t he dat asheet , t hen m ove t o t he locat ion where you want t o st art checking. Keep in m ind t hat when Access reaches t he end of your dat asheet , it loops around and st art s again at t he t op, cont inuing unt il it 's reviewed every field in every record. ( Of course, you can cancel a spell check at any t im e.) I f you want t o check j ust a single field, t hen select t hat field before cont inuing by clicking t he colum n header. 2. Ch oose H om e

Re cor ds

Spe llin g ( or j u st pr e ss F7 ) .

The Check Spelling but t on looks like a sm all checkm ark wit h t he let t ers ABC above it . I f you're perform ing a dat asheet - wide spell check, t hen Access exam ines t he current record and m oves t hrough t he fields from left t o right . When it finishes, it m oves t o t he next record and repeat s t he process. I f you've select ed a single colum n, t hen Access scans only t he values in t hat field, from t op t o bot t om . When t he spell check finishes, a dialog box inform s you t hat all your dat a's been checked. I f your t able passes t he spell check, t hen t his dialog box is t he only feedback you receive. On t he ot her hand, if Access discovers any pot ent ial spelling errors during it s check, t hen it displays a Spelling window ( as shown in Figure 3- 15) , showing t he offending word and a list of suggest ions.

Figu r e 3-15. When Access encounters a word it thinks is misspelled, it highlights the word. file:///C|/html/0596527608/access2007tm-CHP-3-SECT-3.html (1 of 7) [1/7/2007 7:07:02 AM]

Section 3.3. Advanced Editing

Unlike Microsoft Word, Access doesn't let you edit your file while the Spelling window's active. You have to either click one of the options on the Spelling windowfor example, clicking Change to replace the misspelled word with the first suggested spellingor cancel the spell check.

The Spelling window offers a wide range of choices. I f t he spell checker's com plaining about a word t hat really is m isspelled, you have t hree opt ions: ● ●



Fix it on ce . Click one of t he words in t he list of suggest ions, and t hen click Change t o replace your t ext wit h t he proper spelling. You can also double- click t he word in t he list of suggest ions, which has t he sam e effect . Fix it e ve r yw h e r e . Click one of t he words in t he list of suggest ions, and t hen click Change All t o replace your t ext wit h t he proper spelling. I f Access finds t he sam e m ist ake elsewhere in your dat asheet during t he spell check, t hen it aut om at ically repeat s t he change, wit hout bot hering t o alert you about t he problem . Fix it for e ve r . Click one of t he words in t he list of suggest ions, and t hen click Aut oCorrect . Access m akes t he change for t his field, and for any ot her sim ilarly m ist aken words. I n addit ion, it adds t he inform at ion for t he change t o t he Aut oCorrect list ( described in Sect ion 3.3.3) . I f you t ype t he sam e unrecognized word int o anot her record ( or even anot her t able) , Access aut om at ically correct s your ent ry. This opt ion's useful if you've discovered a m ist ake t hat you m ake frequent ly.

On t he ot her hand, if t he spell checker's com plaining about a word t hat you don't want t o change, you have a few m ore possibilit ies available, by clicking t he following opt ions: ● ●

I gn or e skips t his problem and keeps checking. I f Access finds t he sam e m yst ery word elsewhere in your spreadsheet , t hen it prom pt s you again for a correct ion. I gn or e All skips t his problem and keeps checking. I f Access finds t he sam e m yst ery word elsewhere in your spreadsheet , t hen it ignores t he word. You m ight use I gnore All t o force Access t o disregard som et hing you don't want t o correct , like a person's nam e.

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-3.html (2 of 7) [1/7/2007 7:07:02 AM]

Section 3.3. Advanced Editing ● ●



I gn or e Fie ld ignores any errors in t hat field for t he rem ainder of t he spell check. This way's handy t o filt er out fields t hat cont ain a lot of nam es, places, or t it les, so you don't wast e your t im e reviewing bogus spell checker suggest ions. Add adds t he word t o t he cust om spell check dict ionary. This st ep's a great one t o t ake if you plan t o keep using t he word in t his dat asheet and m any m ore. ( A com pany nam e m akes a great addit ion t o t he cust om dict ionary.) Not only does Access ignore any occurrences of t his word, but if it finds a sim ilar but slight ly different word in a field, it provides t he cust om word in it s list of suggest ions, let t ing you quickly clear up m inor t ypos. Ca n ce l st ops t he operat ion alt oget her. You can t hen correct t he field, and resum e t he spell check lat er.

Note: Every Office application on your computer shares the same custom dictionary. If you add a word in Access and then perform a spell check in Word, the same word's allowed. This convenience is timesaving, as long as you don't go overboard adding words that don't really belong.

3.3.1.1. Spell checking options You can cont rol how t he spell checker works by set t ing a few st raight forward opt ions. To set t hese opt ions ( or j ust t ake a look Access Opt ions t o show t he Access Opt ions window. Then, choose Proofing in t he list on at t hem ) , choose Office but t on t he left ( Figure 3- 16) . You can also find t he sam e page of opt ions if you click t he Spelling window's Opt ions but t on while a spell check's underway.

Figu r e 3 1 6 . The spell checker options let you specify the language and a few other miscellaneous settings. All spell check settings are languagespecific; the last box in the window indicates the language you're currently using.

Here are t he m ost com m on spelling opt ions: ● ●

I gn or e w or ds in UPPERCASE. I f you choose t his opt ion, t hen Access doesn't bot her t o check any word in all capit als ( which is helpful when your t ext cont ains lot s of acronym s) . I gn or e w or ds t h a t con t a in n u m be r s. I f you choose t his opt ion, t hen Access doesn't check words t hat cont ain num eric charact ers, like Sales43 or H3ll0. I f you don't choose t his opt ion, Access checks t hese ent ries and flags t hem as errors, unless you've specifically added t hem t o t he cust om dict ionary.

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-3.html (3 of 7) [1/7/2007 7:07:02 AM]

Section 3.3. Advanced Editing ●

● ● ●

I gn or e I n t e r n e t a n d file a ddr e sse s. I f you choose t his opt ion, t hen Access ignores words t hat appear t o be file pat hs ( like c: \ Docum ent s and Set t ings) or Web sit e addresses ( like ht t p: / / FreeSweat Socks.com ) . Fla g r e pe a t e d w or ds. This search finds errors where you inadvert ent ly repeat t he sam e word t wice, like like t his t his. En for ce a cce n t e d u ppe r ca se in Fr e n ch . Forces French words t o t ake t he accent s t hey should have, even for capit al let t ers ( where t hey look a lit t le weird) . English speakers don't need t o worry about t his set t ing. Su gge st fr om m a in dict ion a r y on ly. I f you choose t his opt ion, t hen t he spell checker doesn't use words in t he cust om dict ionary as suggest ions if it finds an unrecognized word. However, it st ill accept s a word t hat m at ches one of t he ent ries in t he cust om dict ionary.

You can also choose t he file t hat Access uses t o st ore cust om wordst he unrecognized words t hat you add t o t he dict ionary while a spell check's underway. To do so, click t he Cust om Dict ionaries but t on, which shows t he Cust om Dict ionaries dialog box ( Figure 3- 17) .

Figu r e 3-17. Top: Using the Custom Dictionaries dialog box, you can delete the current custom dictionary, add new ones, or edit the word list by hand. Bottom: If you click Edit Word List, then you see all the words in your custom.dic file. You can add new ones or remove entries that no longer apply.

Note: Custom dictionaries are stored in an account-specific section of your hard drive. For example, if you're logged in under the user account Dan_Quayle, you'll probably find the custom dictionary in the folder C:\Documents and Settings\Dan_Quayle\Application Data \Microsoft\UProof. One side effect of this system's that custom dictionaries aren't shared between two people who use different accounts on the same computer (unless you manually add the other user's dictionary in the Custom Dictionaries dialog box).

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-3.html (4 of 7) [1/7/2007 7:07:02 AM]

Section 3.3. Advanced Editing

3.3.2. AutoCorrect As you t ype t ext in a field, Aut oCorrect cleans up behind you, correct ing t hings like m iscapit alized let t ers and com m on m isspellings. Aut oCorrect is such a subt le feat ure t hat you m ight not even realize it 's m onit oring your every m ove. To get a t ast e of it s m agic, look for behaviors like t hese: ● ● ● ● ●

I f you t ype HEllo, t hen Aut oCorrect changes it t o Hello. I f you t ype friday, t hen Aut oCorrect changes it t o Friday. I f you st art a sent ence wit h a lowercase let t er, t hen Aut oCorrect uppercases it . I f you scram ble t he let t ers of a com m on word ( for exam ple, t yping t hsi inst ead of t his, or t eh inst ead of t he) , t hen Aut oCorrect replaces t he word wit h t he proper spelling. I f you accident ally hit Caps Lock, and t hen t ype j OHN sMI TH when you really want ed t o t ype John Sm it h, t hen Access not only fixes t he m ist ake, it also swit ches off Caps Lock.

For t he m ost part , Aut oCorrect 's harm less and even occasionally useful, as it can spare you from delivering m inor t ypos in a m aj or report . But if you need t o t ype irregularly capit alized words, or if you have a garden- variet y desire t o rebel against st andard English, you can t urn off som e or all of t he Aut oCorrect act ions. To set Aut oCorrect opt ions, choose Office but t on Access Opt ions t o show t he Access Opt ions window. Then, choose Proofing in t he list on t he left . I n t he page of set t ings on t he right side, click t he " Aut oCorrect ion set t ings" but t on. Most of t he set t ings are self- explanat ory, and you can t urn t hem off by unchecking t hem . Figure 3- 18 explains t he " Replace t ext as you t ype" opt ion, which is not j ust for errors.

Figu r e 3 - 1 8 . Under "Replace text as you type" is a long list of symbols and commonly misspelled words (the column on the left) that Access automatically replaces with something else (the column on the right). But what if you want the copyright symbol to appear as a C in parentheses? You can remove individual corrections (select one, and then click Delete), or you can change the replacement text. And you can add your own rules. You may want to be able to type "PESDS" and have Access insert "Patented Electronic Seltzer Delivery System". Simply type in the "Replace" and "With" text as shown here, and then click Add.

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-3.html (5 of 7) [1/7/2007 7:07:02 AM]

Section 3.3. Advanced Editing

Tip: For really advanced AutoCorrect settings, you can use the Exceptions button to define cases where Access doesn't use AutoCorrect. When you click this button, the AutoCorrect Exceptions dialog box appears with a list of exceptions. This list includes abbreviations that include the period but shouldn't be capitalized (like pp.) and words where mixed capitalization's allowed (like WordPerfect).

3.3.3. Special Characters Text cont ent isn't j ust about let t ers, num bers, and punct uat ion. You also have special sym bols t hat you can't t ype direct ly on your keyboard. One exam ple's t he copyright sym bol ( © ) , which you can insert int o a field by ent ering t he t ext ( C) , and let t ing Aut oCorrect do it s work. Ot her sym bols, like t he Greek t het a ( θ) , aren't as readily available. To use a sym bol like t his, you'll need t he help of t he Charact er Map ut ilit y. The Charact er Map is an oft en- overlooked t ool t hat let s you see all t he charact ers t hat a font provides. I t 's great for digging out t he odd accent ed é and ot her non- English charact ers.

Note: Other Office applications, like Word and Excel, provide far more special characters for you to use. They support all sorts of fonts, including the nifty Wingdings font that's included with Windows and packed with icons. However, Access has a more rigorous way or working. It accepts only plain-vanilla characters that are supported in any font. Databases store unformatted information, and, as a consequence, text fields don't include font and formatting details. The only exception's the seldom-used rich text feature for memo fields (Section 2.3.2.1).

Here's how you can use t he Charact er Map t o add a special charact er: 1. Click t h e W in dow s St a r t bu t t on , a n d t h e n ch oose Ru n . The Charact er Map ut ilit y's a part of Windows, not Access. As a result , you need t o launch it out side of Access. 2. I n t h e Ru n dia log box , t ype ch a r m a p, a n d t h e n click OK. The Charact er Map window appears ( Figure 3- 19) . 3. I n t h e Fon t list , se le ct t h e Ca libr i fon t . There's no point using an exot ic font , because Access doesn't support it . However, you can find t he support ed special charact ers using any com m on font , including Arial, Tim es, and Tahom a. Calibri's t he st andard font t hat Access uses t o display inform at ion in t he dat asheet , unless you've cust om ized it ( as described in Sect ion 3.1.2) . 4. Scr oll t h r ou gh t h e list of ch a r a ct e r s u n t il you fin d t h e on e you w a n t . I f you need a let t er charact er from anot her language, look hardyou'll alm ost cert ainly find it . I f you want som et hing a lit t le m ore exot ic but can't find it , you're probably out of luck. You'll need t o use ordinary t ext inst ead. 5. D ou ble - click t h e ch a r a ct e r . I t appears in t he " Charact ers t o copy" box at t he bot t om of t he Charact er Map window. You can repeat st eps 4 and 5 as m any t im es as you need t o copy several charact ers in a row.

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-3.html (6 of 7) [1/7/2007 7:07:02 AM]

Section 3.3. Advanced Editing

Figu r e 3-19. In this example, the copyright symbol's being copied with the help of Character Map.

6. Click Copy. Windows copies t he sym bols in " Charact ers t o copy" t o t he clipboard. 7. Sw it ch ba ck t o t h e Acce ss w in dow . I f you aren't in t he right fieldt he place where you want t o insert t he copied t ext m ove t here now. I f you want t o place t he sym bol bet ween exist ing charact ers, t hen m ake sure you m ove t he cursor t o t he right place inside t he field. 8. Pr e ss Ct r l+ V t o pa st e t h e sym bol.

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-3.html (7 of 7) [1/7/2007 7:07:02 AM]

Section 3.4. Printing the Datasheet

3.4. Printing the Datasheet I f you want t o st udy your dat a at t he dinner t able ( and aren't concerned about pot ent ial conflict s wit h nonAccess- lovers) , not hing beat s a hard copy of your dat a. You can dash off a quick print out by choosing File Print from t he m enu while your dat asheet 's visible. However, t he result s you get will probably disappoint you, part icularly if you have a large t able. The key problem 's t hat Access isn't bot hered about t ables t hat are t oo wide t o fit on a print ed page. I t deals wit h t hem by split t ing t he print out int o separat e pages. I f you have a large t able and you print it out using t he st andard Access set t ings, you could easily end up wit h a print out t hat 's four pages wide and t hree pages long. Assem bling t his j igsaw is not for t he faint of heart . To get a bet t er print out , it 's absolut ely crucial t hat you preview your t able before you print it , as described in t he next sect ion.

3.4.1. Print Preview The print preview feat ure in Access gives you t he chance t o t weak your m argins, paper orient at ion, and so on, before you send your t able t o t he print er. This way, you can m ake sure t he final print out 's genuinely usable. To preview a t able, open it ( or select it in t he navigat ion pane) , and t hen choose Office but t on Print Print Preview. The print preview shows a pict ure of what your dat a will look like once it 's com m it t ed t o paper. Unlike t he dat asheet view, t he print preview paginat es your dat a ( Figure 3- 20) . You see exact ly what fit s on each page and how m any pages your print out requires ( and what cont ent shows up on each page) .

Figu r e 3-20. This table's

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-4.html (1 of 4) [1/7/2007 7:07:06 AM]

Section 3.4. Printing the Datasheet

too wide to fit on one sheet of paper, so some of the columns are relocated to a second page.

I f you decide you're happy wit h what you see, t hen you can fire off your print out by choosing Print Preview Print Print from t he ribbon. This opens t he fam iliar Windows Print dialog box, where you can pick a print er and seal t he deal. Close Preview When you're finished looking at t he print preview window, choose Print Preview Close Print Preview, or click one of t he view but t ons at t he Access window's bot t om - right corner t o swit ch t o Dat asheet view or Design view.

3.4.1.1. Moving around the print preview You can't change anyt hing in t he print preview window. However, you can browse t hrough t he pages of your virt ual print out and see if it m eet s your approval. Here's how you can get around in t he preview window: file:///C|/html/0596527608/access2007tm-CHP-3-SECT-4.html (2 of 4) [1/7/2007 7:07:06 AM]

Section 3.4. Printing the Datasheet

● ● ●





Use t he scroll but t ons t o m ove from one page t o anot her. These but t ons look t he sam e as t he scroll but t ons in t he dat asheet , but t hey m ove from page t o page, not record t o record. To m ove from page t o page, you can use t he scroll bar at t he side of t he window or t he Page Up and Page Down keys. To j um p in for a closer look, click anywhere on t he preview page ( you'll not ice t hat t he m ouse point er has becom e a m agnifying glass) . This click m agnifies t he sheet t o 100 percent zoom , so you can m ore clearly see t he t ext and det ails. To swit ch back t o full- page view, click t he page or click t he m ouse point er again. To zoom m ore precisely, use t he zoom slider t hat 's in t he st at us bar's bot t om - right corner. Slide it t o t he left t o reduce your zoom ( and see m ore at once) , or slide it t o t he right t o increase your zoom ( and focus on a sm aller port ion of your page) . To see t wo pages at once, choose Print Preview Zoom Two Pages. To see m ore, choose Zoom More Pages, and t hen pick t he num ber of pages you want t o see at Print Preview once from t he list .

3.4.1.2. Changing the page layout Access provides a sm all set of page layout opt ions t hat you can t weak using t he ribbon's Print Preview Page Layout sect ion in t he print preview window. Here are your opt ions: ● ●



Size . Let s you use different paper sizes. I f you're fed up wit h t ables t hat don't fit , you m ight want t o invest in som e larger st ock ( like legal- sized paper) . Por t r a it a n d La n dsca pe . Let you choose how t he page is orient ed. Access, like all Office program s, assum es you want t o print out t ext using st andard port rait orient at ion. I n port rait orient at ion, pages are t urned upright so t hat t he long edge is along t he side and t he short edge is along t he t op. I t m akes perfect sense for résum és and m em os, but it 's pure m adness for a wide t able, because it guarant ees at least som e colum ns will be rudely chopped off and relocat ed t o different pages. Landscape orient at ion m akes m ore sense in t his case, because it t urns t he page on it s side, fit t ing fewer rows per page but m any m ore colum ns. M a r gin s. Let s you choose t he breat hing space bet ween your t able and t he edges of t he page. Margins is a drop- down but t on, and when you click it , you see a m enu wit h several com m on m argin choices ( Norm al, Narrow, and Wide) . I f none of t hose fit t he bill, t hen click t he Page Set up but t on, which opens a Page Set up dialog box where you can set t he exact widt h of t he m argin on each side of t he page.

3.4.2. Fine-Tuning a Printout Based on t he lim it ed page layout opt ions, you m ight assum e t hat t here's not m uch you can do cust om ize a print out . However, you act ually have m ore cont rol t han you realize. Many of t he form at t ing opt ions t hat you've learned about in t his chapt er also have an effect on your print out . By applying t he right form at t ing, you can creat e a bet t er print out . Here are som e pro print ing t ips t hat explain how different form at t ing choices influence your print out s: ● ●



Fon t . Print out s use your dat asheet font and font size. Scale t his down, and you can fit m ore in less space. Colu m n or de r a n d colu m n h idin g. Reorder your colum ns before print ing out t o suit what you want t o see on t he page. Even bet t er, use colum n hiding ( Sect ion 3.1.4) t o conceal fields t hat aren't im port ant . Colu m n w idt h s a n d r ow h e igh t . Access uses t he exact widt hs and height s t hat you've set on your

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-4.html (3 of 4) [1/7/2007 7:07:06 AM]

Section 3.4. Printing the Datasheet



● ●

dat asheet . Squeeze som e colum ns down t o fit m ore, and expand rows if you have fields wit h large am ount s of t ext and you want t hem t o wrap over m ult iple lines. Fr oze n colu m n s. I f a t able's t oo wide t o fit on your print out , t hen t he frozen colum n is print ed on each part . For exam ple, if you freeze t he First Nam e field, you'll see it on every separat e page, so you don't need t o line t he pages up t o find up who's who. Sor t opt ion s. They help you breeze t hrough dat a in a dat asheet and t hey can do t he sam e for a print out . Apply t hem before print ing. Filt e r opt ion s. These are t he unsung heroes of Access print ing. Use t hem t o get j ust t he im port ant rows. That way, your print out has exact ly what you need.

The only challenge you face when using t hese set t ings is t he fact t hat you can't set t hem from t he print preview window. I nst ead, you have t o set t hem in t he dat asheet , j um p t o t he print preview window t o see t he result , j um p back t o t he dat asheet t o change t hem a lit t le bit m ore, j um p back t o t he print preview window, and so on. This process can quickly get t iring.

Tip: Don't spend too much time tweaking the formatting options to create the perfect printout. If you have a large table that just can't fit gracefully into a page, you probably want to use reports, which are described in Part Three. They provide much more formatting muscle, including the ability to split fields over several lines, separate records with borders, and allow large values to take up more space by gently bumping other information out of the way.

file:///C|/html/0596527608/access2007tm-CHP-3-SECT-4.html (4 of 4) [1/7/2007 7:07:06 AM]

Chapter 4. Blocking Bad Data

4. Blocking Bad Data Even t he best dat abase designer has spent a sleepless night worrying about t he errors t hat could be lurking in a dat abase. Bad dat a's a not orious problem it ent ers t he dat abase, lies dorm ant for m ont hs, and appears only when you discover you've m ailed an invoice t o cust om er " Blank Blank" or sold a bag of peanut s for $4.99. The best way t o prevent t hese t ypes of problem s is t o st op bad dat a from m aking it int o your dat abase in t he first place. I n ot her words, you need t o set up validat ion rules t hat rej ect suspicious values as soon as som eone t ypes t hem in. Once bad dat a's ent ered your dat abase, it 's harder t o spot t han a blueberry in a swim m ing pool. This chapt er covers t he essent ial set of Access dat a validat ion t ools: ● ● ● ●

Th e ba sics include duplicat es, required fields, and default values. I n pu t m a sk s form at ordinary t ext int o pat t erns, like post al codes and phone num bers. Va lida t ion r u le s lay down st rict laws for unruly fields. Look u ps lim it values t o a list of preset choices.

file:///C|/html/0596527608/access2007tm-CHP-4.html [1/7/2007 7:07:08 AM]

Section 4.1. Data Integrity Basics

4.1. Data Integrity Basics All of Access's dat a validat ion feat ures work via t he Design view you learned about in Chapt er 2. To put t hem in place, you choose a field and t hen t weak it s propert ies. The only t rick's knowing what propert ies are m ost useful. You've already seen som e in Chapt er 2, but t he following sect ions fill in a few m ore det ails.

Tip: Remember, Access gives you three ways to switch to Design view. You can right-click the table tab title and then choose Design View from the menu, use the Home

View button on the ribbon, or use the tiny view buttons at the Access window's bottom-right corner. And

if you're really impatient, then you don't even need to open your table firstjust find it in the navigation pane, right-click it there, and then choose Design View.

4.1.1. Preventing Blank Fields Every record needs a bare m inim um of inform at ion t o m ake sense. However, wit hout your help, Access can't dist inguish bet ween crit ical inform at ion and opt ional det ails. For t hat reason, every field in a new t able is opt ional, except for t he prim ary- key field ( which is usually t he I D value) . Try t his out wit h t he Dolls t able from Chapt er 1; you'll quickly discover t hat you can add records t hat have virt ually no inform at ion in t hem . You can easily rem edy t his problem . Just select t he field t hat you want t o m ake m andat ory in Design view, and t hen set t he Required field propert y t o Yes ( Figure 4- 1) .

Figu r e 4-1. The Required field property tells Access file:///C|/html/0596527608/access2007tm-CHP-4-SECT-1.html (1 of 12) [1/7/2007 7:07:16 AM]

Section 4.1. Data Integrity Basics

not to allow empty values (called nulls in techspeak).

Access checks t he Required field propert y whenever you add a new record or m odify a field in an exist ing record. However, if your t able already cont ains dat a, t here's no guarant ee t hat it follows t he rules. I m agine you fill t he Dolls t able wit h a few bobbleheads before you decide t hat every record requires a value for t he Charact er field. You swit ch t o Design view, choose t he Charact er field, and t hen flip t he Required field propert y t o Yes. When you save t he t able ( by swit ching back t o Dat asheet view or closing t he t able) , Access gives you t he opt ion of verifying t he bobblehead records t hat are already in t he t able ( Figure 4- 2) . I f you choose t o perform t he t est and Access finds t he problem , it gives you t he opt ion of reversing your changes ( Figure 4- 3) .

Figu r e 4 - 2 . It's a good idea to test the data in your table to make sure it meets the new requirements you put into place.

file:///C|/html/0596527608/access2007tm-CHP-4-SECT-1.html (2 of 12) [1/7/2007 7:07:16 AM]

Section 4.1. Data Integrity Basics

Otherwise, invalid data could still remain. Don't let the message scare youunless you have tens of thousands of records, this check doesn't take long.

Figu r e 4 - 3 . If Access finds an empty value, then it stops the search and asks you what to do about it. You can keep your changes (even though they conflict with at least one record) after all, at least new records won't file:///C|/html/0596527608/access2007tm-CHP-4-SECT-1.html (3 of 12) [1/7/2007 7:07:16 AM]

Section 4.1. Data Integrity Basics

suffer from the same problem. Your other option is to reset your field to its more lenient previous self. Either way, you can track down the missing data by performing a sort on the field in question (Section 3.2), which brings empty values to the top.

WORD TO THE WISE Don't Require Too Much

file:///C|/html/0596527608/access2007tm-CHP-4-SECT-1.html (4 of 12) [1/7/2007 7:07:16 AM]

Section 4.1. Data Integrity Basics

You'll need t o t hink very carefully about what set of values you need, at a m inim um , t o creat e a record. For exam ple, a com pany selling Elvis cost um es m ight not want t o accept a new out fit int o t heir Product s t able unless t hey have every det ail in place. The Required field propert y's a great help here, because it prevent s half- baked product s from showing up in t he cat alogue. On t he ot her hand, t he sam e st rict ness is out of place in t he sam e com pany's Cust om ers t able. The sales st aff needs t he flexibilit y t o add a new prospect wit h only part ial inform at ion. A pot ent ial cust om er m ay phone and leave only a m ailing address ( wit h no billing address, phone num ber, em ail inform at ion, and so on) . Even t hough you don't have all t he inform at ion about t his cust om er, you'll st ill need t o place t hat cust om er in t he Cust om ers t able so t hat he or she can receive t he m ont hly newslet t er. As a general rule, m ake a field opt ional if t he inform at ion for it isn't necessary or m ight not be available at t he t im e t he record is ent ered.

4.1.1.1. Blank values and empty text Access support s t his Required propert y for every dat a t ype. However, wit h som e dat a t ypes you m ight want t o add ext ra checks. That 's because t he Required propert y prevent s only blank fieldsfields t hat don't have any inform at ion in t hem at all. However, Access m akes a slight ly bizarre dist inct ion bet ween blank values and som et hing called em pt y t ext . A blank ( null) value indicat es t hat no inform at ion was supplied. Em pt y t ext indicat es t hat a field value was supplied, but it j ust happens t o be em pt y. Confused yet ? The dist inct ion exist s because dat abases like Access need t o recognize when inform at ion's m issing. A blank value could indicat e an oversight som eone m ight j ust have forgot t en t o ent er t he value. On t he ot her hand, em pt y t ext indicat es a conscious decision t o leave t hat inform at ion out .

Note: To try this out in your datasheet, create a text field that has Required set to Yes. Try inserting a new record, and leaving the record blank. (Access stops you cold.) Now, try adding a new record, but place a single space in the field. Here's the strange part: Access automatically trims out the spaces, and by doing so, it converts your single space to empty text. However, you don't receive an error message because empty text isn't the same as a blank value.

The good news is t hat if you find t his whole dist inct ion confusing, t hen you can prevent bot h blank values and em pt y t ext . Just set Required t o Yes t o st op t he blank values, and set Allow Zero Lengt h t o No t o prevent em pt y t ext .

Note: A similar distinction exists for numeric data types. Even if you set Required to Yes, you can still supply a number of 0. If you want to prevent that action, then you'll need to use the validation rules described later in this chapter (Section 4.3).

4.1.2. Setting Default Values So far, t he fields in your t ables are eit her filled in explicit ly by t he person who adds t he record or left blank. But t here's anot her opt ionyou can supply a default value. Now, if som eone insert s a record and leaves t he field blank, Access applies t he default value inst ead. You set a default value using t he Default Value field propert y. For a num eric AddedCost field, you could set t his t o be t he num ber 0. For a t ext Count ry field, you could use t he t ext " U.S.A." as a default value. ( All t ext values m ust be wrapped in quot at ions m arks when you use t hem for a default value.) Access shows all your default values in t he new- row slot at t he bot t om of t he dat asheet ( Figure 4- 4) . I t also aut om at ically

file:///C|/html/0596527608/access2007tm-CHP-4-SECT-1.html (5 of 12) [1/7/2007 7:07:16 AM]

Section 4.1. Data Integrity Basics

insert s default values int o any hidden colum ns ( Sect ion 3.1.4) . Access insert s t he default value when you creat e a new record. ( You're t hen free t o change t hat value.) You can also swit ch a field back t o it s default value using t he Ct rl+ Alt + Space short cut while you're edit ing it .

Figu r e 4-4. This dating service uses four default values: a default height (5.9), a default city (New York), a default state (also New York), and a default country (U. S.A.). This system makes sense, because most of their new entries have this information. On the other hand, there's no point in supplying a default value for the name fields.

file:///C|/html/0596527608/access2007tm-CHP-4-SECT-1.html (6 of 12) [1/7/2007 7:07:16 AM]

Section 4.1. Data Integrity Basics

Tip: One nice feature is that you can use the default value as a starting point for a new record. For example, when you create a new record in the datasheet, you can edit the default value, rather than replacing it with a completely new value.

You can also creat e m ore int elligent dynam ic default values. Access evaluat es dynam ic default values whenever you insert a new record, which m eans t hat t he default value can vary based on ot her inform at ion. Dynam ic default values use expressions ( specialized dat abase form ulas) t hat can perform calculat ions or ret rieve ot her det ails. One useful expression, Dat e( ) , grabs t he current dat e t hat 's set on your com put er. I f you use Dat e( ) as t he default value for a dat e field ( as shown in Figure 4- 5) , t hen Access aut om at ically insert s t he current dat e whenever you add a new record.

Note: You'll learn much more about SQL expressions in Part Two.

4.1.3. Preventing Duplicate Values with Indexes Any t able's first rule is t hat each record it cont ains m ust be unique. To enforce t his rest rict ion, you need t o choose a prim ary key ( Sect ion 2.4) , which is one or m ore fields t hat won't ever be duplicat ed in different records. Here's t he cat ch. As you learned in Chapt er 2, t he safest opt ion's t o creat e an I D field for t he prim ary key. So far, all t he t ables you've seen have included t his det ail. But what if you need t o m ake sure ot her fields are unique? I m agine you creat e an Em ployees t able. You follow good dat abase design principles and ident ify every record wit h an aut om at ically generat ed I D num ber. However, you also want t o m ake sure t hat no t wo em ployees have t he sam e Social Securit y num ber ( SSN) t o prevent possible errorslike accident ally ent ering t he sam e em ployee t wice.

Figu r e 4 5 . If you use the Date ( ) function as the default value for the DateAcquired field in the bobblehead table, then every time you add a file:///C|/html/0596527608/access2007tm-CHP-4-SECT-1.html (7 of 12) [1/7/2007 7:07:16 AM]

Section 4.1. Data Integrity Basics

new bobblehead record, Access fills in the current date. You decide whether you want to keep that date or replace it with a different value.

Note: For a quick refresher about why ID fields are such a good idea, refer to Section 2.4.1. In the Employees table, you certainly could choose to make the SSN the primary key, but it's not the ideal situation when you start linking tables together (Chapter 5), and it causes problems if you need to change the SSN later on (in the case of an error), or if you enter employee information before you've received the SSN.

You can force a field t o require unique values wit h an index. A dat abase index is analogous t o t he index in a bookit 's a list of values ( from a field) wit h a cross- reference t hat point s t o t he corresponding sect ion ( t he full record) . I f you index t he SocialSecurit yNum ber field, Access creat es a list like t his and st ores it behind t he scenes in your dat abase file:

Ta ble 4 - 1 . Socia lSe cu r it yN u m be r

001- 01- 3455 001- 02- 0434 001- 02- 9558

Loca t ion of Fu ll Re cor d … … …

file:///C|/html/0596527608/access2007tm-CHP-4-SECT-1.html (8 of 12) [1/7/2007 7:07:16 AM]

Section 4.1. Data Integrity Basics



002- 40- 3200

Using t his list , Access can quickly det erm ine whet her a new record duplicat es an exist ing SSN. I f it does, t hen Access doesn't let you insert it . So how do you apply an index t o a field? The t rick's t he I ndexed field propert y, which is available for every dat a t ype except At t achm ent and OLE Obj ect . When you add a field, t he I ndexed propert y's set t o No, which m eans Access doesn't creat e a field. To add an index and prevent duplicat es, you can change t he I ndexed propert y in Design view t o Yes [ No Duplicat es] . The t hird opt ion, Yes [ Duplicat es OK] , creat es an index but let s m ore t han one record have t he sam e value. This opt ion doesn't help you cat ch repeat ed records, but you can use it t o speed up searches ( see t he box, " How I ndexes Speed Up Searches" in Sect ion 6.2.2 for m ore) .

UP TO SPEED How Indexes Work I t 's im port ant t hat t he list of SSNs is sort ed. Sort ing m eans t he num ber 001- 01- 3455 always occurs before 002- 40- 3200 in t he index, regardless of where t he record's physically st ored in t he dat abase. This sort ing's im port ant , because it let s Access quickly check for duplicat es. I f you ent er t he num ber 001- 02- 4300, t hen Access needs t o read only t he first part of t he list . Once it finds t he next " larger" SSN ( one t hat falls lat er in t he sort , like 001- 02- 501) , it knows t he rem ainder of t he index doesn't cont ain a duplicat e. I n pract ice, all dat abases use m any m ore opt im izat ions t o m ake t his process blazingly fast . But t here's one key principlewit hout an index, Access would need t o check t he ent ire t able. Tables aren't st ored in sort ed order, so t here's no way Access can be sure a given SSN isn't in t here unless it checks every record.

Note: As you know from Chapter 2 (Section 2.4.1), primary keys also disallow duplicates, using the same technique. When you define a primary key, Access automatically creates an index on that field.

When you close Design view aft er changing t he I ndexed field propert y, Access prom pt s you t o save your changes. At t his point , it creat es any new indexes it needs. You can't creat e a no- duplicat es index if you already have duplicat e inform at ion in your t able. I n t his sit uat ion, Access gives you an error m essage when you close t he Design window and it at t em pt s t o add t he index.

FREQUENTLY ASKED QUESTION Indexes and Performance Are indexes a t ool for prevent ing bad dat a or a t echnique for boost ing perform ance? I ndexes aren't j ust for prevent ing duplicat e values. They also shine when you need t o boost t he speed of com m on searches. Access can use t he index t o look up t he record it want s, m uch like you can use t he index at t he back of t his book t o find a specific t opic. I f you perform a search t hat scours t he Em ployees t able looking for t he person wit h a specific SSN, t hen Access can use t he index. That way, it locat es t he m at ching ent ry m uch quicker, and sim ply follows t he point er t o t he full record. For m ore inform at ion about how indexes can speed up searches, refer t o Sect ion 6.2.2. However, it 's im port ant t o realize t hat indexes enhance perform ance only for ext rem ely large, com plex t ables. I f you're st oring a few hundred records, each of which has a handful of fields, you really don't need an indexAccess already perform s searches wit h blinding speed. file:///C|/html/0596527608/access2007tm-CHP-4-SECT-1.html (9 of 12) [1/7/2007 7:07:16 AM]

Section 4.1. Data Integrity Basics

4.1.3.1. Multifield indexes You can also use indexes t o prevent a com binat ion of values from being repeat ed. I m agine you creat e a People t able t o t rack your friends and t heir cont act inform at ion. You're likely t o have ent ries wit h t he sam e first or last nam e. However, you m ay want t o prevent t wo records from having t he sam e first and last nam e. This lim it at ion prevent s you from inadvert ent ly adding t he sam e person t wice.

Note: This example could cause endless headaches if you honestly do have two friends who share the same first and last names. In that case, you'll need to remove the index before you're allowed to add the name. You should think carefully about legitimate reasons for duplication before you create any indexes.

To ensure t hat a com binat ion of fields is unique, you need t o creat e a com pound index, which com bines t he inform at ion from m ore t han one field. Here's how t o do it : 1. I n D e sign vie w , ch oose Ta ble Tools | D e sign

Sh ow / H ide

I n de x e s.

The I ndexes window appears ( Figure 4- 6) . Using t he I ndexes window, you can see your current indexes and add new ones.

Figu r e 4 6 . The Indexes window shows all the indexes that are defined for a table. Here, there's a single index for the ID field (which Access created automatically) and a compound index that's in the process of being created.

file:///C|/html/0596527608/access2007tm-CHP-4-SECT-1.html (10 of 12) [1/7/2007 7:07:16 AM]

Section 4.1. Data Integrity Basics

2. Ch oose a n a m e for you r in de x . Type t h is n a m e in t o t h e fir st bla n k r ow in t h e I n de x N a m e colu m n . The index nam e has no real im port anceAccess uses it t o st ore t he index in t he dat abase, but you don't see t he index nam e when you work wit h t he t able. Usually, you'll use t he nam e of one or bot h of t he fields you're indexing ( like Last - Nam e+ First Nam e) . 3. Ch oose t h e fir st fie ld in t h e Fie ld N a m e colu m n in t h e sa m e r ow ( lik e La st - N a m e ) . I t doesn't m at t er which field nam e you use first . Eit her way, t he index can prevent duplicat e values. However, t he order does affect how searches use t he index t o boost perform ance. You'll learn m ore in Sect ion 6.2.2. 4. I n t h e a r e a a t t h e bot t om of t h e w in dow , se t t h e Un iqu e box t o Ye s. This creat es an index t hat prevent s duplicat es ( as opposed t o one t hat 's used only for boost ing search speeds) . You can also set t he I gnore Nulls box t o Yes, if you want Access t o allow duplicat e blank values. I m agine you want t o m ake t he SSN field opt ional. However, if an SSN num ber is ent ered, t hen you want t o m ake sure it doesn't duplicat e any ot her value. I n t his case, you should I gnore Nulls t o Yes. I f you set I gnore Nulls t o No, t hen Access let s only one record have a blank SSN field, which probably isn't t he behavior you want .

Note: You can also disallow blank values altogether using the Required property, as described in Section 4.1.1

I gnore t he Prim ary box ( which ident ifies t he index used for t he prim ary key) . 5. M ove dow n on e r ow . Le a ve t h e I n de x N a m e colu m n bla n k ( w h ich t e lls Acce ss it 's st ill pa r t of t h e pr e viou s in de x ) , bu t ch oose a n ot h e r fie ld in t h e Fie ld N a m e colu m n ( lik e Fir st N a m e ) . I f you want t o creat e a com pound index wit h m ore t han t wo fields, t hen j ust repeat t his st ep unt il you've added all t he fields you need. Figure 4- 7 shows what a finished index looks like. You can now close t he I ndexes window.

file:///C|/html/0596527608/access2007tm-CHP-4-SECT-1.html (11 of 12) [1/7/2007 7:07:16 AM]

Section 4.1. Data Integrity Basics

Figu r e 4-7. Here's a compound index that prevents two people from sharing the same first and last names.

file:///C|/html/0596527608/access2007tm-CHP-4-SECT-1.html (12 of 12) [1/7/2007 7:07:16 AM]

Section 4.2. Input Masks

4.2. Input Masks As you've already learned, dat abases prize consist ency. I f you have a field nam ed Height , you bet t er be sure every value in t hat field uses t he sam e t ype of m easurem ent s; ot herwise, your dat a's not wort h it s weight in sock lint . Sim ilarly, if you have a PhoneNum ber field, you bet t er m ake sure every phone num ber has t he sam e form at . I f som e phone num bers are writ t en wit h dashes, spaces, and parent heses ( like ( 844) 547- 1123) , while ot hers are a bit different ( say 847- 547- 1123) , and a few leave out t he area code inform at ion alt oget her ( 547- 1123) , t hen you've got a sm all problem on your hands. Because of t he lack of consist ency, you'll have a hard t im e working wit h t his inform at ion ( say, searching for a specific phone num ber or sort ing t he phone num bers int o different cat egories based on area code) . To help you m anage values t hat have a fixed pat t ernlike phone num bersyou can use an input m ask. Essent ially, an input m ask ( or j ust m ask for short ) gives you a way t o t ell Access what pat t ern your dat a should use. Based on t his pat t ern, Access changes t he way values are ent ered and edit ed t o m ake t hem easier t o underst and and less error- prone. Figure 4- 8 shows how a m ask let s Access form at a series of charact ers as t hey're being t yped int o a field.

Figu r e 4 8 . Top: Here's a PhoneNumber field with a mask that's ready to go. So far, the person entering the record hasn't typed anything. The PhoneNumber field automatically starts out with this placeholder text. Bottom: The mask formats the numbers as you type.

file:///C|/html/0596527608/access2007tm-CHP-4-SECT-2.html (1 of 10) [1/7/2007 7:07:24 AM]

Section 4.2. Input Masks

If you type 1234567890 into this phone number mask, then you see the text (123) 456-7890. Behind the scenes, the databases stores 1234567890, but the information's presented in the datasheet using a nicely formatted package. That package is the mask.

You can add a m ask t o any field t hat uses t he Text dat a t ype. Masks give you several advant ages over ordinary t ext : ●



● ●

M a sk s gu ide da t a e n t r y. When em pt y, a m asked edit cont rol shows t he place- holders where values need t o go. A phone num ber m ask shows t he t ext ( _ _ _) _ _ _- _ _ _ _ when it 's em pt y, clearly indicat ing what t ype of inform at ion it needs. M a sk s m a k e da t a e a sie r t o u n de r st a n d. You can read m any values m ore easily when t hey're present ed a cert ain way. Most people can pick out t he num bers in t his form at t ed Social Securit y num ber ( 012- 86- 7180) fast er t han t his unform at t ed one ( 012867180) . M a sk s pr e ve n t e r r or s. Masks rej ect charact ers t hat don't fit t he m old. I f you're using t he t elephone m ask, you can't use let t ers. M a sk s pr e ve n t con fu sion . Wit h m any t ypes of dat a, you have several ways t o present t he sam e inform at ion. You can ent er phone num bers bot h wit h and wit hout area codes. By present ing t he m ask wit h t he area code placeholder, you're saying t hat t his inform at ion's required ( and where it goes) . I t 's also obvious t hat you don't need t o t ype in parent heses or a dash t o separat e num bers, because t hose det ails are already t here. You'll see t he sam e benefit if you use m asks wit h dat es, which can be ent ered in all sort s of different com binat ions ( Year/ Mont h/ Day, Mont h- DayYear, and so on) .

Masks are best suit ed for when you're st oring num eric inform at ion in a t ext field. This scenario occurs wit h all sort s of dat a, file:///C|/html/0596527608/access2007tm-CHP-4-SECT-2.html (2 of 10) [1/7/2007 7:07:24 AM]

Section 4.2. Input Masks

including credit card num bers, post al codes, and phone num bers. These t ypes of inform at ion shouldn't be st ored in num ber fields, because t hey aren't m eant t o be int erpret ed as a single num ber. I nst ead, t hey're m eant t o be underst ood as a series of digit s. ( I f you do m ake t he m ist ake of st oring a phone num ber in a num ber field, you'll find out t hat people can t ype in perfect ly nonsensical phone num bers like 0 and14 because t hese are valid num bers, even if t hey aren't valid phone num bers. But an input m ask on a t ext field cat ches t hese errors easily.) Masks can't help you wit h m ore sophist icat ed challenges, like dat a values t hat have varying lengt hs or subt le pat t erns. For inst ance, a m ask doesn't help you spot an incorrect em ail address.

Note: Text and Date/Time are the only data types that support masks.

4.2.1. Using a Ready-Made Mask The easiest way t o get st art ed wit h m asks is t o use one of t he m any at t ract ive opt ions t hat Access has ready for you. This m et hod's great , because it m eans you don't need t o learn t he arcane art of m ask creat ion. Here's what you need t o do t o pick out a prebuilt m ask: 1. I n D e sign vie w , se le ct t h e t e x t fie ld w h e r e you w a n t t o a pply t h e m a sk . For t his t est , t ry a PhoneNum ber field. 2. Look for t h e I n pu t M a sk fie ld pr ope r t y. Click in side t h e fie ld. When you do, a sm all ellipsis ( …) but t on appears at t he left edge, as shown in Figure 4- 9.

Figu r e 4 - 9 . The ellipsis (…) button (circled) is just the way Access tells you that you don't need to fill in this value by hand. Instead, you can click the ellipsis and pop up a wizard (like the Input Mask wizard) or some sort of helpful dialog box.

3.

file:///C|/html/0596527608/access2007tm-CHP-4-SECT-2.html (3 of 10) [1/7/2007 7:07:24 AM]

Section 4.2. Input Masks

Click t h e e llipsis bu t t on . The I nput Mask wizard st art s ( see Figure 4- 10) .

Figu r e 4-10. The Input Mask wizard starts with a short list of commonly used masks. Next to every mask, Access shows you what a sample formatted value looks like. Once you select a mask, you can try using it in the Try It text box. The Try It text box gives you the same behavior that your field will have once you apply the mask.

4.

file:///C|/html/0596527608/access2007tm-CHP-4-SECT-2.html (4 of 10) [1/7/2007 7:07:24 AM]

Section 4.2. Input Masks

Ch oose t h e m a sk you w a n t fr om t h e list of opt ion s. I n t his case, choose t he first it em in t he list ( Phone Num ber) .

Note: Don't see what you want? You'll need to create your own, using the tips in Section 4.2.2. If you see one that's close but not perfect, select it. You can tweak the mask in the wizard's second step. 5. Click N e x t . The wizard's second st ep appears ( see Figure 4- 11) . 6. I f you w a n t , you ca n ch a n ge t h e m a sk or t h e pla ce h olde r ch a r a ct e r . To change t he m ask, you'll need t o learn what every m ask charact er m eans. Sect ion 4.2.2 explains it all.

Figu r e 4-11. The phone number mask is ! (999) 000000. Each 9 represents an optional number from 0 to 9. Each 0 represents a required number from 0 to 9. So according to this mask, (123) 4567890 is a valid phone number, as is 123-

file:///C|/html/0596527608/access2007tm-CHP-4-SECT-2.html (5 of 10) [1/7/2007 7:07:24 AM]

Section 4.2. Input Masks

4567, but (123) 456 isn't.

You use t he placeholder t o show t he em pt y slot s where you ent er inform at ion. The st andard choice is t he underscore. Opt ionally, you can use a space, dash, ast erisk, or any ot her charact er by t yping it in t he " Placeholder charact er" box. 7. Click N e x t . I f you're adding a m ask t o a t ext field, t hen t he wizard's final st ep appears ( see Figure 4- 12) . I f you're adding a m ask t o a dat e field, t hen Access doesn't need t o ask you how t o st ore t he inform at ionit already knows. I n t his case, you can j um p t o st ep 9 and click Finish.

Figu r e 4-12. The final step lets you choose how the data in your field is chosenwith or without the mask symbols.

8. Ch oose h ow you w a n t t o st or e t h e va lu e in t h is fie ld. The st andard choice is t o st ore j ust t he charact ers you've t yped in ( in ot her words, everyt hing you t ype int o t he field) . I f you use t his opt ion, t he placeholders aren't included. For exam ple, t he phone num ber ( 416) 123- 4567 is st ored as 4161234567. This opt ion saves a lit t le space, and it also let s you change t he m ask lat er on t o present t he inform at ion in a slight ly different way. You could also st ore t he m ask com plet e wit h all t he ext ra charact ers. Then a phone num ber's st ored com plet e wit h hyphens, dashes, and spaces, like ( 416) 123- 4567. This approach isn't nearly as flexible because you can't change file:///C|/html/0596527608/access2007tm-CHP-4-SECT-2.html (6 of 10) [1/7/2007 7:07:24 AM]

Section 4.2. Input Masks

t he m ask lat er. 9. Click Fin ish . The final m ask appears in t he I nput Mask field propert y. Before going any furt her, you m ay want t o m ake sure t hat t he lengt h you've reserved for your field m at ches t he m ask. I n t he phone num ber exam ple, you need a Field Size of 10 if you've chosen t o st ore unform at t ed values ( because t here are 10 digit s) , or a Field Size of 14 for t he whole shebang, com plet e wit h placeholders ( one dash, one space, and t wo parent heses) . 10. Sw it ch ba ck t o t h e D a t a sh e e t vie w , a n d click Ye s w h e n Acce ss a sk s you t o sa ve ch a n ge s. Your input m ask is now in place.

Note: Access uses the input mask information to control how you enter information in the datasheet. However, it's possible to circumvent the mask by entering the information in other ways. You could, for instance, create a form (as described in Part Four), and switch off the mask. A mask's not an absolute guarantee against invalid dataif you want such a guarantee, then you need a validation rule instead.

4.2.2. Creating Your Own Mask The I nput Mask wizard provides a fairly lim it ed set of choices. I f you want t o use a m ask wit h your own t ype of inform at ion ( like a special cust om er code t hat your business uses) , t hen you'll have t o creat e your own m ask. Creat ing a m ask's fairly easy, but it can t ake a bit of fiddling before you nail down exact ly t he result you want . You have t wo basic opt ions: ● ●

Type or edit t he m ask direct ly in t he I nput Mask field propert y. Launch t he I nput Mask wizard, choose a m ask t o use as a st art ing point ( as described in Sect ion 4.2.1) , and t hen t weak it in st ep 2. This approach has t he advant age t hat you can t est your m ask in t he Try I t box before you save it as part of your t able.

Every m ask's built out of t hree t ypes of charact ers: ● ● ●

Pla ce h olde r s designat e where you t ype in a charact er. Spe cia l ch a r a ct e r s give addit ional inst ruct ions t hat t ell Access how t o t reat a part of t he m ask. Lit e r a ls are all ot her charact ers, which are really j ust decorat ion t o help m ake t he value easier t o int erpret .

I n t he previous exam ple, t he phone num ber m ask was ! ( 999) 000- 000. The charact ers 9 and 0 are placeholderst hey represent where you t ype in t he digit s of t he phone num ber. The parent heses, space, and dash are j ust form at t ing nicet iest hey're t he lit erals. And t he exclam at ion m ark's t he only special charact er. I t t ells Access t hat charact ers should be ent ered int o t he m ask from left t o right , which is t he st andard opt ion and t he only one t hat really m akes sense for a phone num ber. To help you sort all t his out , refer t o t he following t ables. Table 4- 1 shows all t he placeholders you can use in an input m ask. Table 4- 2 shows ot her special charact ers. Everyt hing else is aut om at ically a lit eral charact er.

file:///C|/html/0596527608/access2007tm-CHP-4-SECT-2.html (7 of 10) [1/7/2007 7:07:24 AM]

Section 4.2. Input Masks

Ta ble 4 - 2 . Pla ce h olde r Ch a r a ct e r s for a n I n pu t M a sk Ch a r a ct e r

D e scr ipt ion

0

A required digit ( 0 t hrough 9) .

9

An opt ional digit ( 0 t hrough 9) .

#

An opt ional digit , a plus sign ( + ) , or a m inus sign ( - )

L

A required let t er.

?

An opt ional let t er.

A

A required let t er or digit .

a

An opt ional let t er or digit .

&

A required charact er of any t ype ( including let t ers, num bers, punct uat ion, and so on) .

C

An opt ional charact er of any t ype ( including let t ers, num bers, punct uat ion, and so on) .

Ta ble 4 - 3 . Spe cia l Ch a r a ct e r s for a n I n pu t M a sk Ch a r a ct e r

D e scr ipt ion

!

I ndicat es t hat t he m ask's filled from left t o right when charact ers are t yped in. This is t he default , so t his charact er's not required ( alt hough t he prebuilt m asks include it ) .




Convert s all charact ers t hat follow t o uppercase.

\

I ndicat es t hat t he following charact er should be t reat ed as a lit eral. For exam ple, t he # charact er has a special m eaning in m asks. Thus, if you want t o act ually include a # in your m ask, you need t o use \ # . Som et im es, t his charact er's used before a placeholder even when it 's not needed. You m ay see a phone m ask t hat has t he charact er sequence \ - inst ead of j ust - . Bot h are equivalent .

Password

Creat es a password ent ry box. Any charact er you t ype in t he box is st ored as t he charact er but displayed as an ast erisk ( * ) . When using t his opt ion, you can't include anyt hing else in your m ask.

Here are a few sam ple m asks t o get you st art ed: ●

● ● ●



( 0 0 0 ) 0 0 0 - 0 0 0 . A phone num ber t hat requires t he area code digit s. This m ask's different from t he phone num ber m ask t hat t he I nput Mask wizard uses. That m ask replaces t he first t hree 0 charact ers wit h 9, m aking t he area code opt ional. 0 0 0 0 0 - 9 9 9 9 . A U.S. zip code, which consist s of five required digit s followed by a hyphen and ( opt ionally) four m ore digit s. L0 L 0 L0 . A Brit ish or Canadian post al code, which is a pat t ern of six charact ers t hat alt ernat e bet ween charact ers and digit s, like M6S 3H2. 9 9 :0 0 :0 0 > LL. A m ask for ent ering t im e inform at ion int o a Dat e/ Tim e field. I t 's m ade up of t wo digit s for t he hour and t wo digit s for t he m inut e. The last t wo charact ers are always displayed in uppercase ( t hanks t o t he > charact er) , and are m eant t o be AM or PM. ( Technically, t his m ask doesn't prevent t he user from flout ing t he syst em and t yping in t wo different charact ers. However, if you ent er a t im e like 12: 30 GM, Access com plains t hat it can't convert your ent ry int o t he Dat e/ Tim e dat a t ype, as required for t he field.) 0 9 9 .0 9 9 .0 9 9 .0 9 9 . An I P ( I nt ernet Prot ocol) address, which ident ifies a com put er on a net work. An I P address is writ t en as four values separat ed by periods. Each value m ust have at least one digit , and can have up t o t hree. This

file:///C|/html/0596527608/access2007tm-CHP-4-SECT-2.html (8 of 10) [1/7/2007 7:07:24 AM]

Section 4.2. Input Masks



pat t ern's represent ed in t he m ask by 099 ( one required digit , followed by t wo opt ional digit s) . Pa ssw or d. A m ask t hat allows ordinary, unlim it ed t ext , wit h one difference. All charact ers are displayed as ast erisks ( * ) , t o hide t hem from prying eyes.

Masks can also have t wo opt ional bit s of inform at ion at t he end, separat ed by sem icolons ( ; ) . The second sect ion's a num ber t hat t ells Access whet her or not it should st ore t he lit eral charact ers for t he m ask in t he record. ( This is t he last quest ion t hat t he I nput Mask wizard asks.) I f you leave t his piece out or use t he num ber 1, t hen Access st ores only t he charact ers t hat som eone t ypes in. I f you use t he num ber 0, t hen Access st ores t he full t ext wit h t he lit erals. The t hird sect ion supplies t he placeholder charact er. I f you leave t his sect ion out , t hen Access uses t he fam iliar underscore. Here's a m ask t hat uses t hese t wo ext ra bit s of inform at ion: (000) 000-000;1;#

Here, t he second sect ion's 1, and t he t hird sect ion's # . This m ask's for phone num bers, and it st ores lit erals ( in t his case, t wo parent heses, a space, and a dash) and uses t he num ber sign for a placeholder inst ead of t he underscore.

POWER USERS' CLINIC Adding Your Mask to the Mask List Som et im es you m ay creat e a m ask t hat 's so useful you want t o use it in m any different t ables in your dat abase ( and m aybe even in different dat abases) . While you can cert ainly copy your m ask t o every field t hat needs t o use it , Access has a nicer opt ionyou can st ore your m ask in it s m ask list . That way, t he m ask shows up whenever you run t he I nput Mask wizard, right alongside all Access's ot her st andard m asks. To add your m ask t o t he list , head t o t he I nput Mask field propert y ( for any field) , and t hen click t he ellipsis but t on t o fire up t he I nput Mask wizard. Then, click t he Edit List but t on, which pops up a handy window where you can edit t he m asks t hat Access provides, and add your own ( Figure 4- 13) .

Figu r e 4-13. To add your own mask, use the record scrolling buttons (at the bottom of this window) to scroll to the end. Or

file:///C|/html/0596527608/access2007tm-CHP-4-SECT-2.html (9 of 10) [1/7/2007 7:07:24 AM]

Section 4.2. Input Masks

you can use this window to change a mask. For example, the prebuilt telephone mask doesn't require an area code. If that's a liberty you're not willing to take, then replace it with the more restrictive version (000) 0000000.

file:///C|/html/0596527608/access2007tm-CHP-4-SECT-2.html (10 of 10) [1/7/2007 7:07:24 AM]

Section 4.3. Validation Rules

4.3. Validation Rules I nput m asks are a great t ool, but t hey apply t o only a few specific t ypes of inform at ionusually fixed- lengt h t ext t hat has a single, unchanging pat t ern. To creat e a t ruly bullet proof t able, you need t o use m ore sophist icat ed rest rict ions, like m aking sure a num ber falls in a cert ain range, checking t hat a dat e hasn't yet occurred, or verifying t hat a t ext value st art s wit h a cert ain let t er. Validat ion rules can help you creat e all t hese rest rict ions by drawing on t he full power of t he SQL language.

Note: You'll get a more thorough introduction to SQL starting in Chapter 6. Fortunately, you need only a dash of SQL to write a validation rule. The key ingredient's a validation expression, and you'll see several practical examples of expressions that you can drop straight into your tables.

A validat ion rule's prem ise is sim ple. You set up a rest rict ion t hat t ells Access which values t o allow in a field and which ones are no good. Whenever som eone adds a new record or edit s a record, Access m akes sure t he dat a lives up t o your validat ion rules. I f it doesn't , t hen Access present s an error m essage and forces you t o edit t he offending dat a and t ry again.

4.3.1. Applying a Field Validation Rule Each field can have a single validat ion rule. The following set of st eps show you how t o set one up. You'll st art out easy, wit h a validat ion rule t hat prevent s a num eric field from accept ing 0 or any negat ive num ber ( and in t he following sect ions you'll hone your rule- writ ing abilit ies so you can t ackle ot her dat a t ypes) . Here's how t o add your validat ion rule: 1. I n D e sign vie w , se le ct t h e fie ld t o w h ich you w a n t t o a pply t h e r u le . All dat a t ypesexcept Mem o, Aut oNum ber, and OLE Obj ect support validat ion. The validat ion rule in t his exam ple works wit h any num eric dat a t ype ( like Num ber or Currency) . 2. I n t h e Va lida t ion Ru le fie ld pr ope r t y, t ype a va lida t ion e x pr e ssion ( Figu r e 4 - 1 4 ) . An expression's a bit of SQL t hat perform s a check on t he dat a you've ent ered. Access perform s it s validat ion check when you finish ent ering a piece of dat a, and t ry t o navigat e t o anot her field or anot her record. For exam ple, > 0 is a validat ion rule t hat forces t he value in a Num ber field t o be larger t han 0. You'll learn m ore validat ion rules in t he following sect ions.

Figu r e 4-14. Here, the Validation Rule

file:///C|/html/0596527608/access2007tm-CHP-4-SECT-3.html (1 of 8) [1/7/2007 7:07:32 AM]

Section 4.3. Validation Rules

property prevents impossible prices, and the Validation Text provides an error message.

3. Type som e e r r or - m e ssa ge t e x t in t h e Va lida t ion Te x t fie ld pr ope r t y. I f you ent er a value t hat fails t he validat ion check, t hen Access rej ect s t he value and displays t his error t ext in a dialog box. I f you don't supply any t ext , t hen Access shows t he validat ion rule for t he field ( what ever you ent ered in st ep 2) , which is m ore t han a lit t le confusing for m ost m ere m ort als. 4. Righ t - click t h e t a b t it le , a n d t h e n ch oose D a t a sh e e t Vie w . I f your t able has exist ing records, Access gives you t he opt ion of checking t hem t o m ake sure t hey m eet t he requirem ent s of your validat ion rule. You decide whet her you want t o perform t his check, or skip it alt oget her. Once you're in Dat asheet view, you're ready t o t ry out your validat ion rule ( Figure 4- 15) .

Figu r e 4-15. Here, a validation rule of >0 prevents negative numbers in the Price field. When you file:///C|/html/0596527608/access2007tm-CHP-4-SECT-3.html (2 of 8) [1/7/2007 7:07:32 AM]

Section 4.3. Validation Rules

enter a negative number, Access pops up a message box with the validation text you defined, as shown here. Once you click OK, you return to your field, which remains in edit mode. You can change the value to a positive number, or press Esc to cancel the record edit or insertion.

Note: Just because your table has validation rules doesn't mean the data inside follows these rules. A discrepancy can occur if you added records before the validation rules came into effect. (You learned about the same potential problem with required fields in Section 4.1.1.) To avoid these headaches, set up your validation rules before you start adding data.

4.3.2. Writing a Field Validation Rule As you can see, it 's easy enough t o apply a validat ion rule t o a field. But creat ing t he right validat ion rule t akes m ore t hought . I n order t o get t he result you want , you need t o t ake your first st ep int o t he som et im es quirky world of SQL. Alt hough validat ion's lim it ed only by your im aginat ion, Access pros t urn t o a few basic pat t erns again and again. The following sect ions give you som e quick and easy st art ing point s for validat ing different dat a t ypes.

file:///C|/html/0596527608/access2007tm-CHP-4-SECT-3.html (3 of 8) [1/7/2007 7:07:32 AM]

Section 4.3. Validation Rules

Note: Access uses your validation rule only if a field contains some content. If you leave it blank, then Access accepts if without any checks. If this isn't the behavior you want, then just set the Required property to Yes to make the field mandatory, as described in Section 4.1.1.

4.3.2.1. Validating numbers For num bers, t he m ost com m on t echnique's t o check t hat t he value falls in a cert ain range. I n ot her words, you want t o check t hat a num ber's less t han or great er t han anot her value. Your t ools are t he com parison signs < and > . Table 4- 3 shows som e com m on exam ples.

Ta ble 4 - 4 . Ex pr e ssion s for N u m be r s Com pa r ison

Sa m ple Ex pr e ssion

D e scr ipt ion

Less t han

< 100

The value m ust be less t han 100.

Great er t han

>0

The value m ust be great er t han 0.

Not equal t o

< > 42

The value can be anyt hing except 42.

Less t han or equal t o

< = 100

The value m ust be less t han or equal t o 100.

Great er t han or equal t o

>=0

The value m ust be great er t han or equal t o 0.

Equal t o

= 42

The value m ust be 42. ( Not m uch point in asking anyone t o t ype it in, is t here?)

Bet ween

Bet ween 0 and 100

The value m ust be 0, 100, or som ewhere in bet ween.

4.3.2.2. Validating dates As wit h num bers, dat e validat ion usually involves checking t o see if t he value falls wit hin a specified range. Here, your challenge is m aking sure t hat your dat e's in t he right form at for an expression. I f you use t he validat ion rule > Jan 30, 2007, Access is ut t erly confused, because it doesn't realize t hat t he t ext ( Jan 30, 2007) is supposed t o represent a dat e. Sim ilarly, if you t ry > 1/ 30/ 07, t hen Access assum es t he num bers on t he right are part of a division calculat ion. To solve t his problem , use Access universal dat e synt ax, which looks like t his: #1/30/2007#

A universal dat e always has t he dat e com ponent s in t he order m ont h/ day/ year, and it 's always bracket ed by t he # sym bol on eit her side. Using t his synt ax, you can craft a condit ion like > # 1/ 30/ 2007# , which st at es t hat a given dat e m ust be larger t han ( fall aft er) t he dat e January 30, 2007. January 31, 2007 fit s t he bill, but a dat e in 2006 is out . The universal dat e synt ax can also include a t im e com ponent , like t his: #1/30/2007 5:30PM#

Note: When comparing two dates, Access takes the time information into consideration. The date #1/30/2007# doesn't include any time information, so it's treated as though it occurs on the very first second of the day. As a result, Access considers the date value #1/30/2007 8:00 AM# larger, because it occurs eight hours later.

Once you've learned t he universal dat e synt ax, you can use any of t he com parison operat ors you used wit h num bers. You can also use t hese handy funct ions t o get inform at ion about t he current dat e and t im e: ● ●

D a t e ( ) get s t he current dat e ( wit hout any t im e inform at ion, so it count s as t he first second of t he day) . N ow ( ) get s t he current inst ant in t im e, including t he dat e and t im e inform at ion.

file:///C|/html/0596527608/access2007tm-CHP-4-SECT-3.html (4 of 8) [1/7/2007 7:07:32 AM]

Section 4.3. Validation Rules

Note: A function's a built-in code routine that performs some task, like fetching the current date from the computer clock. You'll learn about many more date functions, which let you perform advanced tasks like finding the day of the week for a date, in Section 7.2.6.

Table 4- 4 has som e exam ples.

Ta ble 4 - 5 . Ex pr e ssion s for D a t e s Com pa r ison

Sa m ple Ex pr e ssion

D e scr ipt ion

Less t han

< # 1/ 30/ 2007#

The dat e occurs before January 30, 2007.

Great er t han

> # 1/ 30/ 2007 5: 30 PM#

The dat e occurs aft er January 30, 2007, or on January 30, 2007, aft er 5: 30 p.m .

Less t han or equal t o

< = # 1/ 30/ 2007#

The dat e occurs before January 30, 2007, or on t he first second of January 30, 2007.

Great er t han or equal t o

> = # 1/ 30/ 2007#

The dat e occurs on or aft er January 30, 2007.

Great er t han t he current dat e

> Dat e( )

The dat e occurs t oday or aft er.

Less t han t he current dat e

< Dat e( )

The dat e occurs yest erday or before.

Great er t han t he current dat e ( and t im e)

> Now( )

The dat e occurs t oday aft er t he current t im e, or any day in t he fut ure.

Less t han t he current dat e ( and t im e)

< Now( )

The dat e occurs t oday before t he current t im e, or any day in t he past .

4.3.2.3. Validating text Wit h t ext , validat ion let s you verify t hat a value st art s wit h, ends wit h, or cont ains specific charact ers. You perform all t hese t asks wit h t he Like operat or, which com pares t ext t o a pat t ern. This condit ion forces a field t o st art wit h t he let t er R: Like "R*"

The ast erisk ( * ) represent s zero or m ore charact ers. Thus, t he com plet e expression asks Access t o check t hat t he value st art s wit h R ( or r) , followed by a series of zero or m ore charact ers. You can use a sim ilar expression t o m ake sure a piece of t ext ends wit h specific charact ers: Like "*ed"

This expression allows t he values t alked, walked, and 34z% ( $) # ed, but not t alking, walkable, or 34z% ( $) # . For a slight ly less com m on t rick, you can use m ore t han one ast erisk. The following expression requires t hat t he let t er a and b appear ( in t hat order but not necessarily next t o each ot her) som ewhere in a t ext field: Like "*a*b*"

Along wit h t he ast erisk, t he Like operat or also support s a few m ore charact ers. You can use ? t o m at ch a single charact er, which is handy if you know how long t ext should be or where a cert ain let t er should appear. Here's t he validat ion rule for an eight - charact er product code t hat ends in 0ZB: Like "?????0ZB"

file:///C|/html/0596527608/access2007tm-CHP-4-SECT-3.html (5 of 8) [1/7/2007 7:07:32 AM]

Section 4.3. Validation Rules

The # charact er plays a sim ilar role, but it represent s a num ber. Thus, t he following validat ion rule defines a product code t hat ends in 0ZB and is preceded by five num bers: Like "#####0ZB"

And finally, you can rest rict any charact er t o cert ain let t ers or sym bols. The t rick's t o put t he allowed charact ers inside square bracket s. Suppose your com pany uses an eight - charact er product code t hat always begins wit h A or E. Here's t he validat ion rule you need: Like "[AE]???????"

Not e t hat t he [ AE] part represent s one charact er, which can be eit her A or E. I f you want ed t o allow A, B, C, D, you'd writ e [ ABCD] inst ead, or you'd use t he handy short cut [ A- D] , which m eans " allow any charact er from A t o D, including A and D." Here's one m ore validat ion expression, which allows a seven- let t er word, and doesn't allow num bers or sym bols. I t works by repeat ing t he [ A- Z] code ( which allows any let t er) seven t im es. Like [A-Z][A-Z][A-Z][A-Z][A-Z][A-Z][A-Z]

As you can see, t ext validat ion expressions aren't always pret t y. Not only can t hey grow t o ridiculous sizes, but t here are lot s of rest rict ions t hey can't apply. You can't , for inst ance, let t he lengt h of t he t ext vary bet ween a m inim um and m axim um t hat you set . And you can't dist inguish bet ween capit alized and lowercase let t ers.

Note: You can get around many of these limitations using some of the functions that Access provides. in Section 7.2.5, you'll learn how to use functions that can snip out bits of text, test lengths, check capitalization, and more.

4.3.2.4. Combining validation conditions No m at t er what t he dat a t ype, you can also com bine your condit ions in t wo different ways. Using t he And keyword, you can creat e a validat ion rule t hat enforces t wo requirem ent s. This t rick's handy, because each field can have at m ost a single validat ion rule. To use t he And keyword, j ust writ e t wo validat ion rules and put t he word And in bet ween. I t doesn't m at t er which validat ion rule's first . Here's a validat ion rule t hat forces a dat e t o be before t oday but lat er t han January 1, 2000: #1/1/2000#

You can also use t he Or keyword t o accept a value if it m eet s eit her one of t wo condit ions. Here's a validat ion rule t hat allows num bers great er t han 1000 or less t han1000: >1000 Or 50 on t he Price field) . Every t im e you need t o review, print , or edit inform at ion about expensive product s, you run t he TopProduct s query. To fine- t une t he query set t ings, right - click it in t he navigat ion pane, and t hen choose Design View.

file:///C|/html/0596527608/access2007tm-CHP-6-SECT-2.html (8 of 21) [1/7/2007 7:08:39 AM]

Section 6.2. Creating Queries

Access let s you open your t able and any queries t hat use it at t he sam e t im e. ( They all appear in separat e t abs.) However, you can't m odify t he design of your t able unt il you close all t he queries t hat use it . I f you add new records t o a t able while a query's open, t hen t he new records don't aut om at ically appear in t he query. Records Refresh Refresh All. I nst ead, you'll need t o run your query again. The quickest way is t o choose Hom e You can also close your query and open it again, because Access runs your query every t im e you open it in Dat asheet view.

Note: Remember, a query's a view of some of the data in your table. When you edit your query results, Access changes the data in the underlying table. On the other hand, it's perfectly safe to rename, modify, and delete queriesafter all, they're there to make your life simpler.

6.2.1.1. Building filter expressions The secret t o a good query's get t ing t he inform at ion you want , and not hing m ore. To t ell Access what records it should get ( and which ones it should ignore) , you need a filt er expression. The filt er expression defines t he records you're int erest ed in. I f you want t o find all t he orders t hat were placed by a cust om er wit h t he I D 1032, you could use t his filt er expression: =1032

To put t his filt er expression int o act ion, you need t o put it in t he Crit eria box under t he Cust om erI D field. Technically, you could j ust writ e 1032 inst ead of = 1032, but it 's bet t er t o st ick t o t he second form , because t hat 's t he pat t ern you'll use for m ore advanced filt er expressions. I t st art s wit h t he operat or ( in t his case, t he equals sign) t hat defines how Access should com pare t he inform at ion, followed by t he value ( in t his case, 1032) you want t o use t o m ake t he com parison.

Note: If you're using a multivalue field (Section 5.3.2.2), then Access includes the record in the query results if any value matches your filter. Imagine a Classes table that includes a multivalue InstructorID field (indicating that more than one teacher can team up to teach the same class). If you write the filter condition =1032 for the InstructorID field, then Access includes any record where instructor 1032 teaches, whether or not other teachers are also assigned to the class.

I f you're m at ching t ext , t hen you need t o include quot at ion m arks around your value. Ot herwise, Access wonders where t he t ext st art s and st ops. ="Harrington Red"

I nst ead of using an exact m at ch, you can use a range. Add t his filt er expression t o t he OrderTot al field t o find all t he orders wort h bet ween $10 and $50: 10

This condit ion's act ually t wo condit ions ( less t han 50 and great er t han 10) , which are yoked t oget her by t he powerful And keyword ( Sect ion 4.3.2.4) . Alt ernat ively, you can use t he Or keyword if you want t o see result s t hat m eet any one of t he condit ions you've included ( Sect ion 4.3.2.4) . I n Chapt er 7, you'll consider som e m ore powerful t ools for craft ing filt er expressions.

WORD TO THE WISE Don't Get Confused by Lookups

file:///C|/html/0596527608/access2007tm-CHP-6-SECT-2.html (9 of 21) [1/7/2007 7:08:39 AM]

Section 6.2. Creating Queries

As you know, lookups change t he way values appear on t he dat asheet . I f you add a lookup on t he Cust om erI D field in t he Orders t able, t hen you don't see a crypt ic num ber like 1032. I nst ead, you see som e descript ive inform at ion, like t he nam e Hancock, John. However, when you writ e your filt er expression, you need t o rem em ber what inform at ion's act ually st ored in t he field. So t he Cust om erI D filt er expression = 1032 works fine, but = Hancock, John doesn't , because t he nam e inform at ion's act ually st ored separat ely. ( I t 's in t he Cust om ers t able, not t he Orders t able.) Som et im es, you really do want t o creat e a filt er expression t hat uses linked inform at ion. You m ay want t o find records in t he Orders t able using a cust om er nam e inst ead of a cust om er I D, because you don't have t he I D value handy. I n t his sit uat ion, you have t wo choices: ● ●

You can look up t he I D value you need in t he Cust om ers t able before you st art . Then, you can use t hat value when you build your query for t he Orders t able. You can use a j oin query t o get t he nam e inform at ion from t he Cust om ers t able, and display it along- side t he rest of your order det ails. You'll learn how t o perform t his t rick in Sect ion 6.3.

Dat e expressions are part icularly useful. Just rem em ber t o bracket any hardcoded dat es wit h t he # charact er ( Sect ion 4.3.2.2) . I f you add t his filt er condit ion t o t he Dat ePlaced field, t hen it finds all t he orders t hat were placed in 2007: #12/31/2006#

This expression works by requiring t hat dat es are earlier t han January 1, 2008, but lat er t han Decem ber 31, 2006.

Tip: With a little more work, you could craft a filter expression that gets the orders from the first three months of the current year, no matter what year it is. This trick requires the use of the functions Access provides for dates. You'll see how to use them in Section 4.1.3.

6.2.1.2. Getting the top records When you run an ordinary query, you see all t he result s t hat m at ch your filt er condit ions. I f t hat 's m ore t han you bargained for, you can use filt er expressions t o cut down t he list . However, in som e cases, filt ers are a bit m ore work t han t hey should be. I m agine a sit uat ion where you want t o see t he t op 10 m ost expensive product s. Using a filt er condit ion, you can easily get t he product s t hat have prices above a cert ain t hreshold. Using sort ing, you can arrange t he result s so t he m ost expensive it em s t urn up at t he t op. However, you can't as easily t ell Access t o get j ust 10 records and t hen st op.

UP TO SPEED Filter Syntax I f filt ers seem uncannily fam iliar, t here's a reason. Filt ers have exact ly t he sam e synt ax as t he validat ion rules you used t o prot ect a t able from bad dat a ( Sect ion 4.3) . The only difference is t he way Access int erpret s t he condit ion. A validat ion rule like < 50 And > 10 t ells Access a value shouldn't be allowed unless it falls in t he desired range ( 10 t o 50) . But if you pop t he sam e rule int o a filt er condit ion, it t ells Access you aren't int erest ed in seeing t he record unless it fit s t he range. Thanks t o t his sim ilarit y, you can use all t he validat ion rules you saw in Sect ion 4.3.1 t o 137 as filt er condit ions. I n Chapt er 7, you'll learn how t o beef up filt er condit ions wit h Access funct ions.

I n t his sit uat ion, t he query Design view has a short cut t hat can help you out . Here's how it works: 1. Ope n you r qu e r y in D e sign vie w ( or cr e a t e a n e w qu e r y a n d a dd t h e fie lds you w a n t t o u se ) . file:///C|/html/0596527608/access2007tm-CHP-6-SECT-2.html (10 of 21) [1/7/2007 7:08:39 AM]

Section 6.2. Creating Queries

This exam ple uses t he Product s t able, and includes t he Product Nam e and Price fields. 2. Sor t you r t a ble so t h a t t h e r e cor ds you 'r e m ost in t e r e st e d in a r e a t t h e t op. I f you want t o find t he m ost expensive product s, t hen add a descending sort ( Sect ion 3.2) on t he Price field. 3. I n t h e Qu e r y Tools | D e sign

Qu e r y Se t u p

Re t u r n box , ch oose a diffe r e n t opt ion ( Figu r e 6 - 8 ) .

The st andard opt ion's All, which get s all t he m at ching records. However, you can choose 5, 25, or 100 t o get t he t op 5, 25, or 100 m at ching records, respect ively. Or, you can use a percent age value like 25 percent t o get t he t op quart er of m at ching records.

Note: In order for the Query Tools | Design Query Setup Return box to work, you must choose the right sort order. To understand why, you need to know a little more about how this feature works. If you tell Access to get just five records, then it actually performs the normal query, gets all the records, and arranges them according to your sort order. It then throws everything away except for the first five records in the list. If you've sorted your list so that the most expensive products are first (as in this example), you're left with the top five budget-busting products in your results. 4. Ru n you r qu e r y t o se e t h e r e su lt s ( Figu r e 6 - 9 ) .

Figu r e 6 - 8 . If you don't see the number you want in the list, just type it into the Return box on your own. There's no reason you can't grab the top 27 most expensive products.

file:///C|/html/0596527608/access2007tm-CHP-6-SECT-2.html (11 of 21) [1/7/2007 7:08:39 AM]

Section 6.2. Creating Queries

Figu r e 6-9. Here are the top five most expensive products.

6.2.2. Creating a Simple Query with the Query Wizard Design view's usually t he best place t o st art const ruct ing queries, but it 's not t he only opt ion. You can use t he Query wizard t o give you an init ial boost , and t hen refine your query in Design view. The Query wizard works by asking you a series of quest ions, and t hen creat ing t he query t hat fit s t he bill. Unlike m any of t he ot her wizards in Access and ot her Office applicat ions, t he Query wizard's relat ively feeble. I t 's a good st art ing point for query newbies, but not an end- t o- end perform er. Here's how you can put t he Query wizard t o work:

POWER USERS' CLINIC How Indexes Speed Up Searches I n Chapt er 2 ( Sect ion 4.1.3.1) , you learned about t able indexes, and how t o creat e t hem . ( An index is a list of all t he values in one field, in sort ed order. Next t o each value is a point er t o t he full record in t he t able.) I ndexes have t wo purposes. First , t hey can prevent duplicat e values ( Sect ion 4.1.3) . Second, t hey can help Access perform searches m ore speedily. Access can oft en hunt t hrough an index fast er t han it can scan an ent ire t able. Not only is t he index physically sm aller ( because it has t he value from only one field) , but it 's also sort ed, so Access can skip t o t he right place m ore quickly. To underst and t he difference, suppose you ask Access t o find t he " Bavarian Tart " record in t he Product s t able. I f you have an index for t he Product Nam e field, t hen Access can scan t he B sect ion unt il it finds t he right ent ry, and t hen j um p t o t he full det ails. I f you don't have an index, Access is forced t o search t he ent ire t able, record by record. The t able isn't in any sort ed order, so t here's no t elling how long it 'll t ake before Access st um bles across t he right record. At first glance, indexes sound t rem endously useful, and you'll be t em pt ed t o creat e t hem for all your t able fields. But indexes have drawbacks. The m ore indexes you add, t he m ore work Access needs t o do when insert ing and updat ing records. Each index also t akes up som e space. I n fact , indexes are a wast e of resources unless you know t hey'll im prove search perform ance. Here are som e reasons t o consider using an index t o im prove perform ance: ●



You r da t a ba se is h u ge . I f you have only a few hundred records, Access can alm ost always scan t he ent ire t able fast er t han it can use an index, due t o t he way t hat hard drives work. Even if you have t housands of records, Access can oft en load t he whole shebang int o your com put er's m em ory, so it doesn't have t o wait for t he hard drive t o respond, and all your queries are blist eringly fast . You r se a r ch is slow . There's no reason t o enhance a query if it 's already working at t op speed. Most Access fans can search giant dat abases day aft er day wit hout ever having t o wait .

file:///C|/html/0596527608/access2007tm-CHP-6-SECT-2.html (12 of 21) [1/7/2007 7:08:39 AM]

Section 6.2. Creating Queries ●



Th e fie ld you w a n t t o in de x is u se d in a se a r ch . Don't index a field unless you're using it in a filt er condit ion. I f you oft en search for a single, specific cust om er by looking up t he last nam e, t hen consider adding an index on t he Last Nam e field. Th e fie ld you w a n t t o in de x is u n iqu e ( or close t o it ) . I t m akes sense t o add an index t o t he Product Nam e field in t he Product s t able, because very few product s ( if any) share t he sam e nam e. On t he ot her hand, it doesn't m ake sense t o index t he Cit y field in t he Cust om ers t able, because m any cust om ers live in t he sam e cit y. As a result , an index on t he Cit y field would be inefficient , and Access probably wouldn't bot her t o use it at all.

1. Ch oose Cr e a t e

Ot h e r

Qu e r y W iza r d.

Access gives you a choice of several different wizards ( Figure 6- 10) . 2. Ch oose a qu e r y t ype . Th e Sim ple Qu e r y w iza r d's t h e be st st a r t in g poin t for n ow The Query wizard includes a few com m on kinds of queries. Wit h t he except ion of t he crosst ab query, t here's not hing really unique about any of t hese choices. You'll learn t o creat e t hem all using Design view: ❍

Sim ple Qu e r y W iza r d get s you st art ed wit h an ordinary query, which displays a subset of dat a from a t able. This query's t he kind you creat ed in t he previous sect ion.

Figu r e 6-10. In the first step of the Query wizard, you choose from a small set of basic query types.







Cr osst a b Qu e r y W iza r d generat es a crosst ab query, which let s you sum m arize large am ount s of dat a using different calculat ions. You'll build one of your own in Sect ion 9.1. Fin d D u plica t e s Qu e r y W iza r d is sim ilar t o t he Sim ple Query wizard, except it adds a filt er expression t hat shows only records t hat share duplicat ed values. I f you forgot t o set a prim ary key or creat e a unique index for your t able ( Sect ion 4.1.3) , t hen t his can help you clean up t he m ess. Fin d Un m a t ch e d Qu e r y W iza r d is sim ilar t o t he Sim ple Query wizard, except it adds a filt er expression t hat finds unlinked records in relat ed t ables. You could use t his t o find an order t hat isn't associat ed wit h any part icular cust om er. You'll learn how t his works in Sect ion 6.3.2.1.

3.

file:///C|/html/0596527608/access2007tm-CHP-6-SECT-2.html (13 of 21) [1/7/2007 7:08:39 AM]

Section 6.2. Creating Queries

Click OK. The first st ep of t he Query wizard appears. 4. I n t h e Ta ble s/ Qu e r ie s box , ch oose t h e t a ble t h a t h a s t h e da t a you w a n t . Th e n , a dd t h e fie lds you w a n t t o se e in t h e qu e r y r e su lt s, a s sh ow n in Figu r e 6 - 1 1 . For t he best cont rol, add t he fields one at a t im e. Add t hem in t he order you want t hem t o appear in t he query result s, from left t o right . You can add fields from m ore t han one t able. To do so, st art by choosing one of t he t ables, add t he fields you want , and t hen choose t he second t able and repeat t he process. This process really m akes sense only if t he t ables are relat ed. You'll learn m ore in Sect ion 6.3. 5. Click N e x t . I f your query includes a num eric field, t he Query wizard gives you t he choice of creat ing a sum m ary query t hat arranges rows int o groups, and calculat es inform at ion like t ot als and averages. You'll learn about sum m ary queries in Chapt er 7 ( Sect ion 7.3) . For now, if you get t his choice, pick Det ail and t hen click Next .

Figu r e 6-11. To add a field, select it in the Available Fields list, and then click the > arrow button (or just doubleclick it). You can add all fields at once by clicking the >> arrow button, and you can remove

file:///C|/html/0596527608/access2007tm-CHP-6-SECT-2.html (14 of 21) [1/7/2007 7:08:39 AM]

Section 6.2. Creating Queries

fields by selecting them in the Selected Fields list and then clicking 50)) ORDER BY Products.Price;

Here's a breakdown of t he first t wo lines:

file:///C|/html/0596527608/access2007tm-CHP-6-SECT-2.html (17 of 21) [1/7/2007 7:08:39 AM]

Section 6.2. Creating Queries





Lin e 1 st art s wit h t he word SELECT, which indicat es it 's a query t hat select s records ( like all t he queries you've seen in t his chapt er) . Aft er t he word SELECT is a com m a- separat ed list of fields t hat you want t o see. Each field's writ t en out in t he long form at TableNam e.FieldNam e, j ust in case you decide t o creat e a query t hat uses m ore t han one t able. Lin e 2 st art s wit h t he word FROM, which indicat es t he t able ( or t ables) t hat you're searching. I n t his case, t he Product s t able has t he records you need.

These t wo lines represent a com plet e funct ioning query. However, you'll oft en have m ore lines t hat apply filt ering set t ings and sort ing: ●

Lin e 3 st art s wit h t he word WHERE, which indicat es t he st art of your filt er condit ions. I n t his case, t here's only onea requirem ent t hat t he product price be over $50. I f you've defined m ore t han one crit eria on different fields, t hen you see t hem all here, j oined t oget her using t he AND operat or.

Note: Access goes a little crazy with parentheses in the filter conditions. You could rewrite WHERE (((Products.Price)>50)) more simply as WHERE Products.Price>50. Access uses the parentheses because they make it easier to sort out complex queries with multiple conditions. ●

Lin e 4 st art s wit h t he words ORDER BY, which defines t he sort ing order. I n t his case, records are sort ed from lowest t o highest using t he value in t he Price field. I n t he case of a descending sort , you'd see t he abbreviat ion DESC aft er t he field nam e. I f you're sort ing on m ult iple fields, t hen you see a com m a- separat ed field list . The com m and ends wit h a final sem icolon ( ; ) . Access doesn't need t his det ail, but it 's a SQL world convent ion.

The lesson here's t hat every query you build is shaped out of a few com m on ingredient s, represent ed by t he SELECT, FROM, WHERE, and ORDER BY sect ions. Access keeps all t he different views of a query synchronized. I f you m ake a change t o t he SQL t ext , and t hen swit ch back t o t he Design view, t hen you see t he newly m odified version of t he query ( unless you've m ade a m ist ake, in which case Access delivers an error m essage) . To t ry t his charact erist ic out , you can m odify t he SQL t ext so t hat it select s an ext ra colum n and sort s on t wo fields, so t hat product s wit h t he sam e price are arranged alphabet ically ( t he new part s are highlight ed in bold) : SELECT Products.ID, Products.ProductName, Products.Price, Products.Description FROM Products WHERE (((Products.Price)>100)) ORDER BY Products.Price, Products.ProductName;

Right - click t he t ab t it le, and t hen choose Design View t o see how t hese changes appear in t he query designer.

6.2.3.2. Creating a union query The query designer doesn't recognize som e rare SQL t ricks. You can use t hem only by edit ing t he SQL com m and in SQL view, and once you've m ade t he change, you can't look at your query in Design view any longer ( unless you rem ove t he unsupport ed change lat er on) . A union query is one exam ple of a query t hat 's occasionally useful but not support ed by t he query designer. A union query m erges t he result s from m ore t han one t able, and t hen present s t hem in a single dat asheet . Essent ially, a union query's com posed of t wo ( or m ore) separat e select queries. The t rick's t hat t he result s from each select query m ust have t he sam e st ruct ure. So you need t o ret rieve sim ilar colum ns from each t able, in t he sam e order. Assum ing you can m eet t his st andard, all you need t o do is add t he word UNI ON bet ween t he t wo queries. Here's a union query t hat present s a list of nam es drawn from t wo t ables Cust om ers and Em ployees: SELECT Customers.FirstName, Customers.LastName FROM Customers UNION SELECT Employees.FirstName, Employees.LastName

file:///C|/html/0596527608/access2007tm-CHP-6-SECT-2.html (18 of 21) [1/7/2007 7:08:39 AM]

Section 6.2. Creating Queries

FROM Employees

This query works even t hough t he st ruct ure of t he Cust om ers and Em ployees t ables is different . The im port ant part 's t hat t he query result s from bot h t ablesin t his case, t he First Nam e and Last Nam e fieldsm at ch up.

Note: You can create a union query even if the column names differif the columns in the Employees table were F_Name and L_Name, the query would still work. Access simply uses the column names from the first query when it displays the results in the datasheet.

I n t his exam ple, when you view t he query result s, you see a list of cust om er nam es followed by a list of em ployee nam es, alt hough you can't necessarily t ell where one t able leaves off and t he ot her begins. You also can't edit any of t he dat aunion queries are st rict ly for reviewing inform at ion, not changing it . Access doesn't let you edit union queries in t he query designer. I f you right - click t he t ab t it le, and t hen choose Design View, you wind up in SQL view inst ead. Access put s union queries in t he Unrelat ed Obj ect s sect ion of t he navigat ion pane, and uses a different icon for t hem t han for norm al queries ( Figure 6- 14) .

Note: If there are any duplicates in the results, union queries show just one copy. You can change this behavior by replacing UNION with UNION ALL. In the previous example, this step causes a person who's both an employee and a customer to show up twice in the combined results.

Figu r e 6 - 1 4 . Union queries appear in the navigation pane with a different icon. The two joined circles indicate that more than one set of results are being shown together.

Union queries are a good way t o link t oget her sim ilar t ables t hat have been separat ed for reasons of perform ance, securit y, or dist ribut ion. ( See Sect ion 18.2 for t he different reasons you m ight split a single set of dat a int o different t ables.) Union queries aren't a good way t o work wit h parent - child relat ionships. For t his t ask you need j oin queries, which are described in t he next sect ion.

WORD TO THE WISE Think Twice Before Redesigning Your Tables

file:///C|/html/0596527608/access2007tm-CHP-6-SECT-2.html (19 of 21) [1/7/2007 7:08:39 AM]

Section 6.2. Creating Queries

Access is surprisingly savvy at keeping t rack of which queries use part icular t ables. This t rait becom es im port ant when you crack open a t able in design m ode t o change som et hing about it s st ruct ure. Suppose you renam e t he Orders t able t o Sales, and t he Dat ePlaced field t o OrderDat e. The next t im e you run t he First Quart erOrders_2007 query ( Figure 6- 6) , you find t hat rem arkablyit st ill works. Access knows t hat t he First Quart erOrders_2007 query depends on t he Orders t able. When you change t he nam es in t he t able, it adj ust s t he query accordingly. Access includes a nift y t ool t hat can look at any dat abase obj ect you choose, and t ell you what ot her dat abase obj ect s depend on it . You can use t his t ool t o figure out what queries, form s, and report s use t he Orders t able before you change it . To use t his feat ure, follow t hese st eps: 1. Show/ Hide Obj ect Dependencies. The Obj ect Dependencies box appears on t he Choose Dat abase Tools Access window's right side. ( Choose t he sam e com m and again when you want t o hide it .) 2. I n t he navigat ion pane, select t he dat abase obj ect t hat you want t o exam ine. 3. I n t he Obj ect Dependencies box, choose eit her " Obj ect s t hat depend on m e" ( t o see ot her obj ect s t hat use t his obj ect ) or " Obj ect s t hat I depend on" ( t o see all t he obj ect s t his obj ect uses) . 4. At t he t op of t he Obj ect Dependencies box, click t he Refresh link. The Obj ect Dependencies box list s all t he appropriat e obj ect s, divided int o cat egories by t ype ( Figure 6- 15) . Access can't spot all dependencies, like when you need t o delve int o t he SQL view t o creat e a query t hat you can't build in Design view. I f you creat e a union query ( as in t he previous exam ple) , t hen Access isn't sm art enough t o figure out what t ables your query depends on. I f you redesign t hose t ables, t hen you'll get an error t he next t im e you run your query, saying t hat Access can't find t he right field or t able. ( To fix t he error, you need t o open your query in SQL view again, and change t he field and t able nam es t o t heir new values.)

Figu r e 6 - 1 5 . Here, the Object Dependencies box analyzes the Products table. It shows three tables that link to Products, and four

file:///C|/html/0596527608/access2007tm-CHP-6-SECT-2.html (20 of 21) [1/7/2007 7:08:39 AM]

Section 6.2. Creating Queries

queries that use the Products table. You can dig deeper into any object by clicking the plus (+) box next to its name. (Click the + next to TopProducts to check if any other database objects use that query.) The Ignored Objects section's at the bottom of the list. The CustomersAndEmployees union query shows up here, and it tells you that Access has no idea what it depends on.

file:///C|/html/0596527608/access2007tm-CHP-6-SECT-2.html (21 of 21) [1/7/2007 7:08:39 AM]

Section 6.3. Queries and Related Tables

6.3. Queries and Related Tables I n Chapt er 5, you learned how t o split dat a down int o fundam ent al pieces and st ore it in dist inct , well- organized t ables. This sort of design's only problem 's t hat it 's m ore difficult t o get t he full pict ure when you have relat ed dat a st ored in separat e places. Fort unat ely, Access has t he perfect solut ionyou can bring t he t ables back t oget her for display using a j oin. A j oin's a query operat ion t hat pulls colum ns from t wo t ables and fuses t hem t oget her in one grid of result s. You use j oins t o am plify child t ables by adding inform at ion from t he parent t able. Here are som e exam ples: ● ● ●

I n t he bobblehead dat abase, you can show a list of bobblehead dolls ( drawn from t he child t able Dolls) along wit h t he m anufact urer inform at ion for each doll ( from t he parent t able Manufact urers) . I n t he Cacophoné m usic school dat abase, you can get a list of available classes, wit h inst ruct or inform at ion. I n t he Bout ique Fudge dat abase, you can get a list of orders, com plet e wit h t he det ails for t he cust om er who placed t he order.

Note: You've already learned how to create lookup tables to show just a bit of information from a linked table. A lookup can show the name of a product category in place of the ID number in the ProductID field. However, a join query's far more powerful. It can grab oodles of information from the linked tablefar more than you could fit in a single field.

Figure 6- 16 shows how a t able j oin works.

Figu r e 6 1 6 . On its own, the Classes table tells you about each class, but it gives each class, but it gives you only the ID of the assigned instructor. But join this table to the Teachers table, and you can get any other details from the linked teacher recordincluding the first and last name. You'll see how to build this example in Section 6.3.3.

file:///C|/html/0596527608/access2007tm-CHP-6-SECT-3.html (1 of 11) [1/7/2007 7:08:49 AM]

Section 6.3. Queries and Related Tables

6.3.1. Joining Tables in a Query Access m akes it rem arkably easy t o j oin t wo t ables. The first st ep's adding bot h t ables t o your query, using t he Show Table dialog box. I f you're creat ing a new query in Design view, t hen t he Show Table dialog appears right away. I f you're working wit h a query you've already creat ed, t hen m ake sure you're in Design view, right - click t he window, and t hen choose Show Table. I f you've already defined a relat ionship bet ween t he t wo t ables ( using t he relat ion- ships window, as described in Sect ion 5.2.1, or by creat ing a lookup, as described in Sect ion 5.2.5) , t hen Access uses t hat relat ionship t o aut om at ically creat e a query j oin. You'll see a line on t he diagram t hat connect s t he appropriat e fields, as shown in Figure 6- 17. I f you haven't already defined a relat ionship bet ween t he t wo relat ed t ables, t hen you probably should, before you creat e your query ( see Chapt er 5 for full inst ruct ions) . But if for som e crypt ic reason you've decided not t o creat e t he relat ionship ( perhaps t he dat abase design was set in st one by anot her, less savvy Access designer) , t hen you can m anually define t he j oin in t he query window. To do so, j ust drag t he linked field in one t able t o t he m at ching field in t he ot her t able. You can also rem ove a j oin by right - clicking t he line bet ween t he t ables, and t hen choosing Delet e.

Figu r e 6-17. Access automatically joins the CustomerID field in the Orders table to the ID field in the Customers table, based on the relationship that's defined in the database.

Note: If you add two unrelated tables, then Access tries to help you out by guessing a relationship. If it spots a field with the same data type and the same name in both tables, then it adds a join on this field. This action often isn't what you wantfor example, many tables share a common ID field. Also, if you're following the database design rules from Section 2.5, then your linked fields have slightly different names in each table, like ID and CustomerID. If you run into a problem where Access assumes a relationship that doesn't exist, then just remove it before adding the join you really want.

file:///C|/html/0596527608/access2007tm-CHP-6-SECT-3.html (2 of 11) [1/7/2007 7:08:49 AM]

Section 6.3. Queries and Related Tables

UP TO SPEED Relationships vs. Joins I t 's im port ant t o underst and t he differences bet ween a relat ionship and a query j oin. ●



Re la t ion sh ip. A perm anent link bet ween t wo t ables, which is st ored in your dat abase. When creat ing a relat ionship in t he dat abase, you have t he opt ion of swit ching on referent ial int egrit y: a set of rules t hat prevent s inconsist ent dat a in relat ed t ables ( Sect ion 5.2.3) . Join . A query feat ure t hat let s you com bine relat ed dat a from t wo t ables int o one set of result s. The j oin doesn't affect how you ent er or edit t hat inform at ion in t he underlying t ables.

I f you have a relat ionship in place, t hen Access assum es you'll want t o use a j oin t o link t hose t ables t oget her in a query, which only m akes sense.

Once you have your t wo t ables in t he query design window and you've defined t he j oin, t hen you're ready t o choose t he fields you want . You can pick fields from bot h t ables. You can also add filt er condit ions and supply a sort order, as you would wit h any ot her query. Figure 6- 18 shows an exam ple of a query t hat uses a j oin, and Figure 6- 19 shows t hat sam e query in act ion.

Note: When you have two linked tables, it's easy to forget what you're showing. If you join the Orders and Customers tables, and then select fields from each, then what do you end up with: a list of classes or a list of instructors? Easy, you get a list of orders, complete with customer information. Queries with linked tables always act on the child table and bring in additional information from the parent.

Figu r e 6-18. This query shows information from the Orders and Customers tables. It doesn't matter whether the first field's from the Orders or Customers tableeither way,

file:///C|/html/0596527608/access2007tm-CHP-6-SECT-3.html (3 of 11) [1/7/2007 7:08:49 AM]

Section 6.3. Queries and Related Tables

you're creating a list of orders with added customer information. Notice how the Table box (under the Field box) shows which table each field comes from.

Figu r e 6-19. You can easily see at a glance who ordered what. The ID column's the order ID (although you could display the IDs from both the Customers and Orders tables). file:///C|/html/0596527608/access2007tm-CHP-6-SECT-3.html (4 of 11) [1/7/2007 7:08:49 AM]

Section 6.3. Queries and Related Tables

Note: When you perform a join, you see repeated information. If you join the Customers and Orders tables, you see the first and last name of a shopaholic customer appear next to several orders. However, this doesn't violate the database rule against duplicate data. Even though the customer details appear in more than one place in the query results, they're stored only once in the Customers table.

Rem em ber, when you link a parent and child t able wit h a j oin query, you're really perform ing a query t hat get s all t he records from t he child t able, and t hen adds ext ra inform at ion from t he parent t able. For exam ple, you can use a j oin query t o get a list of orders ( from t he child t able) and supplem ent each record wit h inform at ion about t he cust om er t hat m ade t he order. No m at t er how you creat e t he j oin, you won't ever get a list of cust om ers wit h order inform at ion t acked ont hat wouldn't m ake sense, because every cust om er can m ake m ult iple orders. Joins are one of t he m ost useful feat ures in any query writ er's t oolkit . They let you display one t able t hat has all t he inform at ion you need.

Note: When using more than one table, there's always a risk that two tables have a field with the same name. This possibility isn't a problem if you don't plan to show these fields in your query, but it can cause confusion if you do. One way to distinguish between the two fields is to rename one of them in the query datasheet. You'll learn how to perform this trick with a calculated field in Section 7.1.2.

UP TO SPEED Modifying Information Using a Join Query You need t o be careful when m odifying t he dat a in a query t hat uses a j oin. There's never a problem if you want t o m odify t he det ails from t he child t able. I n t he exam ple in Figure 6- 19, it 's easy enough t o change t he Dat ePlaced or St at usI D fields t o change t he order record. However, consider what happens if you change one of t he values in t he parent t able, like t he cust om er's first or last nam e. Obviously, t he sam e cust om er inform at ion m ay appear several t im es in t he query. ( For exam ple, t he query in Figure 6- 19 shows t wo orders by a cust om er nam ed Toby.) I f you m odify t he cust om er nam e in one place, t hen Access aut om at ically changes t he inform at ion in t he Cust om ers t able, and t hen refreshes t he ent ire query. So, if you change " Toby" t o " Tony" in Figure 6- 19, t hen Access refreshes t he second and t hird rows of t he dat asheet . A pot ent ial problem occurs if you want t o change t he link bet ween t he order record and t he cust om er record. You m ay want t o edit an order t hat 's assigned t o Toby so t hat t he dat abase says Lisa m ade t he order. However, you can't m ake t his change by edit ing t he First Nam e and Last Nam e fields in t he query. ( I f you do, you'll sim ply wind up changing Toby's record in t he Cust om ers t able.) I nst ead, you need t o change t he Cust om erI D field in t he Orders t able so t hat it point s t o t he right person. I n t he query shown in Figure 6- 19, t he Cust om erI D field isn't included, so t here's no way t o change t he link.

6.3.2. Outer Joins The queries you saw in t he previous exam ple use what dat abase nerds call an inner j oin. I nner j oins show only linked recordsin ot her words, records t hat appear in bot h t ables. I f you perform a query on t he Cust om ers and Orders t ables, t hen you don't see cust om ers t hat haven't placed an order. You also don't see orders t hat aren't linked t o any part icular cust om er ( t he Cust om erI D value's blank) or aren't linked t o a valid record ( t hey cont ain a Cust om erI D value t hat doesn't m at ch up t o any record in t he Cust om ers t able) . Out er j oins are m ore accom m odat ingt hese j oins include all t he sam e result s you'd see in an inner j oin, plus t he left over unlinked records from one of t he t wo t ables ( it 's your choice) . Obviously, t hese unlinked records show up in t he query result s wit h som e blank values, which correspond t o t he m issing inform at ion t hat t he ot her t able would supply. Suppose you perform an out er j oin bet ween t he Orders and Cust om ers t ables, and t hen configure it so t hat all t he order records are shown. Any orders t hat aren't linked t o a cust om er record appear at t he bot t om of t he list , and have blank values in all t he cust om er- relat ed fields ( like First Nam e and Last Nam e) :

file:///C|/html/0596527608/access2007tm-CHP-6-SECT-3.html (5 of 11) [1/7/2007 7:08:49 AM]

Section 6.3. Queries and Related Tables

Ta ble 6 - 1 . Fir st N a m e

La st N a m e

ID

D a t e Pla ce d

St a t u sI D

St anley

Lem

7

13- Jun- 07

Cancelled

Toby

Grayson

4

03- Nov- 06

Ret urned

Toby

Grayson

6

03- Nov- 06

Shipped

18

01- Jan- 08

I n Progress

19

01- Jan- 08

I n Progress

I n t his part icular exam ple, it doesn't m ake sense for orders t hat aren't linked t o a cust om er t o exist . ( I n fact , it probably indicat es an order t hat was ent ered incorrect ly.) However, if you suspect a problem , an out er j oin can help you t rack down t he problem .

Tip: You can prevent orphaned order records altogether by making CustomerID a required value (Section 4.1.1) and enforcing relational integrity (Section 5.2.3).

You can also perform an out er j oin bet ween t he Orders and Cust om ers t ables t hat shows all t he cust om er records. I n t his case, at t he end of t he query result s, you'll see every unlinked cust om er record, wit h t he corresponding order fields left blank:

Ta ble 6 - 2 . Fir st N a m e

La st N a m e

ID

D a t e Pla ce d

St a t u sI D

St anley

Lem

7

13- Jun- 07

Cancelled

Toby

Grayson

4

03- Nov- 06

Ret urned

Toby

Grayson

6

03- Nov- 06

Shipped

Ben

Sam at ara

Goosey

Mason

Tabasoum

Khan

I n t his case, t he out er j oin query picks up t hree st ragglers. So how do you add an out er j oin t o your query? Your st art wit h an inner j oin ( which Access usually adds aut om at ically; see Sect ion 6.3.1) , and t hen convert it t o an out er j oin. To do so, j ust right - click t he j oin line t hat links t he t wo t ables in t he design window, and t hen choose Join Propert ies ( or j ust double- click t he line) . The Join Propert ies dialog box ( Figure 620) appears, and let s you change t he t ype of j oin you're using.

file:///C|/html/0596527608/access2007tm-CHP-6-SECT-3.html (6 of 11) [1/7/2007 7:08:49 AM]

Section 6.3. Queries and Related Tables

Figu r e 6 - 2 0 . The first option, "Only include rows where the joined fields from both tables are equal", performs the standard inner join. The other two options let you create an outer join that incorporates all the unlinked rows from one of the two tables.

6.3.2.1. Finding unmatched records I nner j oins are by far t he m ost com m on j oins. However, out er j oins let you creat e at least one valuable t ype of query: a query t hat can t rack down unm at ched records. You've already seen how an out er j oin let s you see a list of all your orders, plus t he cust om ers t hat haven't m ade any orders. That com binat ion isn't t erribly useful. However, t he m arket ing depart m ent 's already salivat ing over t he second part of t his equat iont he list of people who haven't bought anyt hing. This inform at ion could help t hem t arget a first - t im e- buyer prom ot ion. To craft t his query, you st art wit h t he out er- j oin query t hat includes all t he cust om er records. Then, you sim ply add one m ore ingredient : a filt er condit ion t hat m at ches records t hat don't have an order I D. Technically, t hese are considered null ( em pt y) values. Here's t he filt er condit ion you need, which you m ust place in t he Crit eria box for t he I D field of t he Orders t able: Is Null

Now, when Access perform s t he query, it includes only t he cust om er records t hat aren't linked t o anyt hing in t he orders t able. Figure 6- 21 shows t he query in Design view.

Figu r e 6-21. This query combines an outer join with a filter condition that matches only unlinked customer records. Notice the Show checkbox

file:///C|/html/0596527608/access2007tm-CHP-6-SECT-3.html (7 of 11) [1/7/2007 7:08:49 AM]

Section 6.3. Queries and Related Tables

isn't checked. That's because the ID field's used for a filter condition, but there's no point in displaying it in the results datasheet.

6.3.3. Multiple Joins Just as you're get t ing com fort able wit h inner and out er j oins, Access has anot her feat ure t o t hrow your way. Many queries don't st op at a single j oin. I nst ead, t hey use t hree, four, or m ore t o bring m ult iple relat ed t ables int o t he m ix. Alt hough t his sounds com plicat ed at first , it really isn't . Mult iple j oins are sim ply ways of bringing m ore relat ed inform at ion int o your query. Each j oin works t he sam e in a m ult iple- j oin sit uat ion as it does when you use it on it s own. To use m ult iple j oins, j ust add all t he t ables you want from t he Show Table dialog box, m ake sure t he j oin lines appear, and t hen choose t he fields you want . Access is alm ost always int elligent enough t o figure out what you're t rying t o do. Figure 6- 22 shows an exam ple where a child t able has t wo parent s t hat can bot h cont ribut e som e ext ra inform at ion. Som et im es, t he inform at ion you want 's m ore t han one t able away. Consider t he OrderDet ails t able Bout ique Fudge uses t o list each it em in a cust om er's order. On it s own, t he OrderDet ails doesn't provide a link t o t he cust om er who ordered t he it em , but it does provide a link t o t he relat ed order record. ( See Sect ion 5.4.2.2 for a discussion of t his design.) I f you want t o get t he inform at ion about who ordered each it em , you need t o add t he OrderDet ails, Orders, and Cust om ers t able t o your query, as shown in Figure 6- 23.

Figu r e 6 2 2 . In this example, a list of products is amplified with product category

file:///C|/html/0596527608/access2007tm-CHP-6-SECT-3.html (8 of 11) [1/7/2007 7:08:49 AM]

Section 6.3. Queries and Related Tables

information and supplier information. The Products table's a child of both the ProductCategories and Suppliers tables, so this query uses both tables effortlessly.

Figu r e 6 - 2 3 . If you want to find out who ordered each item, then you need to find the linked Orders table, and then continue to the linked Customers table. Even if you don't want to show any data from

file:///C|/html/0596527608/access2007tm-CHP-6-SECT-3.html (9 of 11) [1/7/2007 7:08:49 AM]

Section 6.3. Queries and Related Tables

the Orders table, you still need to follow this twostep process. The top figure shows the query that does this, and the bottom figure shows the result you'll get when you run the query.

Mult iple j oins are also t he t icket if you have a m any- t o- m any relat ionship wit h a j unct ion t able ( Sect ion 5.3.2.1) , like t he one bet ween t eachers and classes. As you'll rem em ber from Chapt er 5 ( Sect ion 5.4.1) , t he Cacophoné St udios m usic school uses an int erm ediary t able t o t rack t eacher class assignm ent . I f you want t o get a list of classes, com plet e wit h inst ruct or nam es, t hen you need t o creat e a query wit h t hree t ables: Classes, Teachers, and Teachers_Classes ( see Figure 6- 24) .

Figu r e 6-24. Here's how you define a list of classes that includes

file:///C|/html/0596527608/access2007tm-CHP-6-SECT-3.html (10 of 11) [1/7/2007 7:08:49 AM]

Section 6.3. Queries and Related Tables

the name of the assigned teacher next to each class. The top query shows the design you need, and the bottom figure shows the result.

file:///C|/html/0596527608/access2007tm-CHP-6-SECT-3.html (11 of 11) [1/7/2007 7:08:49 AM]

Chapter 7. Essential Query Tricks

7. Essential Query Tricks Every Access expert st ocks his or her dat abase wit h a few ( or a few dozen) useful queries t hat sim plify dayt o- day t asks. I n t he previous chapt er, you learned how t o creat e queries t hat chew t hrough avalanches of inform at ion and present exact ly what you need t o see. But as Access m ast ers know, t here's m uch m ore power lurking j ust beneat h t he surface of t he query design window. I n t his chapt er, you'll delve int o som e query m agic t hat 's sure t o im press your boss, co- workers, and rom ant ic part ners. You'll learn how t o carry out calculat ions in a query and perform sum m aries t hat boil colum ns of num bers down t o neat t ot als. You'll also learn how t o writ e super- int elligent filt er expressions and how t o creat e dynam ic queries t hat ask for inform at ion every t im e you run t hem . These t echniques are indispensable t o t he repert oire of any t rue query fanat ic.

file:///C|/html/0596527608/access2007tm-CHP-7.html [1/7/2007 7:08:50 AM]

Section 7.1. Calculated Fields

7.1. Calculated Fields When you st art ed designing t ables, you learned t hat it 's a dat abase crim e t o add inform at ion t hat 's based on t he dat a in anot her field or anot her t able. An exam ple of t his m ist ake is creat ing a Product s t able t hat has bot h a Price and a PriceWit hTax field. The fact t hat t he PriceWit hTax field is calculat ed based on t he Price field is a problem . St oring bot h is a redundant wast e of space. Even worse, if t he t ax rat e changes, t hen you're left wit h a lot of records t o updat e and t he pot ent ial for inconsist ent inform at ion ( like a wit h- t ax price t hat 's lower t han a no- t ax price) . Even t hough you know not t o creat e fields like PriceWit hTax, som et im es you will want t o see calculat ed inform at ion in Access. Before Bout ique Fudge print s a product list for one of it s least - loved ret ailers, it likes t o apply a 10 percent price m arkup. To do t his, it needs a way t o adj ust t he price inform at ion before print ing t he dat a. I f t he ret ailer spot s t he lower price wit hout t he m arkup, t hey're sure t o dem and it . Queries provide t he perfect solut ion for t hese kinds of problem s, because t hey include an all- purpose way t o m at hem at ically m anipulat e inform at ion. The t rick's t o add a calculat ed field: a field t hat 's defined in your query, but doesn't act ually exist in t he t able. I nst ead, Access calculat es t he value of a calculat ed field based on one or m ore ot her fields in your t able. The values in t he calculat ed field are never st ored anywhereinst ead, Access generat es t hem each t im e you run t he query.

7.1.1. Defining a Calculated Field To creat e a calculat ed field, you need t o supply t wo det ails: a nam e for t he field, and an expression t hat t ells Access what calculat ion it m ust perform . Calculat ed fields are defined using t his t wo- part form : CalculatedFieldName: Expression

For exam ple, here's how you can define t he PriceWit hTax calculat ed field: PriceWithTax: [Price] * 1.10

Essent ially, t his expression t ells Access t o t ake t he value from t he Price field, and t hen m ult iply it by 1.10 ( which is equivalent t o raising t he price by 10 percent ) . Access repeat s t his calculat ion for each record in t he query result s. For t his expression t o work, t he Price field m ust exist in t he t able. However, you don't need t o show t he Price field separat ely in t he query result s. You can also refer t o t he Price field using it s full nam e, which is m ade up of t he t able nam e, followed by a period, followed by t he field nam e, as shown here: PriceWithTax: [Products].[Price] * 1.10

This synt ax is som et im es necessary if your query involves m ore t han one t able ( using a query j oin, as described in Sect ion 6.3) , and t he sam e field appears in bot h t ables. I n t his sit uat ion, you m ust use t he full nam e t o avoid am biguit y. ( I f you don't , Access gives you an error m essage when you t ry t o run t he query.)

Note: Old-time Access users sometimes replace the period with an exclamation mark (as in [Products]![Price], which is equivalent.

To add t he PriceWit hTax calculat ed field t o a query, you need t o use Design view. First , find t he colum n where you want

file:///C|/html/0596527608/access2007tm-CHP-7-SECT-1.html (1 of 8) [1/7/2007 7:08:57 AM]

Section 7.1. Calculated Fields

t o insert your field. ( Usually, you'll j ust t ack it ont o t he end in t he first blank colum n, alt hough you can drag t he ot her fields around t o m ake space.) Next , t ype t he full definit ion for t he field int o t he Field box ( see Figure 7- 1) .

Figu r e 7 1 . This query shows two fields straight from the database (ID and Name), and adds the calculated PriceWithTax field. The ordinary Price field, which Access uses to calculate PriceWithTax, isn't shown at all.

Now you're ready t o run t he query. When you do, t he calculat ed inform at ion appears alongside your ot her colum ns ( Figure 7- 2) . I f you don't like t he fact t hat your calculat ed inform at ion appears in a slight ly m essier form at wit h m ore decim al places and no currency sym bolyou can fix it up using t he rounding ( Sect ion 7.2.1.1) and form at t ing ( Sect ion 7.2.3) feat ures discussed lat er in t his chapt er.

Figu r e 7 - 2 . The query results now show a PriceWithTax field, with the result of the 10 file:///C|/html/0596527608/access2007tm-CHP-7-SECT-1.html (2 of 8) [1/7/2007 7:08:57 AM]

Section 7.1. Calculated Fields

percent markup. The neat part's that this calculated information's now available instantaneously, even though it isn't stored in the database. Try and beat that with a pocket calculator.

Calculat ed fields do have one lim it at ionsince t he inform at ion isn't st ored in your t able, you can't edit it . I f you want t o m ake a price change, you'll need t o edit t he underlying Price fieldt rying t o change PriceWit hTax would leave Access t horoughly confused.

Note: An expression works on a single record at a time. If you want to combine the information in separate records to calculate totals and averages, then you need to use the grouping features described in Section 7.3.

UP TO SPEED Query Synchronization

file:///C|/html/0596527608/access2007tm-CHP-7-SECT-1.html (3 of 8) [1/7/2007 7:08:57 AM]

Section 7.1. Calculated Fields

Here's an int erest ing t rick t o t ry. Run t he Product sWit hTax query and leave it open, displaying it s result s. Now, open t he Product s t able t hat has t he act ual dat a, and t hen change t he price of any product . Swit ch back t o t he Product sWit hTax query. Has t he PriceWit hTax value changed? I f you can't st and t he suspense, fear not t he PriceWit hTax is aut om at ically refreshed t o reflect t he new price. Access aut om at ically keeps query views synchronized wit h t he live dat a in your t able. When you change a record, Access not icesand it inst ant ly refreshes t he query window. I t 's wort h not ing a few except ions t o t his rule: ● ●

● ●

Access doesn't not ice if you insert a new record aft er you launch a queryt o get t hat t o appear in your query result s, you need t o refresh t he result s. I f you change a record so it no longer appears in your query, it doesn't aut om at ically disappear from view. I f you have a query showing all product s over $100, and you cut t he price of one down t o $50, t hen it st ill appears in your query result list ( wit h t he new price) unt il you refresh t he result s. Sim ilarly, if you change a record t hat current ly appears in your query so it no longer fit s one of your filt er crit eria, it doesn't disappear from view unt il you rerun t he query. I f m ult iple people are edit ing t he dat abase on different com put ers ( as described in Chapt er 18) , you don't see ot her people's changes right away.

To get t he lat est result s, you can refresh individual records or t he ent ire query. To refresh a single record, Records Refresh Refresh Record. To rerun t he query and refresh everyt hing, choose Hom e Records Refresh Refresh All. This act ion also shows any new records and choose Hom e hides any t hat have been changed so t hat t hey no longer sat isfy your filt er condit ions.

Before going any furt her, it 's wort h reviewing t he rules of calculat ed fields. Here are som e point ers: ●





Alw a ys ch oose a u n iqu e n a m e . An expression like Price: [ Price] * 1.10 creat es a circular reference, because t he nam e of t he field you're using is t he sam e as t he nam e of t he field you're t rying t o creat e. Access doesn't allow t his sleight of hand. Bu ild e x pr e ssion s ou t of fie lds, n u m be r s, a n d m a t h ope r a t ion s. The m ost com m on calculat ed fields t ake one or m ore exist ing fields or hard- coded num bers and com bine t hem using fam iliar m at h sym bols like addit ion ( + ) , subt ract ion ( - ) , m ult iplicat ion ( * ) , or division ( / ) . Ex pe ct t o se e squ a r e br a ck e t s. The expression PriceWit hTax: [ Price] * 1.10 is equivalent t o PriceWit hTax: Price * 1.10 ( t he only difference is t he square bracket s around t he field nam e Price) . Technically, you need t he bracket s only if your field nam e cont ains spaces or special charact ers. However, when you t ype in expressions t hat don't use bracket s in t he query Design view, t hen Access aut om at ically adds t hem , j ust t o be on t he safe side.

GEM IN THE ROUGH Renaming a Field in a Query

file:///C|/html/0596527608/access2007tm-CHP-7-SECT-1.html (4 of 8) [1/7/2007 7:08:57 AM]

Section 7.1. Calculated Fields

Tired of seeing long field nam es in your query result s? Based on what you've j ust learned about expressions, you can painlessly renam e a field in your query result s. All you need is a calculat ed field. The t rick's t o creat e a calculat ed field t hat m at ches one of t he exist ing fields ( using an expression) and supplies a new nam e. Technically, you aren't perform ing any calculat ion here, but it st ill works perfect ly well. Here's an exam ple of a calculat ed field t hat renam es Dat eCust om erPlacedPurchaseOrder t o Dat e: Date: DateCustomerPlacedPurchaseOrder

The new nam e ( in t his exam ple, Dat e) is known as an alias. When using t his t echnique, rem em ber not t o include t he original field ( in t his case, Dat eCust om erPlacedPurchaseOrder) in your query. The calculat ed field ( Dat e) already shows t he inform at ion you want .

7.1.2. Simple Math with Numeric Fields Many calculat ed fields rely ent irely on ordinary high school m at h. Table 7- 1 gives a quick overview of your basic opt ions for com bining num bers.

Ta ble 7 - 1 . Ar it h m e t ic Ope r a t or s Ope r a t or

Nam e

Ex a m ple

Re su lt

+

Addit ion

1+ 1

2

-

Subt ract ion

1- 1

0

*

Mult iplicat ion

2* 2

4

^

Exponent iat ion

2^ 3

8

/

Division

5/ 2

2.5

\

I nt eger division ( ret urns t he lowest whole num ber and discards t he rem ainder)

5\ 2

2

Mod

Modulus ( ret urns t he rem ainder left aft er division)

5 Mod 2

1

You're free t o use as m any fields and operat ors as you need t o creat e your expression. Consider a Product s t able wit h a Quant it yI nSt ock field t hat records t he num ber of unit s in your warehouse. To det erm ine t he value you have on hand for a given product , you can writ e t his expression t hat uses t wo fields: ValueInStock: [UnitsInStock] * [Price]

Tip: When performing a mathematical operation with a field, you'll run into trouble if the field contains a blank value. To correct the problem, you need the Nz( ) function, which is described in Section 7.3.

file:///C|/html/0596527608/access2007tm-CHP-7-SECT-1.html (5 of 8) [1/7/2007 7:08:57 AM]

Section 7.1. Calculated Fields

7.1.2.1. Date fields You can also use t he addit ion and subt ract ion operat ors wit h dat e fields. ( You can use m ult iplicat ion, division, and everyt hing else, but it doesn't have any realist ic m eaning.) Using addit ion, you can add an ordinary num ber t o a dat e field. This num ber m oves t he dat e forward by t hat m any days. Here's an exam ple t hat adds t wo weeks of headroom t o a com pany deadline: ExtendedDeadline: [DueDate] + 14

I f you use t his calculat ion wit h t he dat e January 10, 2007, t he new dat e becom es January 24, 2007. Using subt ract ion, you can find t he num ber of days bet ween any t wo dat es. Here's how you calculat e how long it was bet ween t he t im e an order was placed and when it was shipped: ShippingLag: [ShipDate] - [OrderDate]

I f t he ship dat e occurred 12 days aft er t he order dat e, you'd see a value of 12.

Note: Date fields can include time information. In calculations, the time information's represented as the fractional part of the value. If you subtract two dates and wind up with the number 12.25, that represents 12 days and six hours (because six hours is 25 percent of a full day).

Rem em ber, if you want t o include lit eral dat es in your queries ( specific dat es you supply) , you need t o bracket t hem wit h t he # charact er and use Mont h/ Day/ Year form at . Here's an exam ple t hat uses t hat approach t o count t he num ber of days bet ween t he dat e st udent s were expect ed t o subm it an assignm ent ( March 20, 2007) and t he dat e t hey act ually did: LateDays: [DateSubmitted] - #03/20/07#

A posit ive value indicat es t hat t he value in Dat eSubm it t ed is larger ( m ore recent ) t han t he deadline dat ein ot her words, t he st udent was lat e. A value of 4 indicat es a st udent t hat 's four days off t he m ark, while 4 indicat es a st udent t hat handed t he work in four days ahead of schedule.

7.1.2.2. Order of operations I f you have a long st ring of calculat ions, Access follows t he st andard rules for order of operat ions: m at hem at ician- speak for deciding which calculat ion t o perform first when t here's m ore t han one calculat ion in an expression. So if you have a lengt hy expression, Access doesn't j ust carry on from left t o right . I nst ead, it evaluat es t he expression piece by piece in t his order: 1. Pa r e n t h e se s ( Acce ss a lw a ys pe r for m s a n y ca lcu la t ion s w it h in pa r e n t h e se s fir st ) 2. Pe r ce n t

file:///C|/html/0596527608/access2007tm-CHP-7-SECT-1.html (6 of 8) [1/7/2007 7:08:57 AM]

Section 7.1. Calculated Fields

3. Ex pon e n t s 4. D ivision a n d m u lt iplica t ion 5. Addit ion a n d su bt r a ct ion Suppose you want t o t ake t he Quant it yI nSt ock and t he Quant it yOnOrder fields int o considerat ion t o det erm ine t he value of all t he product you have available and on t he way. I f you're not aware of t he order of operat ion rules, t hen you m ight t ry t his expression: TotalValue: [UnitsInStock] + [UnitsOnOrder] * [Price]

The problem here is t hat Access m ult iplies Quant it yOnOrder and Price t oget her, and t hen adds it t o t he Quant it yI nSt ock. To correct t his oversight , you need parent heses like so: TotalValue: ([UnitsInStock] + [UnitsOnOrder]) * [Price]

Now t he Quant it yI nSt ock and Quant it yOnOrder fields are t ot aled t oget her, and t hen m ult iplied wit h t he Price t o get a grand t ot al.

Tip: Need some more space to write a really long expression? You can widen any column in the query designer to see more at once, but you'll still have trouble with complex calculations. Better to click in the Field box, and then press Shift+F2. This action pops open a dialog box named Zoom, which shows the full content in a large text box, wrapped over as many lines as necessary. When you've finished reviewing or editing your expression, click OK to close the Zoom box and keep any changes you've made, or Cancel to discard them.

7.1.3. Expressions with Text Alt hough calculat ed fields usually deal wit h num eric inform at ion, t hey don't always. You have genuinely useful ways t o m anipulat e t ext as well. I f you have t ext inform at ion, t hen you obviously can't use addit ion, subt ract ion, and ot her m at hem at ical operat ions. However, you can j oin t ext t oget her. You can, for inst ance, link several fields of address inform at ion t oget her and show t hem all in one field, conserving space ( and possibly m aking it easier t o export t he inform at ion t o anot her program ) . To j oin t ext , you use t he am persand ( &) operat or. For exam ple, here's how t o creat e a FullNam e field t hat draws inform at ion from t he First Nam e and Last Nam e fields: FullName: [FirstName] & [LastName]

This expression looks reasonable enough, but it 's act ually got a flaw. Since you haven't added any spaces, t he first and file:///C|/html/0596527608/access2007tm-CHP-7-SECT-1.html (7 of 8) [1/7/2007 7:08:57 AM]

Section 7.1. Calculated Fields

last nam e end up cram m ed t oget her, like t his: BenJenks. A bet t er approach is t o j oin t oget her t hree pieces of t ext : t he first nam e, a space, and t he last nam e. Here's t he revised expression: FullName: [FirstName] &" "& [LastName]

This produces values like Ben Jenks. You can also swap t he order and add a com m a, if you prefer t o have t he last nam e first ( like Jenks, Ben) for bet t er sort ing: FullName: [LastName] & ", " & [FirstName]

Note: Access has two types of text values: those you draw from other fields, and those you enter directly (or hard-code). When you hardcode a piece of text (such as the comma and space in the previous example), you need to wrap it in quotation marks so Access knows where it starts and stops.

You can even use t he am persand t o t ack t ext alongside num eric values. I f you want t he slight ly useless t ext " The price is" t o appear before each price value, use t his calculat ed field: Price: "The price is: " & [Price]

file:///C|/html/0596527608/access2007tm-CHP-7-SECT-1.html (8 of 8) [1/7/2007 7:08:57 AM]

Section 7.2. Query Functions

7.2. Query Functions By now, it m ay have crossed your m ind t hat you can m anipulat e num bers and t ext in even m ore am bit ious waysways t hat go beyond what t he basic operat ors let you do. You m ay want t o round off num bers or capit alize t ext . Access does include a feat ure t hat let s you t ake your expressions t o t he next level, and it 's called funct ions. A funct ion's a built - in algorit hm t hat t akes som e dat a t hat you supply, perform s a calculat ion, and t hen ret urns a result . The difference bet ween funct ions and t he m at hem at ical operat ors you've already seen is t he fact t hat funct ions can perform far m ore com plex operat ions. Access has a cat alog wit h dozens of different funct ions, m any of which perform feat s you wouldn't have a hope of accom plishing on your own. Funct ions com e in handy in all sort s of int erest ing places in Access. You can use t hem in: ● ● ●

Ca lcu la t e d fie lds. To add inform at ion t o your query result s. Filt e r con dit ion s. To det erm ine what records you see in a query. Visu a l Ba sic code . The all- purpose ext ensibilit y syst em for Access t hat you'll t ackle in Part Five.

As you explore t he world of funct ions, you'll find t hat m any are well suit ed t o calculat ed fields but not filt er condit ions. I n t he following sect ions, you'll see exact ly where each funct ion m akes m ost sense.

Note: Functions are a built-in part of the Access version of SQL (Section 6.2.3), which is the language it uses to perform data operations.

7.2.1. Using a Function Whet her you're using t he sim plest or t he m ost com plicat ed funct ion, t he synt ax t he rules for using a funct ion in an expressionis t he sam e. To use a funct ion, sim ply ent er t he funct ion nam e, followed by parent heses. Then, inside t he parent heses, put all t he inform at ion t he funct ion needs in order t o perform it s calculat ions ( if any) . For a good exam ple, consider t he handy Round( ) funct ion, which t akes a fract ional num ber and t hen t idies up any unwant ed decim al places. Round( ) is a good way t o clean up displayed values in a calculat ed field. You'll see why Round( ) is useful if you creat e an expression like t his, which discount s prices by five percent : SalePrice: [Price] * 0.95

Run a price like $43.97 t hrough t his expression, and you wind up wit h 41.7715 on t he ot her sidewhich doesn't look t hat great on a sales t ag. The Round( ) funct ion com es in handy here. Just feed it t he unrounded num ber and t he num ber of decim al places you want t o keep: SalePrice: Round([Price] * 0.95, 2)

Technically, t he Round( ) funct ion requires t wo pieces of inform at ion, or argum ent s. The first 's t he num ber you want t o round ( in t his case, it 's t he result of t he calculat ion Price * 0.95) , and t he second's t he num ber of digit s t hat you want t o ret ain t o t he right of t he decim al place ( 2) . The result : t he calculat ion rounded t o t wo decim al places, or 41.77.

Note: Most functions, like Round( ), require two or three arguments. However, some functions can accept many more, while a few don't need any arguments at all.

FREQUENTLY ASKED QUESTION Banker's Rounding

file:///C|/html/0596527608/access2007tm-CHP-7-SECT-2.html (1 of 14) [1/7/2007 7:09:11 AM]

Section 7.2. Query Functions

Access doesn't seem t o round num bers correct ly. What 's going on? I t m ay surprise you t hat Access rounds t he num ber 21.985 t o 21.98. I f you were t aught t o always round up t he num ber 5, you probably expect 21.99 inst ead. This is known as arit hm et ic rounding. However, Access doesn't use arit hm et ic roundinginst ead, it chooses banker's rounding, which is bet t er in som e sit uat ions. The difference bet ween arit hm et ic rounding and banker's rounding is how t hey t reat t he num ber 5. Since 21.985 lies exact ly halfway bet ween 21.98 and 21.99, it isn't easy t o decide what t o do wit h it . I f you always round 5 up, you'll int roduce a bias in t ot als and averages. Because you round up m ore oft en t hat you round down, any t ot al or average t hat you calculat e ends up j ust a sm idge higher t han it should be. Banker's rounding addresses t his by rounding 5 up som et im es and down ot her t im es, depending on whet her it 's paired wit h an even or odd num ber. 21.985 is rounded down t o 21.98, but 21.995 is rounded up t o 22. This way isn't t he only way t o fight rounding bias ( you could decide random ly when t o round and when not t o) , but it 's a com m only accept ed pract ice in account ing and st at ist ics.

7.2.1.1. Nested functions You can use m ore t han one funct ion in a single calculat ed field or filt er condit ion. The t rick is nest ing: nerdspeak for put t ing one funct ion inside anot her. For exam ple, Access provides an absolut e- value funct ion nam ed Abs( ) t hat convert s negat ive num bers t o posit ive num bers ( and leaves posit ive num bers unchanged) . Here's an exam ple t hat divides t wo fields and m akes sure t he result is posit ive: Speed: Abs([DistanceTravelled] / [TimeTaken])

I f you want t o round t his result , you place t he ent ire expression inside t he parent heses for t he Round( ) funct ion, like so: Speed: Round(Abs([DistanceTravelled] / [TimeTaken]), 2)

When evaluat ing an expression wit h nest ed funct ions, Access evaluat es t he innerm ost funct ion first . Here, it calculat es t he absolut e value, and t hen rounds t he result . I n t his exam ple, you could swap t he order of t hese st eps wit hout changing t he result : Speed: Abs(Round([DistanceTravelled] / [TimeTaken], 2))

I n m any ot her sit uat ions, t he order you use is im port ant , and different nest ing produces a different result . Nest ed funct ions can get ugly fast . Even in a relat ively sim ple exam ple like t he speed calculat ion, it 's difficult t o t ell what 's going on wit hout working t hrough t he calculat ion piece by piece. And if you m isplace a bracket , t he whole calculat ion can be t hrown off. When you need t o nest funct ions, it 's a good idea t o build t hem up bit by bit , and run t he query each t im e you add anot her funct ion int o t he m ix, rat her t han t ry t o t ype t he whole shebang at once.

7.2.2. The Expression Builder Funct ions are a great innovat ion, but Access j ust m ight have t oo m uch of a good t hing. Access provides a cat alog of dozens of different funct ions t ailored for different t asks, som e of which are int ended for specialized m at hem at ical or st at ist ical operat ions.

Note: This book doesn't cover every Access function. (If it did, you'd be fighting to stay awake.) However, in the following sections you'll see the most useful functions for working with numbers, text, and dates. To discover even more functions, use the Expression Builder. Or, if you prefer to do your learning online, check out the pithy resource www.techonthenet.com/access/functions.

To quickly find t he funct ions you want , Access provides a t ool called t he Expression Builder. To launch t he Expression Builder, follow t hese st eps:

file:///C|/html/0596527608/access2007tm-CHP-7-SECT-2.html (2 of 14) [1/7/2007 7:09:11 AM]

Section 7.2. Query Functions

Ope n a qu e r y in D e sign vie w . 2. Righ t - click t h e box w h e r e you w a n t t o in se r t you r e x pr e ssion , a n d t h e n ch oose Bu ild. I f you're creat ing a calculat ed field, t hen you need t o right - click t he Field box. I f you're creat ing a filt er condit ion, t hen you need t o right - click t he Crit eria box. Once you choose Build, t he Expression Builder appears, showing any cont ent t hat 's current ly in t he box ( Figure 7- 3) .

Figu r e 7 - 3 . The Expression Builder consists of a text box at the top of the window, where you can edit your expression, some buttons that quickly insert common operators (like +, -, /, and *, if for some reason you can't find them on the keyboard), and a threepaned browser at the bottom of the window that helps you find fields and functions you want

file:///C|/html/0596527608/access2007tm-CHP-7-SECT-2.html (3 of 14) [1/7/2007 7:09:11 AM]

Section 7.2. Query Functions

to use.

3. Add or e dit t h e e x pr e ssion . The Expression Builder includes t wo short cut s t hat you'll want t o t ry. You can insert a nam e wit hout t yping it by hand ( Figure 74) , and you can find a funct ion by browsing ( Figure 7- 5) .

Figu r e 7 4 . To pop in a new field name, double-click the Tables folder in the leftmost list. Then, click the subfolder that corresponds to the table you want to use. Finally, double-click the field name in the middle list to insert it into your expression. This technique's recommended only for those who love to click.

Note: The Expression Builder is an all-purpose tool to create expressions for calculated fields and filter conditions. Some options make sense only in one context. The logical operators like the equals (=) symbol and the And, Or, Not, and Like operators are useful for setting criteria for filtering (Section 6.2.1.1), but don't serve any purpose in calculated fields.

file:///C|/html/0596527608/access2007tm-CHP-7-SECT-2.html (4 of 14) [1/7/2007 7:09:11 AM]

Section 7.2. Query Functions

Figu r e 7 - 5 . To find a function, start by doubleclicking the Functions folder in the list on the left. Then, choose the Built-In Functions subfolder. (The other option shows you any custom functions that you've added to your database using custom VBA code.) Next, choose a function category in the middle list. The list on the right shows all the functions in that category. You can doubleclick the function to insert it into your file:///C|/html/0596527608/access2007tm-CHP-7-SECT-2.html (5 of 14) [1/7/2007 7:09:11 AM]

Section 7.2. Query Functions

expression.

Note: When you insert field names in the Expression builder, they're written in a slightly lengthier format that always includes the table name. You'll see [Products]![Price] instead of just [Price]. Don't worry both mean the same thing to Access. 4. Click OK. Access copies your new expression back int o t he Field box or Crit eria box.

Note: When you use the Expression Builder to add a function, it adds placeholders (like and ) where you need to supply the arguments. Replace this text with the values you want to use.

Most Access expert s find t hat t he Expression Builder is t oo clunky t o be wort h t he t rouble. But even t hough t he Expression Builder m ay not be t he m ost effect ive way t o writ e an expression, it 's a great way t o learn about new and m yst erious funct ions, t hanks t o it s built - in funct ion reference. I f you find a funct ion t hat sounds prom ising but you need m ore inform at ion, select it in t he list and t hen click Help. You'll be rewarded wit h a brief sum m ary t hat explains t he purpose of t he funct ion and t he argum ent s you need t o supply, as shown in Figure 7- 6.

Figu r e 7 - 6 . The reference for the Round( ) function spells out what it does, and explains the two parameters. One parameterthe number of decimal placesis wrapped in square brackets, which means it's an optional file:///C|/html/0596527608/access2007tm-CHP-7-SECT-2.html (6 of 14) [1/7/2007 7:09:11 AM]

Section 7.2. Query Functions

value. Leave it out, and Access rounds to the nearest whole number. You'll also notice a table of contents on the left that lets you browse to any other Access function and read its description.

7.2.3. Formatting Numbers Form at ( ) is one int erest ing m at hem at ical funct ion, which t ransform s num bers int o t ext . Form at ( ) is int erest ing because t he t ext it creat es can be form at t ed in several different ways, which allows you t o cont rol exact ly how your num bers are present ed. To underst and t he difference, t hink back t o t he expression you used earlier for discount ing product prices: SalePrice: [Price] * 0.95

Even if t he Price field has t he Currency dat a t ype, t he calculat ed values in t he SalePrice field appear as ordinary num bers ( wit hout t he currency sign, t housands separat or, and so on) . So you see 43.2 when you m ight prefer $43.20. You can rem edy t his problem by using t he Form at ( ) funct ion t o apply a currency form at : SalePrice: Format([Price] / 0.95, "Currency")

Now t he calculat ed values include t he currency sign. Even bet t er, since currencies are displayed wit h j ust t wo decim al places, you no longer need t o clean up fract ional values wit h t he Round( ) funct ion. The t rick t o using t he Form at ( ) funct ion is knowing what t ext t o supply for t he second argum ent in order t o get t he result you want . Table 7- 2 spells out your opt ions.

file:///C|/html/0596527608/access2007tm-CHP-7-SECT-2.html (7 of 14) [1/7/2007 7:09:11 AM]

Section 7.2. Query Functions

Ta ble 7 - 2 . For m a t t in g Opt ion s For m a t

D e scr ipt ion

Ex a m ple

Currency

Displays a num ber wit h t wo decim al places, t housand separat ors, and t he currency sign.

$1,433.20

Fixed

Displays a num ber wit h t wo decim al places.

1433.20

St andard

Displays a num ber wit h t wo decim al places and t he t housands separat or.

1,433.20

Percent

Displays a percent value ( a num ber m ult iplied by 100 wit h a percent sign) . Displays t wo digit s t o t he right of t he decim al place.

143320.00%

Scient ific

Displays a num ber in scient ific not at ion, wit h t wo decim al places.

1.43E+ 03

Yes/ No

Displays No if t he num ber's 0 and Yes if t he num ber's anyt hing else. You can also use t he sim ilar form at t ypes True/ False and On/ Off.

Yes

POWER USERS' CLINIC More Advanced Number Formats True perfect ionist s won't be happy wit h t he form at opt ions in Table 7- 2. I nst ead, t hey'll want com plet e cont rol over t he num ber of decim al places. One opt ion is t o use t he Form at Currency( ) , Form at Percent ( ) , and Form at Num ber( ) funct ions ( depending on whet her you want t he result ing t ext t o use currency form at , percent form at , or be displayed as an ordinary num ber) . When using t hese funct ions, you pass t he value t hat you want t o form at as t he first argum ent , and t he num ber of decim al places you want t o keep in t he second argum ent . For even m ore cont rol, you can define a cust om num ber form at t hat spells out exact ly what you want , and use t hat wit h t he Form at ( ) funct ion. You won't learn about cust om num ber form at s in t his book, but you can get m ore inform at ion on t his feat ure in Excel 2007: The Missing Manual, or in Access Help ( Figure 7- 6) .

7.2.4. More Mathematical Functions The m at hem at ical funct ions in Access don't get m uch respect , because people don't need t hem t erribly oft en. You've already seen Round( ) and Form at ( ) t he m ost useful of t he bunchbut t here are st ill a few ot hers t hat Access m avens t urn t o from t im e t o t im e in calculat ed fields. They're list ed in Table 7- 3.

Ta ble 7 - 3 . Fu n ct ion s for N u m e r ic D a t a Fu n ct ion

D e scr ipt ion

Ex a m ple

Re su lt

Sqr( )

Get t he square root

Sqr( 9)

3

Abs( )

Get s t he absolut e value ( negat ive num bers becom e posit ive)

Abs( - 6)

6

Round( )

Rounds a num ber t o t he specified num ber of decim al places

Round( 8.89, 1)

8.9

Fix( )

Get s t he int eger port ion of t he num ber, chopping off any decim al places

Fix( 8.89)

8

I nt ( )

The sam e as Fix( ) , but negat ive num bers are rounded down inst ead of up

I nt ( - 8.89)

-9

Rnd( )

Generat es a fract ional random num ber bet ween 0 and 1

I nt ( ( 6) * Rnd + 1)

A random int eger from 1 t o 6

Val( )

Convert s num eric dat a in a t ext field int o a bona fide num ber, so t hat you can use it in a calculat ion. St ops as soon as it finds a non- num eric charact er, and ret urns 0 if it can't find any num bers.

Val( " 315 Crossland St " )

315

file:///C|/html/0596527608/access2007tm-CHP-7-SECT-2.html (8 of 14) [1/7/2007 7:09:11 AM]

Section 7.2. Query Functions

Form at ( )

Turns a num ber int o a form at t ed st ring, based on t he opt ions you chose

Form at ( 243.6, Currency)

$243.60

GEM IN THE ROUGH Use Random Numbers for a Random Sort People rarely use t he Rnd( ) funct ionaft er all, who needs t o fill a colum n wit h m ade- up inform at ion? However, ent erprising Access gurus have com e up wit h one int riguing use for Rnd( ) . They use it t o sort a t able so t hat all t he records appear in a random order. Basically, you add a calculat ed field t hat holds t he random num ber. You can use a field expression such as Random : Rnd ( ) . I f you look at your query result s, t hen you will see a random value bet ween 0 and 1 ( like 0.7045, 0.2344, and so on) next t o each record. Now, swit ch back t o Design view, and t hen clear t he Show checkbox so t hat t he Random field doesn't appear in t he dat asheet . Next , choose Ascending or Descending ( it really doesn't m at t er) in t he Sort box, and t hen rerun t he query. Voilà! Every t im e you use t his query, t he records appear in a different order, according t o t he random num bers t hat Access generat es on t he fly.

7.2.5. Text Functions So far, all t he funct ions you've seen have worked wit h num eric dat a. However, t here's st ill a lot you can do wit h t ext . Overall, t here are t hree ways you can m anipulat e t ext : ●

● ●

Join t e x t . You can do t hings like com bining several fields t oget her int o one field. This t echnique doesn't require a funct ioninst ead, you can use t he & operat or described in Sect ion 7.1.3. Ex t r a ct pa r t of a t e x t va lu e . You m ay want j ust t he first word in a t it le or t he first 100 charact ers in a descript ion. Ch a n ge t h e ca pit a liza t ion . You m ay want t o show lowercase t ext in capit als, and vice versa.

Table 7- 4 shows t he m ost com m on funct ions people use wit h t ext .

Ta ble 7 - 4 . Fu n ct ion s for Te x t Fu n ct ion

D e scr ipt ion

Ex a m ple

Re su lt

UCase( )

Capit alizes t ext

UCase( " Hi There" )

HI THERE

LCase( )

Put s t ext in lowercase

LCase( " Hi There" )

hi t here

Left ( )

Takes t he num ber of charact ers you indicat e from t he left side

Left ( " Hi There" , 2)

Hi

Right ( )

Takes t he num ber of charact ers you indicat e from t he right side

Right ( " Hi There" , 5)

There

Mid( )

Takes a port ion of t he st ring st art ing at t he posit ion you indicat e, and wit h t he lengt h you indicat e

Mid( " Hi There" , 4, 2)

Th

Trim ( )

Rem oves blank spaces from eit her side ( or use LTrim ( ) and RTrim ( ) t o t rim spaces off j ust t he left or right side)

Trim ( " Hi There" )

Hi There

Len( )

Count s t he num ber of charact ers in a t ext value

Len( " Hi There" )

8

Using t hese funct ions, you can creat e a calculat ed field t hat shows a port ion of a long t ext value, or changes it s capit alizat ion. However, how you can use t hese funct ions in a filt er expression m ay not be as obvious. You could creat e a filt er condit ion t hat m at ches part of a t ext field, inst ead of t he whole t hing. Here's an exam ple of a filt er condit ion t hat select s records t hat st art wit h Choco: Left([ProductName], 5) = "Choco"

file:///C|/html/0596527608/access2007tm-CHP-7-SECT-2.html (9 of 14) [1/7/2007 7:09:11 AM]

Section 7.2. Query Functions

Figure 7- 7 shows how you ent er t his filt er condit ion.

Figu r e 7-7. The Left ( ), Right ( ), and Mid( ) functions work in much the same way as the Like keyword (Section 4.3.2.3) to help you match bits and pieces of long text values.

The Len( ) funct ion's a bit of an oddit y. I t exam ines a t ext value and ret urns num eric inform at ion ( in t his case, t he num ber of charact ers in t he value, including all spaces, let t ers, num bers, and special charact ers) . The Len( ) funct ion isn't t oo useful in a sim ple calculat ed expression, because you'll rarely be int erest ed in t he num ber of let t ers in a t ext value. However, it does let you writ e som e int erest ing filt er condit ions, including t his one t hat grabs records wit h a Descript ion of less t han 15 charact ers ( which probably could use som e ext ra inform at ion) : Len(Description) < 15

7.2.6. Date Functions You've already seen how you can use sim ple addit ion and subt ract ion wit h dat es ( Sect ion 7.1.2.2) . However, you can accom plish a whole lot m ore wit h som e of Access's dat e funct ions. Wit hout a doubt , everyone's favorit e dat e funct ions are Now( ) and Dat e( ) , which you first saw in Chapt er 4 ( Sect ion 4.3.2.3) . These funct ions grab t he current dat e and t im e, or j ust t he current dat e. You can use t hese funct ions t o creat e queries t hat work wit h t he current year's wort h of orders. Here's a filt er condit ion t hat uses Dat e( ) t o select proj ect s t hat are past due: = button to move it from the Available Fields list to the Selected Fields list. Click >> to add all the fields in one shot.

4. Th e n e x t st e p a sk s you if you w a n t t o a dd a n y gr ou pin g. For n ow , click N e x t t o cr e a t e a r e por t w it h ou t gr ou pin g. You'll learn how t o use grouping in a report in Sect ion 11.6. 5. Ch oose t h e fie ld ( or fie lds) you w a n t t o u se t o sor t you r r e por t r e su lt s, a n d t h e n click N e x t . You can sort your result s by a com binat ion of four fields, but usually one's enough t o get t hem in t he order you want . 6.

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-2.html (2 of 4) [1/7/2007 7:10:52 AM]

Section 11.2. The Report Wizard

Ch oose a la you t opt ion for you r r e por t ( Figu r e 1 1 - 1 1 ) . Your layout opt ions include: ❍





Colu m n a r put s each field on a separat e row, one aft er t he ot her. The nam e's a lit t le m isleadingessent ially your report has t wo colum ns. The first colum n holds t he field capt ion, and t he second colum n includes t he field dat a. Ta bu la r uses invisible layout t ables t hat you explored in Chapt er 10. Access t ransform s each field int o a separat e colum n. Ju st ifie d packs t he inform at ion int o t he sm allest space possible. One row could include several fields. The nam e " j ust ified" refers t o t he fact t hat t he dat a fills t he ent ire widt h of t he page wit h no spaces. Where one fields ends, t he next begins.

Figu r e 1111. The layout option tells Access how it should organize your fields in the detail section.

7. I f you w a n t t o t u r n t h e pa ge on it s side , t h e n ch oose La n dsca pe or ie n t a t ion , a n d t h e n click Next. Landscape orient at ion let s you fit wide t ables or large am ount s of inform at ion, but it includes fewer rows per page. 8.

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-2.html (3 of 4) [1/7/2007 7:10:52 AM]

Section 11.2. The Report Wizard

Ch oose on e of t h e pr e se t st yle s, a n d t h e n click N e x t . The st yles det erm ine t he form at t ing Access applies t o your report . Unfort unat ely, you'll have a difficult t im e visualizing t he final result unless you act ually t ry each opt ion. 9. En t e r t h e n a m e for you r r e por t . When t he Report wizard finishes, it im m ediat ely saves your report . 10. Ch oose " Pr e vie w t h e r e por t " if you w a n t t o look a t t h e fin ish e d pr odu ct in Pr in t Pr e vie w m ode , or " M odify t h e r e por t 's de sign " if you w a n t t o ch a n ge it in D e sign vie w fir st . Th e n , click Fin ish . Access saves your report , and t hen opens it in Print Preview m ode or design m ode, depending on your choice. As you can see, t he Report wizard really isn't t hat flexible. I t support s only a few t ypes of layout s, and it doesn't let you t ailor how Access arranges different fields. However, it m ay give you a good st art ing point ( and even if it doesn't , it 's a wort hwhile way t o explore report layout in Design view) .

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-2.html (4 of 4) [1/7/2007 7:10:52 AM]

Section 11.3. The Label Wizard

11.3. The Label Wizard I f you have a t able wit h address inform at ion ( like cust om er hom es, business locat ions, or suspect ed UFO sit es) , Access has anot her wizard t o offer you. The Label wizard pulls address inform at ion out of any t able you want and uses it t o print out handy m ailing labels. To m ake t his work, you j ust need t o buy a few sheet s of label paper from your favorit e office supply st ore. Label paper variessom e t ypes pack t he inform at ion in very t ight ly, so you can print out dozens of ret urn addresses at once, while ot hers use larger labels for put t ing t he m ailing address on a let t er or package. But no m at t er what t ype of label paper you pick, it has a st andard Avery num ber t hat t ells Access everyt hing it needs t o know about t he labels' size, and how t hey're arranged. You give Access t he Avery num ber, and t hen it can creat e a report t hat put s t he address inform at ion in t he correct place. All you have t o do is print , peel, and st ick.

Tip: If you have a database that stores information about people, then you may have thought about using Access reports to build form letters and other documents. Getting Access to cooperate isn't all that easy. Instead, you'll do better using a real word processing program like Word. Word includes a mail merge feature that can extract data from an Access database, and then use it to generate any document you want. For more information, check out Word 2007: The Missing Manual.

To creat e a bat ch of labels, here's what you need t o do: 1. I n t h e n a viga t ion pa n e , se le ct t h e t a ble w it h t h e a ddr e ss in for m a t ion . I t doesn't act ually need t o be address inform at ion. I f you want t o print em ployee nam e t ags or product st ickers, or you j ust have an insat iable urge t o label m yst erious it em s around t he house, t hen you can place t hat dat a on your labels inst ead.

Note: If you need to create labels using the information in more than one table, then you'll need to create a join query (Section 6.3), and then select that before you launch the Label wizard. 2. Ch oose Cr e a t e

Re por t s

La be ls.

The Label wizard st art s. The first st ep asks you t o pick t he t ype of label paper you're using ( Figure 11- 12) . 3. I f you r la be l pa pe r 's on e lon g r oll ( a s oppose d t o in dividu a l sh e e t s) , ch oose Con t in u ou s in st e a d of " Sh e e t fe e d" . Unless you have a print er from t he dark ages of com put er print ing, you're unlikely t o use t his opt ion. 4. Fin d t h e la be l t h a t h a s t h e sa m e pr odu ct n u m be r a s you r la be l pa pe r . D ou ble - ch e ck t h a t t h e dim e n sion s Acce ss sh ow s m a k e se n se . Norm ally, t he product num ber's t he Avery num ber, which is what m ost people use. ( You should have no t rouble finding t he Avery num ber on t he front of a package of label paper.) However, if your label paper uses a different num bering syst em , t hen pick t he com pany t hat m ade t he paper from t he " Filt er by m anufact urer" list .

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-3.html (1 of 5) [1/7/2007 7:10:56 AM]

Section 11.3. The Label Wizard

Figu r e 1112. This example uses the common C2160 type of label, which arranges labels in three columns per page.

Note: If you're creating strange nonstandard labels of your own devising, then click the Customize box to show the New Label Size dialog box, and then click New to show the New Label dialog box. Then you can fill in the exact measurements for each part of your label. 5. Click N e x t . The next st ep of t he wizard asks you t o choose t he form at t ing for your label t ext ( Figure 11- 13) .

Figu r e 11-13. Access shows a Preview box with some text so that you won't inadvertently make a dangerously oversized label.

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-3.html (2 of 5) [1/7/2007 7:10:56 AM]

Section 11.3. The Label Wizard

6. Pick t h e fon t , t e x t size , a n d t h e fon t color you w a n t , a n d t h e n click N e x t . Of course, you can change t hese det ails in Design view aft er t he fact , but it 's bet t er t o get t hem right from t he beginning. Usually, you should keep t he font size t hat Access recom m endst his size fit s a good four t o six lines of t ext in your label ( depending on t he label t ype) . I n t he next st ep, you get t o pick t he fields t hat Access should place on t he label. 7. To a dd t h e fir st lin e t o you r t a ble , fin d t h e fie lds you n e e d in t h e " Ava ila ble fie lds" list , a n d t h e n dou ble - click t h e m . Add t he fields in t he order you want t hem t o appear ( First Nam e, Last Nam e, St reet , Cit y, and so on) . As you pick fields, Access insert s a special placeholder in t he " Prot ot ype label" box. I t adds t he code { First Nam e} t o show you where it 'll place t he value from t he First Nam e field. I t 's up t o you t o add t he spacing you want bet ween t hese fields. ( Usually, you j ust want spaces and com m as.) Figure 11- 14 shows how.

Figu r e 11-14. To space out the information in your label, click between two fields you want to separate in the "Prototype label" box. Then, hit the Space bar to add a space. You can also add plain text wherever you want (like the word "To:" or a comma).

8. I n t h e " Pr ot ot ype la be l" box , click t h e se con d lin e . N ow , r e pe a t st e p 7 t o a dd fie lds t o t h is lin e .

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-3.html (3 of 5) [1/7/2007 7:10:56 AM]

Section 11.3. The Label Wizard

Repeat t his st ep unt il you've added all t he fields you need, each on t he appropriat e line. 9. Opt ion a lly, pick a fie ld t o u se t o sor t t h e la be ls, a n d t h e n click N e x t . The sort order m ay or m ay not be im port ant t o you. ( I t could help you m at ch a label up wit h a let t er, if t he let t ers are also in t he sam e sort ed order. But it doesn't m ake a difference if you're preparing a m ass m ailing t hat 's t he sam e for every person.) Oft en, people don't use sort ing but do use filt ering ( Sect ion 6.2.1.1) t o get j ust som e labels ( like all t he cust om ers living in a specific cit y) . I f you use sort ing, t hen Access will arrange your labels from left t o right , and t hen down t he page. 10. En t e r you r r e por t 's n a m e . When t he Label wizard finishes, it im m ediat ely saves your report . 11. Ch oose " Se e t h e la be ls a s t h e y w ill look pr in t e d" if you w a n t t o look a t t h e fin ish e d pr odu ct in Pr in t Pr e vie w m ode , or " M odify t h e la be l de sign " if you w a n t t o ch a n ge it in D e sign vie w fir st . Th e n , click Fin ish . Access saves your report , and t hen opens it in print preview m ode ( Figure 11- 15) or design m ode, depending on your choice. I f you open it in design m ode, t hen you can add ext ra t ouches. ( You could place a com pany logo in t he corner of t he address, and so on.)

Figu r e 1115. The final report, with labels.

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-3.html (4 of 5) [1/7/2007 7:10:56 AM]

Section 11.3. The Label Wizard

The label report 's really j ust an ordinary Access report , like t he kind you've learned about t hroughout t his chapt er. The Det ail sect ion cont ains a t em plat e t hat defines how Access places t he fields for a single label, and t hat t em plat e's copied across t he form . The only difference bet ween label report s and ordinary report s is t hat label report s use m ult iple colum ns. That way, t he Det ail sect ion ( which represent s t he label) can be copied from right t o left across t he widt h of t he page, and t hen down t he page. This m et hod gives you a t ight ly packed grid of labels. ( Usually, t he Det ail sect ion's copied in one direct ion only: down t he page.) You can creat e your own report t hat also uses m ult iple colum ns t o put records in a grid. You sim ply need t o open your report in Design view, m ake sure your det ail sect ion's very narrow ( see Chapt er 11) , and t hen choose Report Design Tools | Page Set up Page Layout Colum ns. This pops open a dialog box where you can set t he num ber of colum ns, and t he space bet ween t hem . You can also choose whet her Access lays out your records from t op t o bot t om and t hen left t o right , or from left t o right and t hen t op t o bot t om . Eit her way, check t he Print Preview t o m ake sure everyt hing fit s nicely on t he page.

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-3.html (5 of 5) [1/7/2007 7:10:56 AM]

Section 11.4. Fine-Tuning Reports with Properties

11.4. Fine-Tuning Reports with Properties As you've already learned, you can m ost easily t weak your report 's cont rols wit h t he t oolbar but t ons. However, even t hough t he t oolbar's packed full of useful feat ures, it doesn't have everyt hing. Behind t he scenes, each cont rol has a host of low- level set t ings, known as propert ies. Many of t hese set t ings are obscure, and people rarely use t hem . Som e are known only t o a sm all num ber of ant isocial Access j unkies. But a few are genuinely useful, because t hey provide feat ures t hat you can't reach anywhere else in Access. You can hunt down and change t hese set t ings only wit h t he Propert y Sheet .

Tip: The Properties window's occasionally useful for report writing, but it becomes much more important when you tackle forms in Part Four and add code in Part Five.

To show t he Propert y Sheet , choose Report Design Tools | Design Propert y Sheet appears at t he window's right side ( Figure 11- 16) .

Tools

Propert y Sheet . The

The Propert y Sheet let s you fine- t une a single report it em at a t im e. You choose t he it em by select ing it on t he design surface, or choosing it from t he drop- down list at t he t op of t he Propert y Sheet . I f you want t o t weak a specific cont rol, it 's usually easier t o click t o select it on t he design surface. The drop- down list 's by nam e, and Access doesn't always use t he m ost int uit ive nam es. Som et im e t hey m at ch t he underlying field ( like Product Cat egoryI D) , and som et im es t hey don't ( like Text 3) . Most cont rols have a sim ilar set of propert ies. To help get around t his int im idat ing long list , t he Propert y Sheet divides it int o t he following t abs: ● ● ●

● ●

For m a t cont ains t he opt ions you'll change m ost oft en, including t he font , color, borders, and m argins. D a t a ident ifies where t he cont rol get s it s inform at ion. For t he cont rols in t he det ail sect ion, t his t ab ident ifies t he linked field's nam e. Usually, you don't need t o change t hese set t ings on your own. Eve n t let s you at t ach Visual Basic code t hat springs int o act ion when som et hing specific happens. You'll learn m uch m ore about code in Part Five. Ot h e r includes t he Nam e propert y, which defines t he cont rol nam e, and a few m iscellaneous propert ies t hat are m ore relevant wit h form s. All shows t he whole shebang.

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-4.html (1 of 6) [1/7/2007 7:11:00 AM]

Section 11.4. Fine-Tuning Reports with Properties

Figu r e 11-16. The Property Sheet shows a list of settings (known as properties) for a single control. You can see the full list in the All tab, or you can see a partial list of properties in one of the other tabs. In this example, a text box control's currently selected.

Tip: To get a quick one-sentence description of a mysterious property, click to select it in the Property Sheet, and then, at the bottom of the Access window, look for the descriptive text that appears in the Status bar.

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-4.html (2 of 6) [1/7/2007 7:11:00 AM]

Section 11.4. Fine-Tuning Reports with Properties

I nt erest ingly, cont rols aren't t he only t hing you can change in t he Propert y Sheet . You can also adj ust report set t ings ( at t he t op of t he Propert y Sheet , choose Report in t he drop- down list ) , which ident ify where t he dat a com es from and how you can view or edit t he report . And you can t weak set t ings t hat are specific t o a part icular sect ion ( like Report Header, Report Foot er, PageHeaderSect ion, PageFoot er- Sect ion, and Det ail) , which include page break det ails and addit ional form at t ing. Of course, it 's one t hing t o know t hat t here are a bunch of set t ings you can change, and anot her t hing ent irely t o know what set t ings are wort h t weaking. The Propert y Sheet 's clut t ered wit h a lot of propert ies t hat aren't wort h your t im e. I n t he next sect ion, you'll consider a t able ( Table 11- 1) t hat list s t he m ost useful propert ies in report s.

11.4.1. Modifying Common Properties I f you're st ill a lit t le overwhelm ed by t he Propert y Sheet , t hen t ry t he following st eps. They walk you t hrough t he process of m aking a change: 1. Se le ct a con t r ol on t h e de sign su r fa ce . I t s propert ies appear in t he Propert y Sheet . 2. Click t h e For m a t t a b, a n d t h e n scr oll dow n t h e list u n t il you fin d t h e Ba ck Color se t t in g. The Back Color set t ing det erm ines t he color t hat appears for t he cont rol background, behind t he t ext . 3. Click t h e Ba ck Color box . An e llipsis ( …) bu t t on a ppe a r s in t h e box . Click it . A color picker dialog box appears. The Back Color box shows a color num ber t hat represent s t he color. But unless you've m em orized hundreds of t housands of crypt ic color codes, you'll find it easier t o choose t he color from t he color picker dialog box. 4. Ch oose a color . The new color appears im m ediat ely, along wit h t he new color num ber. You can also use t his t echnique t o set t he background for an ent ire sect ion of t he report . From t he drop-

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-4.html (3 of 6) [1/7/2007 7:11:00 AM]

Section 11.4. Fine-Tuning Reports with Properties

down list in t he Propert y Sheet , j ust choose a sect ion like Report Header or Det ail, and t hen follow t hese st eps.

Tip: If you change the background color of a report section, then make sure you also change it for all the controls on that part of the report, or they'll have white boxes around them. You can select all the controls you want to change at once by dragging a selection box around them, or you can just hold down Shift, and then click each one. Then, head to the Property Sheet to make your batch change.

I n t his exam ple, you could change t he background color m ore easily using t he ribbon. However, you can change m any propert ies in t he Propert y Sheet t hat have no equivalent in t he ribbon. Table 11- 1 list s a few useful exam ples, all of which you find in t he Form at t ab.

Ta ble 1 1 - 1 . Use fu l Con t r ol Pr ope r t ie s ( in t h e For m a t Ta b) Se le ct e d I t e m

Any cont rol t hat shows t ext

Text box

Pr ope r t y

D e scr ipt ion

Text Align

Norm ally, t he alignm ent depends on t he t ype of dat a you're displaying. For exam ple, Access right - aligns num bers and dat es. I f you want t o com pare a long list of num bers, t hen t his syst em m akes sense. But if you want your num bers t o line up wit h ot her pieces of t ext dat a, t hen you can choose a different alignm ent opt ion here, like Left or Cent er.

Form at

Norm ally, Access uses t he num ber form at t ing t hat 's defined for your dat a t ype, and you don't need t o worry about t his set t ing. However, if you're using a calculat ed expression ( Sect ion 7.1) , t hen Access shows t he result as an ordinary num ber, even if you want t wo decim al places and a currency sym bol. To fix t his, choose t he form at you want ( like Currency) . Sect ion 2.3.3.2 describes your ot her opt ions.

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-4.html (4 of 6) [1/7/2007 7:11:00 AM]

Section 11.4. Fine-Tuning Reports with Properties

Text box

Report

Report

PageHeaderSect ion, Page- Foot erSect ion, Report - Header, Report Foot er

Det ail

Det ail

Can Grow

I f you set Can Grow t o Yes, Access expands t he field vert ically t o fit it s cont ent . Can Grow is swit ched on for all fields when you creat e a sim ple t abular report , but it 's not necessarily on for ot her t ypes of report s t hat you generat e wit h t he Report wizard. When it 's not swit ched on, Access chops down long cont ent t o fit t he available space.

Default View

Det erm ines what view your report st art s in when you open it by double- clicking it s nam e in t he navigat ion pane. Ordinarily, you st art in Report view.

Page Header and Page Foot er

The st andard set t ing, All Pages, places t he header and foot er on every page. Alt ernat ely, you can choose t o leave t he page header or page foot er out on pages t hat include t he report header or report foot er.

Display When

Ordinarily, t hese sect ions appear onscreen, and in t he final print out . Alt ernat ely, you can choose t o include t hem in eit her t he onscreen represent at ion or t he print out , but not bot h.

Force New Page

Ordinarily, t his propert y's set t o None, and Access packs in as m uch inform at ion as possible before m oving t o t he next page. Alt ernat ively, you can use Before Sect ion t o st art each record on a new page. The ot her Force New Page opt ions are int ended for use wit h grouping ( Sect ion 11.6) .

Keep Toget her

I f set t o Yes, t hen Access never split s t he det ail sect ion over a page break in a print out . I f t here isn't enough room for a com plet e record left on a page, t hen Access skips st raight t o t he next page, and resum es print ing t here.

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-4.html (5 of 6) [1/7/2007 7:11:00 AM]

Section 11.4. Fine-Tuning Reports with Properties

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-4.html (6 of 6) [1/7/2007 7:11:00 AM]

Section 11.5. Expressions

11.5. Expressions Earlier in t his chapt er, you learned how t o add a label and set it s t ext . But if you look at t he cont rols on a t ypical report , you'll quickly not ice t hat t hey don't all use ordinary t ext . Consider t he dat e or page num ber inform at ion ( which appears in t he t op- right corner of a sim ple report ) . Bot h t hese det ails appear in ordinary label cont rols, but t he t ext looks dist inct ly different . I t st art s wit h an equal ( = ) sign, which indicat es t he presence of an expression. Expressions let labels and ot her cont rols show dynam ic values. No one want s t o t ype in a specific dat e in a report , because you'd be forced t o updat e it every t im e you want t o m ake a print out . I nst ead, you use an expression like = Dat e( ) , which t ells Access t o grab t he current dat e from t he com put er clock and display t hat . Expressions aren't new. You learned about t hem wit h queries in Chapt er 6 ( Sect ion 7.1) . However, unt il now you probably didn't realize t hat t hey're equally at hom e in report s. You can add your own expressions t o a report t o display dynam ic dat a, or perform calculat ions based on ot her fields. Suppose you want t o im prove t he wedding list by com bining t he first and last nam es int o a com pact one- line display. As you learned in Sect ion 7.1.3, t he & sym bol's t he t icket for fusing t oget her pieces of t ext . Here's t he expression you need: =FirstName & " " & LastName

Tip: Refer to Chapter 7 (starting in Section 7.1) for an overview of expressions, the different types of calculations you can perform, and the different functions you can use with them.

You can't ent er an expression int o a label cont rol, because a label's lim it ed t o fixed, unchanging t ext . I nst ead, you need t o use t he t ext box cont rol. ( Access also uses t he t ext box cont rol t o display m ost fields.) Once you've added t he t ext box t o t he design surface, click t o select it . The m ouse point er changes int o t he t ext point er. Click again t o edit t he t ext , and t hen ent er your expression exact ly, rem em bering t o st art wit h t he equal sign ( Figure 11- 17) .

Figu r e 11-17. Top: The expression looks like an ordinary file:///C|/html/0596527608/access2007tm-CHP-11-SECT-5.html (1 of 2) [1/7/2007 7:11:03 AM]

Section 11.5. Expressions

text value in Design view. Bottom: When you preview the report, Access performs the calculation, and then shows the result.

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-5.html (2 of 2) [1/7/2007 7:11:03 AM]

Section 11.6. Grouping

11.6. Grouping Grouping's an indispensable t ool for m aking sense of large volum es of dat a by arranging t hem int o sm aller groups. You can t hen perform calculat ions on each individual group. Consider a list of orders in t he Bout ique Fudge com pany. Depending on how you want t o group your dat a, you can consider whet her chocolat e m ilk out sells chocolat e beer, whet her cust om ers in New York crave m ore cocoa t han t hose in Alabam a, and so on. You have t hree ways t o use grouping t o analyze inform at ion in a report : ●

Use gr ou pin g w it h a qu e r y. I n t his case, your report doesn't include any det ails. I nst ead, it feat ures calculat ed sum s, averages, m axim um s, or m inim um s. You don't need any fancy report ing m oj o t o pull t his offj ust creat e a t ot als query wit h grouping ( as described in Sect ion 7.3) , and t hen use t hat query t o build a report .

FREQUENTLY ASKED QUESTION Expression Errors Why does m y expression display # Error when I preview it ? The # Error code indicat es, unsurprisingly, t hat som et hing's not quit e right wit h your expression. Access t ries t o evaluat e it , runs int o t rouble, and shows t he error m essage inst ead. You can oft en get a good indicat ion of t he problem by swit ching back t o Design view, and t hen looking at t he offending t ext box cont rol. Usually, you'll see a green t riangle in t he cont rol's t op- left corner t o highlight t he problem . Select it , and an error icon appears im m ediat ely t o t he left . You can hover over t he error icon t o see a descript ion of t he problem , and click it t o see a short m enu of possible fixes t hat you can apply and error checking opt ions t hat can t ell Access t o ignore t his problem in t he fut ure. Access error m essages are not oriously unclear, so even when you find t he error icon and get t he det ails, you m ay st ill be in t he dark about t he real problem . To get you on t he right t rack, consider t his short list of com m on problem s: ❍ ❍ ❍ ❍

● ●

You didn't st art your expression wit h an equal sign. You m isspelled t he field nam e, or you referred t o a field t hat isn't in t he underlying t able or query. You included a m ism at ched set of parent heses. Your t ext box has t he sam e nam e as one of t he fields you're t rying t o use. I f you have t he expression = Unit sI nSt ock+ Unit sOnOrder and your t ext box cont rol is nam ed Unit sI nSt ock, Access becom es confused. To resolve t his, renam e t he t ext box by changing t he Nam e propert y of t he t ext box t o som et hing else ( like Unit sI nSt ockCalculat ion) using t he Propert y Sheet . ( The Nam e propert y appears at t he t op of t he All t ab.)

Use r e por t gr ou pin g. This way, you can organize large volum es of inform at ion int o subgroups. You st ill see all t he det ails, but you can use subt ot als and ot her calculat ions. You can also add m ult iple grouping levels t o pull out buried t rends. Use su br e por t s. This way has t he sam e effect as report grouping. The only difference is t hat you creat e your report in t wo dist inct pieces.

Note: Subreports are largely a holdover from earlier versions of Access. In Access 2007, the grouping features have improved so much that you no longer need subreports. In this book, you'll focus on getting the most from report grouping, and bypass subreports.

11.6.1. Report Grouping To creat e groups, follow t hese st eps: 1. Sw it ch t o La you t vie w or D e sign vie w . 2. Ch oose t h e fie ld you w a n t t o u se for sor t in g.

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-6.html (1 of 12) [1/7/2007 7:11:12 AM]

Section 11.6. Grouping

Usually, you should sort your t able using t he sam e field you plan t o use for grouping. I f you want t o group by Product Cat egoryI D ( which creat es a separat e group of product s for each cat egory) , t hen you should begin by sort ing your result s by Product Cat egoryI D. That way, all t he product s in t he sam e group are list ed t oget her. ( You could also sort by a unique field in t he linked Product Cat egories t able, like Cat egoryNam e. Since each product cat egory has a different nam e, t his sort s your product s int o groups j ust as effect ively.)

Note: If you've created a lookup, Access is smart enough to do the right thing, and use the descriptive field, rather than the linked field, for sorting. ProductCategoryID uses a lookup that displays the matching product name, rather than the underling category ID number that no one really cares about. When you right-click the ProductCategoryID field and choose Sort On, Access actually uses the CategoryName field. 3. To a pply a sor t , r igh t - click t h e fie ld you w a n t t o u se for sor t in g, a n d t h e n ch oose a sor t com m a n d ( lik e " Sor t A t o Z" or " Sor t Sm a lle st t o La r ge st " ) . The exact wording of t he m enu com m and depends on t he dat a t ype of t he field. 4. Righ t - click t h e fie ld you w a n t t o u se for gr ou pin g, a n d t h e n se le ct Gr ou p On . Acce ss sor t s you r r e su lt s by t h a t fie ld, a n d t h e n gr ou ps t h e m . Figures 11- 18 and 11- 19 show t wo report s t hat group product s by cat egory.

Figu r e 1118. Here, a simple tabular report's sorted and grouped by category with a few quick clicks.

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-6.html (2 of 12) [1/7/2007 7:11:12 AM]

Section 11.6. Grouping

Tip: When you use grouping, it may not make sense to keep your column headers in the page layout section. That's because every group header interrupts your table. Often, you're better off placing the column headers at the bottom of the group header, so they appear at the beginning of every group (not at the top of every page). Figure 11-18 uses this approach. (Figure 11-19 doesn't need to, because it doesn't use any headers at all.) Unfortunately, in order to use this more attractive arrangement, you need to remove your fields from their automatic layout (Section 11.1.3).

Figu r e 11-19. Grouping works equally well with reports that have complex, nontabularlayouts. However, you could have a slightly harder time seeing where the groups begin and end, so consider giving the category section a different background color (using the Back Color property described in Section 11.4.1) to make it stand out, as in this example. Or, you can use the line control to create a divider at the top of each category. Figure 11-20 shows this report in Design view.

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-6.html (3 of 12) [1/7/2007 7:11:12 AM]

Section 11.6. Grouping

Grouping works by adding m ore sect ions t o your report . I f you group using t he Product Cat egoryI D field, t hen your report gains a new sect ion nam ed Product - Cat egoryI D Header, which Access places j ust above t he det ail sect ion ( see Figure 11- 20) . This group header includes inform at ion about t he groupingin t his case, t he product cat egory. The det ail sect ion has t he dat a for each record t hat 's placed in t he group.

Note: As you'll see later, you can actually add multiple levels of grouping. When you do, Access adds one group header for each level.

11.6.2. Fine-Tuning with the "Group, Sort, and Total" Pane Once you have your grouping in place, you have m any m ore opt ions: ● ● ●

You can add an ext ra layer of sort ing t hat sort s each subgroup. You can perform sum m ary calculat ions for each group. You can force page breaks t o occur at t he st art of each new group.

Figu r e 1 1 2 0 . Design view provides the easiest way to add content to the header section of each group. In the ProductCatalog report, you may want to add additional fields from the ProductCategories table to the ProductCategoryID Header section (like the Description).

You can m ost easily add any of t hese feat ures wit h t he " Group, Sort , and Tot al" pane. To show it in Design view, choose Grouping & Tot als Group & Sort . Or, in Layout view, choose Report Layout Tools Report Design Tools | Design Grouping & Tot als Group & Sort . | Form at t ing The Group, Sort , and Tot al pane appears at t he bot t om of t he window. Figure 11- 21 shows what you'll see if you exam ine t he product s- by- cat egory report from Figure 11- 19.

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-6.html (4 of 12) [1/7/2007 7:11:12 AM]

Section 11.6. Grouping

Figu r e 1 1 - 2 1 . This report has one level of sorting (alphabetically by CategoryName) and one level of grouping (byProductCategoryID). To see more options for any given level, select it and then click More (circled). Figure 11-22 shows the grouping settings you can change.

The following sect ions describe your opt ions in t he Group, Sort , and Tot al pane:

11.6.2.1. Sort by … Chooses t he field t hat 's used for sort ing. I n Figure 11- 21, fields are sort ed by Cat egoryNam e, and t hen grouped by Product Cat egoryI D.

Figu r e 1122. The Group, Sort, and Total pane gives you a quick way to set up subtotals, headers and footers, and page break options for each level of grouping you use.

11.6.2.2. Group on …

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-6.html (5 of 12) [1/7/2007 7:11:12 AM]

Section 11.6. Grouping

Chooses t he field t hat 's used for grouping. This opt ion let s you swit ch up your grouping in a flash.

11.6.2.3. From A to Z/from smallest to largest Changes t he sort order. The exact wording depends on t he dat a t ype, but you can sort alphabet ically for t ext , num erically for num bers, or chronologically for dat es.

11.6.2.4. By entire value Tells Access t o creat e a separat e group for every different value in t he grouped field. I f you're grouping by Product Cat egoryI D, t hen t his opt ion ensures t hat Access places each cat egory in a dist inct group. I n som e sit uat ions, t his approach creat es t oo m any groups, m aking it difficult t o perform any analysis ( and wast ing ream s of paper) . I n cases like t hat , you need a way t o creat e larger groups t hat include m ore records. I f you're grouping product s by price or orders by dat e, t hen you m ay prefer t o group a range of values, as shown in Figure 11- 23.

11.6.2.5. With … totaled Subt ot als is t he m ost popular grouping feat ure. Subt ot als let s you com pare how different groups st ack up t o one anot her. The " Group, Sort , and Tot al" pane let s you perform calculat ions using any num eric fields for your subt ot als ( Figure 11- 24) . Depending on what you're t rying t o accom plish, you can count values, add t hem , calculat e averages, or det erm ine m axim um and m inim um values in a group. You can place t his inform at ion int o a header t hat appears at t he beginning of each group, or a foot er t hat follows at t he end. Finally, you can t op your report off wit h a final grand t ot al t hat adds up all t he subgroups.

Figu r e 11-23. With date or numeric fields, you can choose to create a group that encompasses an entire range of values. In this example, groups are created by price in intervals of five. The first group has products priced less than $5, the next group stretches from $5 to $9.99, and so on.

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-6.html (6 of 12) [1/7/2007 7:11:12 AM]

Section 11.6. Grouping

11.6.2.6. With title … Click t his sect ion t o add a fixed t it le t hat appears in t he cat egory header, at t he beginning of each cat egory sect ion. Of course, you can add a t it le on your own by insert ing a label in Design view, but t his opt ion provides a convenient short cut .

11.6.2.7. With a header section / with a footer section You can apply a header at t he beginning of each group, and a foot er at t he end. Once you add t hese sect ions, you can place any cont ent you want in t hem using Design view. You'll use t hem m ost oft en t o display inform at ion about t he ent ire group, show subt ot als, or draw separat ing lines wit h t he line cont rol ( Sect ion 11.1.4) .

11.6.2.8. Keep group together on one page This set t ing helps you prevent orphaned cat egory headers. I n t he product cat alog exam ple, t his opt ion m akes sure you don't wind up wit h a group t it le like Beverages at t he bot t om of a page, and all t he m at ching product s on t he following page. Ordinarily, Access doesn't prevent awkward page breaks. I nst ead, it sim ply t ries t o fill each page. I f t his isn't what you want , t hen you have t wo ot her choices. You can choose t o m ake sure t he ent ire group's always placed on t he sam e page ( assum ing it 's less t han one page long) , or you can choose t o m ake sure t he header and at least one record are kept t oget her on t he sam e page.

Figu r e 112 4 . In this example, the list of products is grouped by category, and the average price of each category is displayed in the footer (circled).

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-6.html (7 of 12) [1/7/2007 7:11:12 AM]

Section 11.6. Grouping

One opt ion t he " Group, Sort , and Tot al" pane doesn't offer you is forcing a new page break at t he beginning of each group. To accom plish t his, you need t o swit ch t o Design view, select t he group header sect ion, and t hen, in t he Form at sect ion Propert y Sheet , look for t he Force New Page set t ing ( Sect ion 11.5) . Set it t o Before Sect ion t o force a page break at t he beginning of each new sect ion, or Aft er Sect ion t o force t he page break at t he end of t he sect ion. ( You don't see a difference bet ween t hese t wo set t ings unless you're using a report header and foot er. I f you have a report header and you use Before Sect ion, t hen you end up wit h a page break bet ween t he report header and t he first sect ion.)

Note: You don't see Force New Page setting's effect in Layout view, Report view, or Design view. It appears only when you use the Print Preview feature (Section 10.2), or when you actually print your report.

I n m any scenarios, you'll want a group t o st art on a new page. This st ipulat ion m akes sense when print ing t he class list shown in Figure 11- 25. I n t his case, t he Force New Page set t ing let s you avoid put t ing t wo at t endance list s on t he sam e page.

Figu r e 11-25. This class attendance list uses several of the tricks you've learned in this chapter to create a printout that's a world away from a typical report. The report displays a list of students grouped by class. There's no report header, but the group header for each class adds a few key pieces of information

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-6.html (8 of 12) [1/7/2007 7:11:12 AM]

Section 11.6. Grouping

from the Classes table. Each class group starts on a new page thanks to the Force New Page settings, and each student's followed by a row of handdrawn rectangle controls where you can tick off the attendance.

11.6.3. Multiple Groups Your report s aren't lim it ed t o a single group. I n fact , you can add as m any levels of sort ing and grouping as you want , t o slice and dice your dat a int o sm aller, m ore t ight ly focused subgroups. To add anot her level of grouping, j ust right - click t he field you want t o use, and t hen click Group On. This adds it t o t he list in t he " Group, Sort , and Tot al" pane. ( You can also add addit ional levels of sort ing by right - clicking a field, and t hen choosing a sort com m and. I f you began by sort ing and grouping your product s int o cat egories, t hen you could sort each cat egory by product nam e.) When you have m ore t han one group in t he " Group, Sort , and Tot al" pane, it 's im port ant t o m ake sure t hey're applied in t he right order. I f you t ry t o group a list of ordered it em s by cust om er and t hen by product cat egory, you'll get a different result from t he one you get if you group first by cat egory and t hen by cust om er. Figure 11- 26 illust rat es t he issue. Each group you add can have a header and foot er sect ion and it s own set of t ot als. You add t hese ingredient s using t he " Group, Sort , and Tot al" panej ust select t he appropriat e grouping level, click More, and t hen change t he various opt ions, as described in t he previous sect ion.

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-6.html (9 of 12) [1/7/2007 7:11:12 AM]

Section 11.6. Grouping

Figu r e 11-26. Access applies groups in a top-tobottom order. So in this example, the results are grouped by CustomerID, and then by OrderID. If you don't want this outcome, then select one of the grouping levels, and then click the up or down arrow button to move it. (To remove a grouping level altogether, select it and then press Delete.)

Figu r e 11-27. This report transforms order information into a printable invoice using grouping and a few other tricks you've seen already. The raw

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-6.html (10 of 12) [1/7/2007 7:11:12 AM]

Section 11.6. Grouping

information comes from the OrderDetails table (supplemented with information from the Orders, Product, and Customer tables). Line controls separate the different sections of the invoice, automatically generated totals tell you how much the order costs altogether, and expressions combine a few fields and add some extra text (like "Order History for" and "Order #"). This example's included in the Boutique Fudge database with the downloadable content for this chapter.

When you have m ore t han one level of grouping, you can hide som e of your inform at ion so you see j ust t he t ot als. I n Layout Grouping & Tot als Hide Det ails. I f you use t his t echnique on view, j ust choose Report Layout Tools | Form at t ing t he exam ple in Figure 11- 27, Access hides t he line- by- line order det ails, and all you'll see is t he t ot al for each order.

Tip: The invoice example creates a report that prints invoices for all the orders in your database. However, you can use filtering (Section 3.2.2) to filter down the results to a specific order or customer.

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-6.html (11 of 12) [1/7/2007 7:11:12 AM]

Section 11.6. Grouping

file:///C|/html/0596527608/access2007tm-CHP-11-SECT-6.html (12 of 12) [1/7/2007 7:11:12 AM]

Part IV: Building a User Interface with Forms

Part IV: Building a User Interface with Forms Ch a pt e r 1 2 : Cr e a t in g Sim ple For m s Ch a pt e r 1 3 : D e sign in g Adva n ce d For m s Ch a pt e r 1 4 : Bu ildin g a N a viga t ion Syst e m

file:///C|/html/0596527608/access2007tm-PART-IV.html [1/7/2007 7:11:14 AM]

Chapter 12. Creating Simple Forms

12. Creating Simple Forms So far, you've learned how t o creat e t ables t hat house your dat a, queries t hat search it , and report s t hat prepare it for print ing. You've also creat ed act ion queries t hat aut om at e big updat es. But your act ual dat abase users ( whet her t hat 's you or som eone else) will spend m ost of t heir t im e on an ent irely different j ob: daily dat abase upkeep. Dat abase upkeep includes reviewing, edit ing, and insert ing inform at ion. Real dat a- bases go t hrough t his process cont inuously. I n a t ypical day, t he st aff at Cacoph- oné St udios adds new st udent s, t he cust om er service depart m ent at Bout ique Fudge places new orders, and t he Got hic Wedding planners t weak t he seat ing arrangem ent s. Bobbleheads are bought , addresses are changed, purchases are logged, t est scores are recorded, and your dat a grows and evolves. You can perform your daily upkeep using t he dat asheet ( Chapt er 3) , but t hat isn't t he easiest approach. Alt hough t he dat asheet packs a lot of inform at ion int o a sm all space, it 's oft en awkward t o use, and it 's int im idat ing t o Access newcom ers. The solut ion is form s: specialized dat abase obj ect s t hat m ake it easier for anyone t o review and edit t he inform at ion in a t able.

Note: Remember, if you're using Access in a business environment, different people probably use your database. You may create it, but others need to be able to use it to perform a variety of tasksusually data entry and searches. These other folks may not be as Access-savvy as you are.

file:///C|/html/0596527608/access2007tm-CHP-12.html [1/7/2007 7:11:15 AM]

Section 12.1. Form Basics

12.1. Form Basics Form s get t heir nam e from paper form s t hat people use t o record inform at ion when a com put er isn't handy. Depending on your sit uat ion, you m ay creat e an Access form t hat resem bles a paper form t hat your com pany or organizat ion uses. I f you're working at a bank, you can creat e an Access form t hat lays out inform at ion in t he sam e basic arrangem ent as a paper- based cust om er applicat ion form . This arrangem ent m akes it easy t o copy inform at ion from t he paper int o your dat abase. However, m ost of t he t im e t he form s you design don't have a real- world equivalent . You'll creat e t hem from scrat ch, and use t hem t o m ake dat a ent ry easier. To underst and why form s are an indispensable part of alm ost all dat abases, it helps t o first consider t he dat asheet 's short com ings. Here are som e areas where form s beat t he dat asheet : ●







Be t t e r a r r a n ge m e n t s. I n t he dat asheet , each field occupies a single colum n. This arrangem ent works well for t ables wit h few fields, but leads t o endless side- t o- side scrolling in larger t ables. I n a form , you can m ake sure t he dat a you need is always in sight . You can also use color, lines, and pict ures t o help separat e different chunks of cont ent . Ex t r a in for m a t ion . You can pack a form wit h any t ext you want , which m eans you can add clues t hat help newbies underst and t he dat a t hey need t o supply. You can also add calculat ed det ailsfor exam ple, you can calculat e and display t he t ot al purchases m ade by a cust om er wit hout forcing som eone t o fire up a separat e query. Ta ble r e la t ion sh ips. Many t asks involve adding records t o m ore t han one relat ed t able. I f a new cust om er places an order in t he Bout ique Fudge dat abase, t hen you need t o creat e a new record in t he Cust om ers and Orders t ables, along wit h one or m ore records in t he OrderDet ails t able. A form let s you do all t his work in one place ( rat her t han forcing you t o open t wo or t hree dat asheet s) . Bu t t on s a n d ot h e r w idge t s. Form s support cont rolsbut t ons, links, list s, and ot her fancy pieces of user int erface m at t er you can add t o your form . The person using your dat abase can t hen click a but t on t o fire off a relat ed t ask ( like opening anot her form or print ing a report ) .

Properly designed form s are what t he geeks call a dat abase's front end. I n a dat a- base t hat uses form s, you can edit dat a, perform searches, and t ake care all of your day- t o- day t asks wit hout ever t ouching a dat asheet .

12.1.1. Creating a Simple Form As wit h report s, Access gives you an easy and a m ore advanced way t o const ruct a form . The easy way creat es a ready- m ade form based on a t able or query. Keen eyes will not ice t hat t his process unfolds in m ore or less t he sam e way as when you aut om at ically generat e a sim ple report ( Sect ion 10.1.1) . Here's how it works: 1. I n t h e n a viga t ion pa n e , se le ct t h e t a ble or qu e r y you w a n t t o u se t o ge n e r a t e t h e for m . Try t he Product s t able from t he Bout ique Fudge dat abase.

Note: If you create a form for a parent table that's linked to other tables, then you wind up with a slightly different type of form. If you create a form for the Categories table (a parent of the Products table), then you end up with a two-part form that lets you view and modify the category record and the linked product records in each category. You'll take a closer look at using forms with linked tables in Chapter 13 (Section 13.3.1). 2. Ch oose Cr e a t e

For m s

For m .

A new t ab appears, wit h your form in Layout view. The sim ple form shows one record at a t im e, wit h each field on a separat e line ( Figure 12- 1) . I f your t able has lot s of fields, t hen Access creat es m ore t han one colum n ( Figure 12- 2) .

file:///C|/html/0596527608/access2007tm-CHP-12-SECT-1.html (1 of 11) [1/7/2007 7:11:26 AM]

Section 12.1. Form Basics

Figu r e 1 2 - 1 . This simple form for the Products table already shows a fair bit of intelligence. Access uses text boxes for all the text fields, a drop-down list box for fields that have a lookup (in this case, ProductCategoryID), and a checkbox for any Yes/No field (like Discontinued). It also makes some boxes (like Description) larger than others, because it notices that the underlying field has a larger maximum allowable length (Section 2.3.1.1).

Figu r e 1 2 - 2 . In this form for the Customers table, Access can't fit all the fields using the ordinary one-field-perline arrangement. Instead, it adds a second column.

file:///C|/html/0596527608/access2007tm-CHP-12-SECT-1.html (2 of 11) [1/7/2007 7:11:26 AM]

Section 12.1. Form Basics

Tip: Good design practices pay off when you begin building forms. If your text fields store a far greater number of characters than they need (as controlled by the Field Size property described in Section 2.3.1.1), your form winds up with huge text boxes that waste valuable space. You need to resize them by hand.

When you first creat e a form , Access arranges t he fields from t op t o bot t om in t he sam e order in which t hey're defined in t he t able. I t doesn't m ake any difference if you've rearranged t he colum ns in t he dat asheet . However, Access leaves any colum ns you've hidden in t he dat asheet ( Sect ion 3.1.4) out of t he form .

Tip: You can add or remove fields in a form in the same way you do with a report. If the Field List pane isn't open, then choose Form Layout Tools Controls Add Existing Fields. Then, drag the field you want from the Field List pane onto the form. To remove a field, | Formatting click to select it on the form, and then press Delete. However, keep in mind that people often use forms to add records, and if you want to preserve that ability, you need to make sure your form includes all the required fields for the table. 3. Ar r a n ge t h e fie lds in t h e or de r you w a n t by dr a ggin g t h e m a r ou n d. Alt hough a sim ple form doesn't look like t he sim ple report s you learned about back in Chapt er 10, you can act ually work wit h it in m uch t he sam e way. One of t he easiest ways t o t ailor your form is t o drag fields from one place t o anot her ( Figure 12- 3) . 4. Ch a n ge you r colu m n s' w idt h s. When you creat e a new form in Layout view, Access m akes all t he fields quit e wide. Usually, you'll want t o shrink t hem down t o m ake your form m ore com pact . I t 's also hard t o read long lines of t ext , so you can show large am ount s of inform at ion bet t er in a narrower, t aller t ext box. To do so, j ust click t o select t he appropriat e field; a yellow rect angle appears around it . Then, drag one of t he edges. Figure 124 shows t his process in act ion.

Figu r e 1 2 - 3 . To move a field, drag it to a new position. Access reshuffles all the other fields accordingly. In this example, the Price field's being relocated to the top of the form, just under the ProductName field. Access bumps all the other fields down file:///C|/html/0596527608/access2007tm-CHP-12-SECT-1.html (3 of 11) [1/7/2007 7:11:26 AM]

Section 12.1. Form Basics

the page to make room.

Figu r e 12-4. Here, the Description field is being heightened to fit more lines of text at a time. You can also make a field wider or narrower, but there's a catchwhen you do so, it affects the entire column. In this report for the Products table, every field always has the same width. (You'll learn how to get around this limitation later in Section 12.3.)

Note: You may like to make a number of changes that you can't accomplish just by dragging, such as adding a new column or giving each field a different width. To make changes like these, you need to understand layouts, which are covered in Section 12.3. 5.

file:///C|/html/0596527608/access2007tm-CHP-12-SECT-1.html (4 of 11) [1/7/2007 7:11:26 AM]

Section 12.1. Form Basics

Opt ion a lly, you ca n click a fie ld h e a de r t o e dit it s t e x t . This opt ion let s you change Product Cat egoryI D t o j ust Cat egory. 6. Opt ion a lly, you ca n t w e a k t h e for m a t t in g t o m a k e t h e for m m or e a t t r a ct ive , by ch a n gin g fon t s a n d color s. You can m ost quickly change t he form at t ing of your form by select ing t he appropriat e part ( by clicking) , and t hen using Font sect ion. You can also use t he Form Layout Tools | t he but t ons in t he ribbon's Form Layout Tools | Form at t ing Form at t ing sect ion t o adj ust t he way Access shows num eric values. You learned about all your form at t ing Form at t ing opt ions in Sect ion 10.3.1 when you built basic report s. Oft en, you'll want t o form at specific fields different ly t o m ake im port ant inform at ion st and out . You can also form at t he t it le, header sect ion, and form background. Figure 12- 5 shows an exam ple of j udicious field form at t ing.

Figu r e 1 2 - 5 . You can select the field header (Price, for example) and the box with the field value separately, which means you can give these components different formatting. This form gives a shaded background fill to the Price, UnitsInStock, and UnitsOnOrder fields. It also gives a larger font size to the Price field and Price header, so this information stands out.

file:///C|/html/0596527608/access2007tm-CHP-12-SECT-1.html (5 of 11) [1/7/2007 7:11:26 AM]

Section 12.1. Form Basics

Tip: To select more than one part of a form at once, hold down Ctrl while you click. This trick allows you to apply the same formatting to several places at once.

I f you're in a hurry ( or j ust st ylist ically challenged) , t hen you can use a nift y Access feat ure called Aut oForm at t o apply a Aut o- Form at whole slew of relat ed form at t ing changes. Just m ake a choice from t he Form Layout Tools | Form at t ing sect ion ( which has t he sam e Aut oForm at choices you used wit h report s in Sect ion 10.3) . 7. Sa ve you r for m . You can save your form at any t im e by choosing Office but t on Access prom pt s you t o save it at t hat t im e.

Save. Or, if you close t he form wit hout saving it ,

12.1.2. Using a Form Now t hat you've creat ed your first form , it 's t im e t o t ake it for a t est spin. All form s have t hree different viewing m odes:

UP TO SPEED AutoNumber Fields in Forms The best way t o uniquely ident ify each record is wit h an Aut oNum ber field ( Sect ion 2.3.9) . When you insert a record, Access fills in a value for t he Aut oNum ber field. All t he t ables you'll see in t his book include a field nam ed I D t hat uses t he Aut oNum ber dat a t ype. Only Access can set an Aut oNum ber field. For t hat reason, you m ay not want t o show it in your form s. ( I f you decide not t o show it , j ust select it in Layout view and t hen press Delet e.) However, t here are som e reasons t hat you m ight act ually want t o keep t he Aut oNum ber field on display: ●



You u se t h e Au t oN u m be r fie ld on som e t ype of pa pe r w or k . Cacophoné St udios put s each st udent 's I D num ber on t heir regist rat ion papers. When you need t o look up t he st udent record lat er on, it 's easier t o use t he I D num ber t han search by nam e. You u se t h e Au t oN u m be r fie ld a s a t r a ck in g va lu e or con fir m a t ion n u m be r . Aft er you ent er a new order record in t he Bout ique Fudge dat abase, you can record t he order record's I D num ber. The next t im e you have a quest ion about t he order ( has it shipped?) , you can use t he I D num ber t o look it up. Depending on how you use t he I D num ber, you m ay choose t o place it at t he bot t om of t he form rat her t han in it s usual posit ion at t he t op. That approach avoids confusion. ( I t 's less likely t hat people will t ry t o t ype in t heir own I D num bers when t hey creat e new records.)

● ●



La you t vie w . This is t he view you've been using so far. I t let s you see what your form looks like ( wit h live dat a) , rearrange fields, and apply form at t ing. D e sign vie w . While Layout view provides t he sim plest way t o refine your form , Design view gives you com plet e power t o fine- t une it . I n Design view, you don't see t he live dat a. I nst ead, you see a blueprint t hat t ells Access how t o const ruct your form . You'll st art using Design view lat er in t his chapt er. For m vie w . Bot h Layout view and Design view are t here t o help you creat e and refine your form . But once you've perfect ed it , it 's t im e t o st op designing your form and st art using it t o browse your t able, review t he inform at ion it cont ains, m ake changes, and add new records.

Note: When you open a form by double-clicking it in the navigation pane, it opens in Form view. If you don't want this view, then right-click your form in the navigation pane, and then choose Layout View or Design View to start out in a different view.

To t ry out t he form you creat ed, swit ch it t o Form view if you're not already t here. Just right - click t he t ab t it le, and choose Form View. I n Form view, you can perform all t he sam e t asks you perform ed in t he dat asheet when you worked wit h a t able. Wit h a sim ple form , t he key difference is t hat you see only one record at a t im e.

file:///C|/html/0596527608/access2007tm-CHP-12-SECT-1.html (6 of 11) [1/7/2007 7:11:26 AM]

Section 12.1. Form Basics

Most people find form s m uch m ore int uit ive t han t he dat asheet grid. The following sect ions give a quick overview of how you can use Form view t o perform som e com m on t asks.

UP TO SPEED Different People, Different Forms I n m any sit uat ions, you'll want t o creat e m ore t han one form for t he sam e t able. That way, you can design form s t o help wit h specific t asks. At Bout ique Fudge headquart ers, a single person's in charge of set t ing prices. This individual ( known as t he Price Fudger) reviews t he product list every day, and t weaks t he prices based on t he current invent ory. To do t his, t he Price Fudger needs j ust t hree pieces of inform at ion for each product : t he field values for Product Nam e, Price, and Unit sI nSt ock. To st ream line t his process, you can creat e a form t hat includes j ust t hese det ails. To m ake t his form really pract ical, you can add som e feat ures t hat you haven't seen yet , but which are described lat er in t his chapt er. You can do t hings such as prevent changes in all t he fields except Price t o guard against accident al changes, you can pack several records ont o t he form for a quick, at - a- glance price set t ing, and you can filt er t he product list down t o leave out discont inued it em s. These st eps m ake t he form bet t er suit ed t o t he t ask at hand. And if you really want t o im press your fellow Access fans, t hen you can t hrow in t he m acro and code feat ures described in Part Five t o creat e but t ons t hat perform a t ask ( like j acking up a price by 10 percent ) aut om at ically. I t 's up t o you how m any form s you want t o creat e. Som e people t ry t o creat e as few form s as possible and m ake t hem flexible enough t o work for a variet y of different t asks. Ot her people creat e dozens of specialized form s t hat can save t im e. I n a large com pany like Bout ique Fudge, each depart m ent ( like sales, shipping, cust om er service, and so on) will probably use it s own t ailored form . Every form guides em ployees t o do exact ly what t hey need t o do ( and st ops t hem from doing what t hey shouldn't ) .

12.1.2.1. Finding and editing a record Rare is t he record t hat never changes. Depending on t he t ype of dat a you're st oring, m ost of your work in Form view m ay consist of hunt ing down a specific record and m aking m odificat ions. You m ay need t o rat chet up t he price of a product , change t he address det ails of an it inerant cust om er, or reschedule a class. Before you can m ake any of t hese changes, you need t o find t he right record. I n Form view, you have four ways t o get t o t he record you need. The first t hree of t hese m et hods use t he navigat ion cont rols t hat appear at t he bot t om of t he form window. ●





By n a viga t in g. I f your t able's relat ively sm all, t hen t he fast est way t o get going is t o click t he arrow but t ons t o m ove from one record t o t he next . Sect ion 3.2 has a but t on- by- but t on breakdown. By posit ion . I f you know exact ly where your record is, t hen you can t ype in t he num ber t hat represent s t he posit ion ( for exam ple, 100 for t he one- hundredt h record) , and t hen hit Ent er. I f you don't get exact ly where you want , t hen you can also use t he navigat ion but t ons t o m ove t o a nearby record. By se a r ch in g. The quick search feat ure finds a record wit h a specific piece of t ext ( or num eric value) in one of it s fields. To use quick search, t ype t he t ext you want t o find in t he search box, as shown in Figure 12- 6. I f you want a search t hat exam ines a specific field or gives you addit ional opt ions, t hen use t he Hom e Sect ion 3.2.3.

Find

Find com m and, which is described in

Figu r e 12-6. When you use file:///C|/html/0596527608/access2007tm-CHP-12-SECT-1.html (7 of 11) [1/7/2007 7:11:26 AM]

Section 12.1. Form Basics

the quick search box, you don't need to hit Enter. Access finds the next match as you type.



By filt e r in g. Using filt ering, you can narrow down t he displayed records t o a sm all set . Filt ering's best - kept secret 's t hat you can use a feat ure called filt er by form t o quickly hunt down a single record. You'll see how t hat works in Sect ion 12.2.2.

Once you've found t he record you want t o change, you can edit it in t he sam e way you would in t he dat asheet . I f you m ake a change t hat breaks a rule ( like t yping t he t ext " Exasperat ed Bananas" in a dat e field) , t hen you get t he sam e fam iliar error m essages. Access com m it s any change you m ake as soon as you m ove t o anot her record or field. To back out of a change, hit Esc before you m ove on. When you do, t he original value reappears in t he cell, and Access t osses out your changes. And if you do com m it a change by accident , t hen you can use t he Undo but t on in t he Quick Access t oolbar ( above t he ribbon) , or hit Ct rl+ Z, t o reverse it .

12.1.2.2. Adding a record As you already know, you add a new record in dat asheet view by scrolling t o t he very bot t om of t he t able, and t yping j ust underneat h t he last row. I n Form view, t he concept 's sim ilarscroll t o t he very end of your t able, j ust past t he last record. You'll know you've reached t he m agic ready- t o- add- a- record spot when all t he fields in your form are blank ( Figure 12- 7) . To save yourself t he scrolling t rip, use t he New Record but t on at t he bot t om of t he form ( m arked in Figure 12- 7) . I f you've decided t hat you don't want t o add a new record aft er all, t hen hit Esc t wice. The first t im e you press Esc, Access wipes out t he value in t he current field.

file:///C|/html/0596527608/access2007tm-CHP-12-SECT-1.html (8 of 11) [1/7/2007 7:11:26 AM]

Section 12.1. Form Basics

Figu r e 12-7. When you create a new record, you start off with a clean slate that shows your form's formatting but no values. If you've set any default values for the table (Section 4.1.2), then you see them appear instead of the blank values. In the Products table, the UnitsInStock field has a default value of 10.

The second t im e, Access rem oves all t he ot her values you ent ered. Now t hat your form 's been rest ored t o it s original em pt iness, you can safely scroll off t o anot her record. I f you scroll away from your new record while t here's st ill som e dat a left in it , t hen Access creat es t he new record and adds it t o t he t able. You can't reverse t his act ion. I f you want t o get rid of a newly creat ed record, t hen you need t o delet e it , as described in t he next sect ion.

12.1.2.3. Deleting a record When you find a record t hat shouldn't exist , you can wipe it out in seconds. The easiest way t o delet e t he current record is Records Delet e. But you have anot her opt ion. You can select t he whole record by clicking t he m argin t o choose Hom e on t he form window's left side. Then you can liquidat e it by pressing Delet e. No m at t er what approach you use, Access asks you for confirm at ion before it rem oves a record. You can't recover delet ed records, so t read carefully.

12.1.2.4. Printing records Here's a lit t le- known secret about form s: You can use t hem t o creat e a quick print - out . To do so, open your form , and t hen Print . The fam iliar Print dialog box appears, where you can choose your print er and t he num ber of choose Office but t on copies you want .

file:///C|/html/0596527608/access2007tm-CHP-12-SECT-1.html (9 of 11) [1/7/2007 7:11:26 AM]

Section 12.1. Form Basics

GEM IN THE ROUGH Showing Pictures from a Database As you learned in Chapt er 2, you can st ore a pict ure file as part of a record using t he At t achm ent dat a t ype. Form s handle at t achm ent s gracefully using t he At t achm ent cont rol. The At t achm ent cont rol has one t ruly useful perkit shows pict ure cont ent direct ly on your form . Here's how it works. I f your at t achm ent field st ores a pict ure, t hen t hat pict ure appears in t he At t achm ent cont rol box so you can adm ire it right on your form . This behavior's a great im provem ent over t he dat asheet , which forces you t o open t he pict ure file in anot her program t o check it out . Even bet t er, if t he at t achm ent field st ores m ore t han one pict ure, t hen you can use t he arrows on t he handy pop- up m inibar t o m ove from one im age t o t he next , as shown in Figure 12- 8. As you know, at t achm ent fields can st ore any t ype of file. I f you're not st oring a pict ure, t hen t he At t achm ent cont rol isn't nearly as useful. All you see's an icon for t he program t hat owns t hat file t ype. I f your at t achm ent field cont ains a Word docum ent , t hen you see a Word icon. I f it cont ains a t ext docum ent , t hen you see a Not epad icon, and so on. I f your at t achm ent fields don't include pict ures, you m ay as well resize t he box for t he At t achm ent cont rol so t hat it 's j ust large enough t o display t he file t ype icon. There's no reason t o m ake it any bigger, because t he rest of t he space will be wast ed.

Figu r e 1 2 - 8 . Top: Here, the Picture field shows a bobblehead doll's picture. Access sizes the picture to fit the Attachment control box (without unnaturally stretching or skewing the picture). Bottom: When you select the Picture field, you see a minibar with additional options appear right above the image. The arrows let you step through all the attached files for this record. The paper clip icon opens the Attachments window, where you can add or remove attachments, or open them in a different program. (The Attachments window's described in Section 2.3.8.)

When you print a form , Access print s all t he records, one aft er t he ot her. I f you want t o print j ust t he current record, t hen, in t he Print dialog box, choose t he Select ed Records opt ion before you click OK. You can also use Office but t on 9) . Click Print Preview

Print

Close Preview

Print Preview t o check out t he result before you send it t o t he print er ( Figure 12Close Print Preview t o ret urn t o your form .

file:///C|/html/0596527608/access2007tm-CHP-12-SECT-1.html (10 of 11) [1/7/2007 7:11:26 AM]

Section 12.1. Form Basics

Figu r e 12-9. This preview shows what you'll get if you print the CustomerList form. The printout closely matches the form, with the same formatting and layout. When Access first creates the form, it gives it the same width as an ordinary sheet of paper. When you print the form, Access crams as many recordsthree in this caseas it can fit on each page.

Alt hough you m ight be t em pt ed t o use form s as a convenient way t o creat e snazzy print out s, you'll always get m ore feat ures and bet t er cont rol if you use report s.

file:///C|/html/0596527608/access2007tm-CHP-12-SECT-1.html (11 of 11) [1/7/2007 7:11:26 AM]

Section 12.2. Sorting and Filtering in a Form

12.2. Sorting and Filtering in a Form Sort ing and filt ering are t wo indispensable feat ures t hat Access gives you wit h Form view. Learning how t o use t hem could hardly be easierin fact , you already learned everyt hing you need t o know when you t ackled t he dat asheet in Chapt er 3. The creat ors of Access t ook great care t o ensure t hat filt ering and sort ing work t he sam e in form s as t hey do in t he dat asheet . You use t he sam e com m ands, on t he sam e part of t he ribbon, t o put t hem int o act ion.

12.2.1. Sorting a Form As you've probably realized by now, form s show your dat a in raw, unsort ed order. So records appear in t he order you creat ed t hem . ( The only except ion's if you creat e a form t hat get s it s dat a from a query, and t hat query uses sort ing.) Fort unat ely, sort ing's easy. I n fact , you can sort t he records t hat are shown in a form in exact ly t he sam e way you sort records in a dat asheet . Choose t he field you want t o use for sort ing, right - click it , and t hen choose one of t he sort ing opt ions. I n a t ext - based field, you'll see t he sort ing choices " Sort A t o Z" ( for an alphabet ical sort ) and " Sort Z t o A" ( for a reverseSort & Filt er sect ion. alphabet ical sort ) . You can also use t he Ascending and Descending but t ons on t he ribbon's Hom e For m ore inform at ion about your sort ing opt ions ( including how t o sort by m ult iple fields) , see Sect ion 3.2.

12.2.2. Filtering a Form Filt ering's a feat ure t hat let s you cut down t he t ot al num ber of records so you see only t hose t hat int erest you. Filt ering can pick out act ive cust om ers, in- st ock product s, expensive orders, and ot her groups of records based on specific crit eria. I n a form , you have t he following filt ering choices: ●







Qu ick filt e r shows you a list of all t he values for a part icular field and let s you choose which ones you want t o hide. I t 's easy t o use, but pot ent ially t im e- consum ing. I f you want t o hide num eric values t hat fall int o a cert ain range, t hen you'll get t he j ob done m uch fast er wit h t he " filt er by condit ion" approach ( as described lat er) . To show t he list of quick filt er values, m ove t o Sort & Filt er Filt er. Sect ion 3.2.2.1 has full det ails about quick filt ers. t he field you want t o filt er, and t hen click Hom e Filt e r by se le ct ion applies a filt er based on an exist ing value. First , find t he value in one of t he records, right - click it , and t hen choose a filt er opt ion. You can right - click a price value of $25, and t hen choose " Great er Than or Equal t o 25" t o hide lowcost it em s. For m ore inform at ion, see Sect ion 3.2.2.2. Filt e r by con dit ion let s you define t he exact crit eria you want t o use t o filt er records. You don't need t o base it on an exist ing value. To add t his sort of filt er, right - click t he field and t hen look for a subm enu wit h filt ering opt ions. This m enu it em 's nam ed according t o t he dat a, so t ext fields include a Text Filt ers opt ion, num ber fields have a Num ber Filt ers opt ion, and so on. You can learn m ore about t his t ype of filt er in Sect ion 3.2.2.3. Adva n ce d filt e r s are filt ers t hat you design using a window t hat looks j ust like t he query designer. The advant age of advanced filt ers is t hat you can apply filt ers on m ore t han one field in a single st ep. To creat e a set of advanced filt ers, Sort & Filt er Advanced Filt er Opt ions Advanced Filt er/ Sort . choose Hom e

Note: If you insert a new record that doesn't match the currently active filter conditions, your new record disappears from sight as soon as you add it. To get it back, remove the filter settings using the ribbon: Select the Home tab, click the Advanced button in the Sort & Filter chunk, and then choose Clear All Filters. Or, use the Toggle Filter button to temporarily suspend your filter settings (and click Toggle Filter later to get them back).

12.2.3. Using the Filter by Form Feature One ot her filt ering t echnique works wit h form s: filt er by form . Essent ially, " filt er by form " t ransform s your form int o a fullfledged search form . Using t his search form , you supply one or m ore crit eria. Then you apply t he filt er t o see t he m at ching record ( or records) . Alt hough you can use " filt er by form " wit h t he dat asheet , it really shines wit h form s. " Filt er by form s" is part icularly useful for searching out a single hard- t o- find record. ( I f you want t o use filt ering t o pull out a whole group of records, one of t he ot her filt ering opt ions is generally easier.) Here's how t o use t he " filt er by form " feat ure: 1.

file:///C|/html/0596527608/access2007tm-CHP-12-SECT-2.html (1 of 5) [1/7/2007 7:11:31 AM]

Section 12.2. Sorting and Filtering in a Form

Ch oose H om e

Sor t & Filt e r

Adva n ce d Filt e r Opt ion s

Filt e r By For m .

Access changes your form t o search m ode. I n search m ode, your form looks exact ly t he sam e, except all t he fields are blank. I f you've already used t he " filt er by form " feat ure and you're ret urning t o change t he filt er set t ings, t hen you should st art by clearing t he previous set of filt ers. To do so, right - click a blank spot on t he form surface, and t hen choose Clear Grid. 2. M ove t o t h e fie ld you w a n t t o u se for filt e r in g. A drop- down arrow appears in t he field. 3. Click t h e dr op- dow n a r r ow , a n d t h e n ch oose t h e va lu e you w a n t t o in clu de in you r r e su lt s. The drop- down list shows all t he values from t he different records in t he t able ( Figure 12- 10) . When you choose one, it appears in t he field box in quot at ion m arks. 4. I f you w a n t t o a pply a filt e r t o m or e t h a n on e fie ld, t h e n r e t u r n t o st e p 2 . Use m ult iple filt er condit ions if a single filt er condit ion m ay result in m ore m at ches t han you want . I f you don't rem em ber a cust om er's last nam e, you could apply a First Nam e filt er. But if t hat cust om er has a com m on first nam e, t hen you m ay also want t o apply a filt er on anot her field, like Cit y. I f you don't want t o use exact m at ches, t hen you can writ e in m ore com plex filt ers using an expression. Use < 10 t o find num eric values under 10, and Like Jon* t o find t ext values like " Jones," " Jonat hon," and " Jonson." Filt ering's part icularly useful wit h dat e fields. Sect ion 6.2.1.1 has t he full scoop on filt ering expressions. 5. I f you w a n t t o pe r for m m or e t h a n on e filt e r in g ope r a t ion a n d com bin e t h e r e su lt s, t h e n click t h e Or t a b a n d fill ou t m or e filt e r se t t in gs ( Figu r e 1 2 - 1 1 ) . I f you fill out your first search form so t hat it m at ches t he Last Nam e " Gorfinkel," and t he second search form t o m at ch t he First Nam e " Jehosophat ," your result s will include all t he records t hat have t he last nam e Gorfinkel and all t hose t hat have t he first nam e Jehosophat . However, if you put bot h t hose filt er condit ions on t he sam e search form , your m at ches include only people nam ed Jehosophat Gorfinkel.

Figu r e 12-10. Here's the Customers form in "filter by form" mode. Using the dropdown list, you can quickly find a customer by last name. Or you can file:///C|/html/0596527608/access2007tm-CHP-12-SECT-2.html (2 of 5) [1/7/2007 7:11:31 AM]

Section 12.2. Sorting and Filtering in a Form

find a name by typing the first few letters rather than scrolling through the list, as shown here. In this example, typing "Ra" brings up the first alphabetical match: the last name Randawa.

Figu r e 12-11. The Or tab appears at the bottom of the form. When you click the Or tab, a second copy of your search form appears, where you can fill out additional filter conditions. Each time file:///C|/html/0596527608/access2007tm-CHP-12-SECT-2.html (3 of 5) [1/7/2007 7:11:31 AM]

Section 12.2. Sorting and Filtering in a Form

you click the Or tab, another Or tab appears. You can repeat this process to fill in a dozen search forms at once, but there's rarely any reason to go to such lengths.

6. Righ t - click a bla n k spot on t h e for m su r fa ce , a n d t h e n ch oose Apply Filt e r / Sor t . Access swit ches back t o your norm al form , and t hen applies t he filt er set t ings. At t he bot t om of t he form , bet ween t he navigat ion but t ons and t he search box, you see t he word " Filt ered" appear t o let you know t hat you aren't seeing all t he records. I f you decide not t o apply t he filt er set t ings, j ust close t he search form . Access swit ches back t o your norm al form but doesn't apply any filt ering.

Tip: To remove your filter settings but keep them handy for later use, choose Home

Sort & Filter

Toggle Filter. To reapply the

filter settings later on, click Toggle Filter a second time. Access stores the most recent filter settings with your form, so they're always available.

12.2.4. Saving Filters for the Future One of form filt ering's lim it at ions is t hat Access rem em bers only your m ost recent set of filt ers. I f you've perfect ed a com plex filt er expression t hat you want t o reuse lat er, t his qualit y's a problem . As soon as you apply a different filt er, you'll lose all your hard work. Fort unat ely, you have several solut ions t o t his dilem m a. One opt ion's t o creat e a whole new query t hat perform s t he filt ering, and use t hat query in a whole new form . This choice is a good one if you want t o use your filt er crit eria t o perform a specific t ask, and you also want t o cust om ize t he way t he form works or t he way it displays it s dat a. On t he ot her hand, if you don't plan t o use your filt ering set t ings very oft en, but you j ust want t o have t hem on hand for t he next t im e you need t hem ( or if you need t o st ore dozens of different filt er set t ings, and you don't want t o be st uck wit h dozens of nearly ident ical form s) , t here's a bet t er opt ion. You can save your filt er set t ings as a query in your dat abase. Then, when you want t hem back, you can load t hem up and apply t hem t o your form .

file:///C|/html/0596527608/access2007tm-CHP-12-SECT-2.html (4 of 5) [1/7/2007 7:11:31 AM]

Section 12.2. Sorting and Filtering in a Form

Here's how t o pull t his t rick off: 1. Apply you r filt e r s. Use any of t he t echniques described in Sect ion 12.2.2. 2. Ch oose H om e

Sor t & Filt e r

Adva n ce d

Adva n ce d Filt e r / Sor t .

This act ion opens a query window. This query uses t he sam e dat a source ( t able or query) as your form , and it applies your filt ering using t he Crit eria box under t he appropriat e field ( Sect ion 6.2.1) . You don't need t o m ake any changes in t he query window because Access aut om at ically fills in t he Crit eria box ( or boxes) based on t he current filt er set t ings. 3. Ch oose H om e

Sor t & Filt e r

Adva n ce d

Sa ve a s Qu e r y. Su pply a n a m e for t h is qu e r y, a n d t h e n click OK.

Alt hough you can use t his query like a norm al query, you probably won't . So t o prevent confusion, use a different t ype of nam e, like Cust om erBrowser_Filt er, t hat clearly indicat es t his query's designed for form filt ering. The next t im e you want t o ret rieve your filt er set t ings and reapply t hem , open your form and follow t hese st eps: 1. Ch oose H om e

Sor t & Filt e r

Adva n ce d

Adva n ce d Filt e r / Sor t .

Adva n ce d

Loa d Fr om Qu e r y.

This act ion shows t he query window. 2. Ch oose H om e

Sor t & Filt e r

Access shows all t he queries t hat use t he sam e t able and don't involve j oins. 3. Pick t h e filt e r qu e r y you cr e a t e d e a r lie r , a n d t h e n click OK. The filt er set t ings for t hat query appear in t he query window. 4. Righ t - click a n yw h e r e on t h e bla n k spa ce in t h e qu e r y w in dow , a n d t h e n ch oose Apply Filt e r / Sor t t o pu t you r filt e r se t t in gs in t o e ffe ct .

Tip: You can use this trick to apply the same filter expression to different forms, as long as these forms include the fields you want to filter. (You can use the filter settings that you created for the Customer-Browser form to filter another form that shows a list of customers, but not a form that shows products.)

file:///C|/html/0596527608/access2007tm-CHP-12-SECT-2.html (5 of 5) [1/7/2007 7:11:31 AM]

Section 12.3. Creating Better Layouts

12.3. Creating Better Layouts So far, all t he form s you've been creat ing look fairly sim ilar: All t he fields get channeled int o one or m ore colum ns of t ight ly packed inform at ion. I n m any cases, t hat syst em works perfect ly fine. But som et im es you want t o let your inner form designer com e out and play. You've already seen t his idea wit h report s in Chapt er 11. Once you break a report out of it s layout t able, you can creat e a print out t hat looks m ore like a ret ail product cat alog t han a drab t able of inform at ion. The sam e principle's at work wit h form sonce you decide t o leave t he Sim ple World of Sim ple Form s, you can creat e form s t hat are a lot m ore original. You can creat e form s t hat use whit e space t o break up dense groupings of inform at ion; form s t hat add graphical frills like pict ures, lines, and rect angles; form s t hat pack inform at ion m ore t ight ly or m ore loosely; form s t hat resem ble t he paper docum ent s t hey're based on; and so on.

12.3.1. Liberating Controls from Layouts Like report s, form s use a helpful feat ure called a layout : a form at t ing cont ainer t hat Access uses behind t he scenes t o arrange a group of cont rols. I f you widen one field in a layout , all t he ot her fields in it are widened as well. I f you m ove a layout , all t he cont rols m ove along wit h it . And if you rearrange a layout , all t he cont rols m aint ain a consist ent am ount of spacing.

Note: Remember, controls (Section 11.1.2) are the ingredients you can add to a form or report. Controls include things like labels, pictures, and text boxes. You use some controls to display fixed content (like your form title), while others have dynamic content (like the field values from the current record).

I f you want t o be able t o arrange your cont rols precisely, t hen you need t o st art by rem oving t hem from t he layout . ( And, as wit h report s, it t akes a fair am ount of t im e t o place each cont rol by hand and st ill m ake sure t hings looks nice.) Before you pull a cont rol out of it s layout , m ake sure you're in Layout view or Design view ( by right - clicking t he t ab t it le, and t hen choosing Layout View or Design View) . Layout view's a bit nicer t o look at , but Design view m akes it a bit easier t o m ove your fields. When you drag a field capt ion ( like t he label t hat cont ains t he word " Product Nam e" ) in Design view, t he linked cont rol t hat shows t he field value m oves along wit h it . I n Layout view, you need t o m ove bot h pieces separat ely, which m akes for t wice as m uch work. ( I ncident ally, you can drag t he capt ions and field boxes separat ely in Design view t oo, if you underst and where t o click. Sect ion 11.1.5 explains.)

Rem ove. Finally, drag t he To act ually rem ove a field, right - click t he field you want t o reposit ion, and t hen choose Layout field t o it s new locat ion. Figure 12- 12 shows an exam ple of aform t hat doesn't use layout s for any of it s cont rols.

Figu r e 1212. The weird staggered effect shown here wouldn't be possible with the rigid tablebased structure of a layout. But you

file:///C|/html/0596527608/access2007tm-CHP-12-SECT-3.html (1 of 12) [1/7/2007 7:11:42 AM]

Section 12.3. Creating Better Layouts

pay a price for this design (and it's not just eye strain). If you ever modify the table and need to update the form, then you'll have more work to rearrange the fields, since there's no layout behind the scenes holding them all together.

12.3.2. Using More Than One Layout As you learned earlier in t his chapt er, Access arranges fields int o m ore t han one colum n if it can't fit t hem all in j ust one ( as shown in Figure 12- 2) . When Access creat es m ult iple colum ns, each colum n's act ually a separat e layout . Great news: You t oo can creat e m ult iple layout s. You m ight want t o for several reasons, including: ● ● ●

To a r r a n ge you r fie lds in side - by- side colu m n s. You do t his by placing one lay- out next t o anot her. To a r r a n ge you r fie lds in t o se ve r a l discr e t e gr ou ps. These fields can appear in different places on t he form . You could have one group at t he t op and one group at t he bot t om , separat ed by ot her cont ent . To give diffe r e n t w idt h t o diffe r e n t fie lds. All t he fields in a layout have t he sam e widt h. I f you place your fields int o different layout s, t hey can have different widt hs.

To place fields int o a new layout , follow t hese st eps: 1. M a k e su r e you 'r e in La you t vie w . I f not , right - click t he form 's t ab t it le, and t hen choose Layout View. 2.

file:///C|/html/0596527608/access2007tm-CHP-12-SECT-3.html (2 of 12) [1/7/2007 7:11:42 AM]

Section 12.3. Creating Better Layouts

Righ t - click t h e fir st fie ld you w a n t t o r e m ove , a n d t h e n ch oose La you t

Re m ove .

I f t he field's inside t he m iddle of a layout t able, Access pops it off t o t he side. I f t he field's at t he end of t he layout t able, it s posit ion doesn't change. 3. D r a g you r fie ld off t o a n ot h e r pa r t of t h e for m . I f you want t o place your second layout beneat h t he first , t hen drag t his field down t he form t o it s new posit ion. 4. Righ t - click t h e fie ld you 've r e m ove d, a n d t h e n ch oose La you t

St a ck e d.

This act ion creat es a new layout for t he field you cut loose in st ep 2. All t he layout s you've seen so far are st acked, which m eans t he fields appear one on t op of t he ot her. You'll see an exam ple of t abular ( side- by- side) layout in t he next sect ion. 5. Fin d on e of t h e fie lds you w a n t t o m ove in t o t h e n e w la you t , a n d t h e n dr a g it dow n t h e r e ( Figu r e 1 2 - 1 3 ) . Dragging a field from one layout t o anot her's a short cut . I t 's fast er t han rem oving all t he fields you want from t he first layout , and t hen adding t hem t o t he second layout .

Figu r e 1 2 - 1 3 . As your mouse cursor passes over the new layout you've just created, a yellow line appears showing where the field will be placed if you release the mouse button. You can drop a field at the top of the layout, at the bottom, or anywhere inside. In this example, the PostalCode field's being placed between the State and Country fields.

6. Re pe a t st e p 5 for e a ch of t h e fie lds you w a n t in t h e n e w la you t . Moving fields bet ween layout s can be a bit t ricky. I f everyt hing goes wonky and a field lands in t he wrong place, t hen j ust use t he Undo feat ure t o put t hings right . ( Undo an act ion by pressing Ct rl+ Z, or by clicking t he Undo but t on in t he Quick Access t oolbar above t he ribbon.) 7. W h e n you 've pe r fe ct e d you r se con d la you t , m ove it t o t h e cor r e ct posit ion .

file:///C|/html/0596527608/access2007tm-CHP-12-SECT-3.html (3 of 12) [1/7/2007 7:11:42 AM]

Section 12.3. Creating Better Layouts

To m ove your layout , click one of t he fields and t hen look for t he four- way- arrow icon in t he t op- left corner. Drag t hat icon t o m ove t he whole layout . Be carefulif you place a layout t oo close t o anot her layout , t hen Access assum es you want t o m erge t hem int o a single layout . ( You can hold down t he Ct rl key while you drag t o t ell Access not t o do t his.) Figure 12- 14 shows a finished form wit h several layout s.

12.3.3. Using Tabular Layouts Layout s can organize cont rols in t wo different ways: in st acked groups ( where each field's in a separat e row) and in t ables ( where each field's placed in a separat e colum n) . Usually, st acked group layout s are m ore useful for form s, while t abular layout s m ake sense for densely packed report s. However, you m ay occasionally choose t o use a t abular layout in a form . You'd do t his m ost oft en when you want t o show m ore t han one record at a t im e; it 's oft en easier t o fit m ore onscreen when you pack fields int o colum ns.

Tip: Although a form can contain several of both types of layout (tabular and stacked), they rarely fit well together. So pick one and stick with it.

To change an ordinary form ( wit h a st acked layout ) so t hat it uses a t abular layout , follow t hese st eps: 1. M a k e su r e you 'r e in La you t vie w . I f not , right - click t he t ab t it le, and t hen choose Layout View.

Figu r e 12-14. This form groups fields into four neat subsections. It adds a clearer, more structured organization than a single layout table but dodges the complexity of creating a form without any layouts, especially if you need to add more fields or change their order later on.

file:///C|/html/0596527608/access2007tm-CHP-12-SECT-3.html (4 of 12) [1/7/2007 7:11:42 AM]

Section 12.3. Creating Better Layouts

2. Se le ct a ll t h e fie lds on you r for m by h oldin g dow n Sh ift a n d click in g t h e m on e a t a t im e . To save som e t im e, look for t he four- way- arrow icon t hat appears at a layout 's t op- right corner when you select som et hing inside it . You can click t his icon t o select t he whole layout in one shot . 3. Righ t - click you r se le ct ion , a n d t h e n ch oose La you t

Ta bu la r .

When creat ing a t abular layout , Access put s each field capt ion in t he form 's header area and t he corresponding field value underneat h, as shown in Figure 12- 15. You'll need t o perform som e drag- and- drop fiddling t o get all t he fields in t he right order, and t o m ake t hem t he right sizes. This process is a bit awkward. Fort unat ely, t here's a short cut . I f you know you want t o use a t abular layout , t hen you can Form s Form t o creat e your form , choose Creat e creat e one from t he beginning. I nst ead of choosing Creat e Mult iple I t em s. Doing so creat es a form t hat uses a t abular layout and shows m ore t han one record at a t im e Form s ( Figure 12- 16) .

Figu r e 12-15. This tabular layout shows four columns of information. This form's got one layout-less control: the box for the Notes field, which the person designing this form has moved down to make room.

Figu r e 1216. Usually, tabular file:///C|/html/0596527608/access2007tm-CHP-12-SECT-3.html (5 of 12) [1/7/2007 7:11:42 AM]

Section 12.3. Creating Better Layouts

layouts go handin-hand with forms that show lots of records at once, like the form shown here.

12.3.4. Showing Multiple Records in any Form You can show m ore t han one record in a form even if you don't use a t abular layout . I n fact , as long as your form 's fairly com pact , it 's easy. Here's how: 1. Ar r a n ge you r for m so t h a t it 's a s com pa ct a s possible . When showing m ult iple records, t hey're placed one above t he ot her, as shown in Figure 12- 17. So t he short er you m ake your form , t he m ore records you can see at once. On t he ot her hand, it doesn't m at t er how wide or narrow your form is ( so long as everyt hing fit s on your screen at once) .

Figu r e 1217. Now you can see three products all on the same screen. (Notice how the bottom three fields have been removed from the top three

file:///C|/html/0596527608/access2007tm-CHP-12-SECT-3.html (6 of 12) [1/7/2007 7:11:42 AM]

Section 12.3. Creating Better Layouts

fields' stacked layout so they can fit more tightly together.) The arrow in the margin indicates that the second record's the current record. To see more records, you can use the familiar record navigation buttons at the bottom of the form, or you can use the scroll bar on the right.

2. Sw it ch t o D e sign vie w , if you 'r e n ot t h e r e a lr e a dy. As always, you can swit ch t o Design view by right - clicking t he t ab t it le and t hen choosing Design View. 3. Re size you r for m so t h e r e 's n o bla n k spa ce , a s sh ow n in Figu r e 1 2 - 1 8 . As you rearrange your cont rols, you'll free up space at t he bot t om of your form . However, it 's up t o you t o reclaim t his space by shrinking t he overall form . I f you t ry t o shrink a form but it rem ains st ubbornly locked in place, t here's probably a cont rol on t he form t hat ext ends int o t hat space. You need t o shrink t he cont rol first and t hen t he form .

file:///C|/html/0596527608/access2007tm-CHP-12-SECT-3.html (7 of 12) [1/7/2007 7:11:42 AM]

Section 12.3. Creating Better Layouts

Figu r e 121 8 . To shrink the form, drag the bottom border up, until it reaches the bottom of the lowest control.

Note: In order to fit more than one record into view at once, the form window needs to be larger than the actual form. 4. I f t h e Pr ope r t y Sh e e t isn 't visible , t h e n ch oose For m D e sign Tools | D e sign

Tools

Pr ope r t y Sh e e t .

As you learned in Chapt er 11, t he Propert y Sheet let s you t weak t he set t ings for cont rols and ot her it em s. I n t his case, t he set t ing you need t o change isn't available in t he ribbon. I nst ead, it 's buried in t he Propert y Sheet . 5. I n t h e Pr ope r t y Sh e e t list box , ch oose For m . This act ion shows set t ings t hat apply t o t he ent ire form , not j ust a single cont rol. 6. Click t h e For m a t t a b, a n d t h e n fin d t h e D e fa u lt Vie w se t t in g. The Default View set t ing appears near t he t op of t he list . I t let s you cont rol how t he form appears when you first open it . 7. Ch oose Con t in u ou s For m . The m ost com m on opt ions are Single Form ( which shows a single record of inform at ion) , and Cont inuous Form ( which shows m ult iple records, one aft er t he ot her) . You can also choose a non- Form view, like Dat asheet ( t he boring spreadsheet like t ables you learned about in Chapt er 3) , Pivot Table, or Pivot - Chart . Finally, you can use Split Form for a view t hat com bines t he dat asheet wit h your cust om form . You'll learn m ore about t his opt ion in t he next sect ion. 8. Opt ion a lly, se t t h e D ividin g Lin e s pr ope r t y t o Ye s t o sh ow a t h in h or izon t a l lin e be t w e e n e a ch r e cor d. Now, when you swit ch back t o Form view, you'll see several records at once, provided t hey fit int o t he window.

12.3.5. Split Forms Bot h single- record view and m ult iple- record view have t heir advant ages. Wit h single- record view, you have plent y of room

file:///C|/html/0596527608/access2007tm-CHP-12-SECT-3.html (8 of 12) [1/7/2007 7:11:42 AM]

Section 12.3. Creating Better Layouts

t o exam ine one record, and you don't get dist ract ed by onscreen clut t er. Wit h m ult iple- record view, you can com pare t he current record t o ot her nearby records. Access has a t ype of form t hat let s you get t he best of bot h worlds: split form s. Split form s com bine t wo views of your dat a in one form . The idea's t hat you can use t he dat asheet t o scroll t hrough all your records, and use t he form t o view or edit a recordbut all in t he sam e window. Figure 12- 19 shows an exam ple.

Note: Usually, you'll use the datasheet to move to the record you want to edit and the form to review or edit it, but that way's not necessaryyou can change records in the datasheet, and you can navigate using the navigation buttons at the bottom of the form.

Figu r e 12-19. The most common type of split form puts the datasheet section at the top. The currently selected record's shown underneath. You can change the size of each portion by dragging the splitter bar that's in between.

I t 's easy t o creat e a split form all you need t o do is, on t he ribbon, choose Creat e Form s Split Form . However, you need t o know a lit t le bit m ore if you want t o convert an exist ing form int o a split form , or if you want t o change how Access present s t he t wo sect ions of a split form . The secret lies in changing t he form set t ings using t he Propert y Sheet . Here's how: 1. Sw it ch you r for m t o D e sign vie w . 2. I f t h e Pr ope r t y Sh e e t isn 't a lr e a dy visible , t h e n sh ow it by ch oosin g For m D e sign Tools | D e sign Pr ope r t y Sh e e t . 3. I n t h e Pr ope r t y Sh e e t dr op- dow n list , ch oose For m .

file:///C|/html/0596527608/access2007tm-CHP-12-SECT-3.html (9 of 12) [1/7/2007 7:11:42 AM]

Tools

Section 12.3. Creating Better Layouts

4. Ch oose t h e For m a t t a b, w h ich in clu de s a ll t h e se t t in gs t h a t r e la t e t o split for m s. 5. Fin d t h e D e fa u lt Vie w , a n d t h e n se t t h is t o Split For m . N ow you ge t t h e t w o- pa r t w in dow sh ow n in Figu r e 1 2 - 1 9 . Several m ore set t ings let you cont rol how split form s work. Table 12- 1 has t he det ails.

Ta ble 1 2 - 1 . For m Pr ope r t ie s for Split For m s Pr ope r t y

D e scr ipt ion

Split Form Orient at ion

Using t his set t ing, you can place t he dat asheet port ion of t he window at t he t op ( t he st andard choice) , at t he bot t om , on t he left , or on t he right .

Split Form Size

Set s how large t he dat asheet port ion of t he window appears. You'll need t o experim ent wit h different num bers t o find what works. Most people prefer t o size t he split window by hand in Form view.

Split Form Split t er Bar

I f you change t his set t ing t o No, t here won't be a split t er bar in bet ween t he t wo port ions of t he window. You ( or t he person using t he form ) can't change t he space allocat ed t o each port ion by dragging t he split t er bar. I nst ead, you'll be st uck wit h t he size t hat 's specified in t he Split Form Size set t ing.

Save Split t er Bar Posit ion

I f you change t his set t ing t o Yes, every t im e you m ove t he split t er bar, t he dat asheet size is recorded in t he Split Form Size set t ing. The next t im e you open t he form , t he split t er bar's posit ioned where it was m ost recent ly. I f you change t his set t ing t o No, t hen Access doesn't save your changes. The split t er bar revert s t o it s original posit ion, as set in t he Split Form Size propert y.

Split Form Dat asheet

Change t his set t ing t o Read Only if you want t o prevent people from changing dat a in t he dat asheet sect ion of t he window. ( They can st ill use t he dat asheet t o navigat e from one record t o anot her.) Doing so's one way t o prevent errors caused by accident al key presses. I f you want t o prevent edit s alt oget her, t hen use t he Allow Edit s, Allow Delet ions, and Allow Addit ions set t ings described in Table 12- 2.

Split Form Print ing

Tells Access whet her t o use t he dat asheet view ( Dat asheet Only) or t he Form view ( Form Only) t o creat e a print out . The st andard set t ing's Form Only, which m eans Access organizes t he inform at ion in your print out t o fit your form 's layout .

12.3.6. Even More Useful Form Properties So far, you've used t he Propert y Sheet t o change t he view of your form , let t ing an ordinary form show m ult iple it em s or a split view. However, t he Propert y Sheet 's packed wit h m any m ore set t ings. Som e are useful; ot hers you'll alm ost never t ouch. Table 12- 2 list s a few m ore set t ings t hat m ay com e in handy.

Ta ble 1 2 - 2 . Use fu l For m Pr ope r t ie s Pr ope r t y

Ta b

D e scr ipt ion

Record Source

Dat a

Where t he dat a com es from . This propert y's usually t he nam e of a t able or query in t he dat abase. However, if you're t echnically inclined, t hen you can t ype a new SQL com m and ( Sect ion 6.2.3) direct ly int o t his field.

Filt er

Dat a

The filt er expression t hat 's used t o lim it result s. You can set t his field by hand, or build a filt er expression using t he ribbon, as described in Sect ion 12.2.2.

Filt er On Load

Dat a

I f set t o Yes, t he filt er expression's applied as soon as you open t he form . I f No, t he filt er expression's st ored, but Sort & Filt er Apply Filt er. not applied unt il you choose Hom e

Order By

Dat a

The sort ing expression you use t o order result s. You can set t his field by hand, or set t he sort order using t he ribbon, as described in Sect ion 12.2.

Order By On Load

Dat a

I f set t o Yes, Access applies t he sort order as soon as you open t he form . I f No, t he sort order's st ored but not applied. That opt ion's not part icularly usefulunless you open up t he Propert y Sheet again and set Order By On Load back t o Yes, t he st ored sort order won't ever com e int o effect .

file:///C|/html/0596527608/access2007tm-CHP-12-SECT-3.html (10 of 12) [1/7/2007 7:11:42 AM]

Section 12.3. Creating Better Layouts

Allow Filt ers

Dat a

I f set t o No, you can't use any of t he filt ering com m ands described in t his chapt er. I nst ead, you'll always see all t he records.

Capt ion

Form at

The t ext t hat appears in t he t ab t it le ( or t he window capt ion, if you're using overlapping windows inst ead of t abbed docum ent s) . I f you leave t his blank, t hen Access uses t he form 's nam e as t he capt ion.

Allow [ …] View

Form at

These set t ings let you t urn off a part icular view. For exam ple, if you set Allow Layout View t o No, you don't see t he opt ion for swit ching your form t o Layout view.

Allow Edit s

Dat a

I f set t o No, you can't change any dat a in t he form . However, you can st ill add a new record wit h all- new dat a. The st andard opt ion's Yes.

Allow Delet ions

Dat a

I f set t o No, you can't delet e any record while using t his form . The st andard opt ion's Yes.

Allow Addit ions

Dat a

I f set t o No, you can't insert a new record wit h t his form . The st andard opt ion's Yes.

Dat a Ent ry

Dat a

I f set t o Yes, t his form can only be used t o add new records. When you swit ch t o Form view, you don't see any of t he exist ing records. I nst ead, you see a blank slat e where you can add a new record. As you add new records, t hey rem ain visibleat least unt il you close t he form and reopen it .

Record Select ors

Form at

I f set t o No, your form doesn't include t he m argin on t he left . This m argin has t wo roles. First , it shows an arrow next t o t he current record ( which is useful in form s t hat show several records at a t im e) . Second, if you click t he m argin, t hen you can select t he ent ire record ( aft er which you can quickly delet e it wit h t he Delet e key) .

Navigat ion But t ons

Form at

I f set t o No, your form doesn't include t he handy navigat ion cont rols at t he bot t om t hat let you j um p from record t o record. You're m ost likely t o use t his opt ion if you're designing a form wit h a radically different appearance and you don't want any of t he Access st aples, or if you're creat ing your own navigat ion but t ons t hat use VBA code.

Note: Many form properties apply only in the rare case that you're using free-floating windows (Section 1.3.6). You can choose whether the window's automatically centered (Auto Center), whether it can be resized (Border Style), whether it includes minimize and maximize icons (Min Max Buttons), and so on. These properties have no effect if your database is using the more standard tabbed windows.

UP TO SPEED The Access Form Family Access form s m anage t o please j ust about everyone. I f you're in a hurry, t hen you can creat e a ready- m ade form wit h a basic layout and add a dash of form at t ing. Or, if you're feeling a creat ive buzz com ing on, you can pull your fields out of t he st andard layout s and place t hem absolut ely anywhere. I n ot her words, form s are flexiblet im e- pressed business t ypes get t he convenience t hey need, while serious art ist es get t he creat ive cont rol t hey dem and. Here's a roundup of all your form choices: ●













A sim ple for m shows one record at a t im e in a basic st acked layout . To creat e a sim ple form , choose Creat e Form s Form . A la you t - le ss for m let s you place cont rols anywhere you want on a form . I t 's up t o you whet her you want t o show a single record at once, or several records at a t im e. When creat ing a layout - less form , you need t o do all t he work. You can Form s Form Design ( t o st art in Design view) or Creat e Form s Blank get st art ed by choosing Creat e Form ( which st art s you in Layout view) . A t a bu la r for m shows records in a t abular layout . Usually, t abular form s show several records at once ( which gives t he appearance of a t able) . To quickly creat e one of t hese babies, choose Creat e Form s Mult iple I t em s. A Pivot Ch a r t or Pivot Ta ble for m is a form t hat exist s for t he sole purpose of showing a Pivot Chart or Pivot Table ( see Chapt er 9) . You can creat e t hese form s by choosing Creat e Form s Pivot Chart and Creat e Form s More Form s Pivot Table. Sect ion 9.3 has m ore. A da t a sh e e t for m looks exact ly like t he Dat asheet view you get wit h a t able. This form 's not as powerful as ot her form t ypes, but it 's st ill useful if you want a cust om ized dat asheet - like view of your dat a. You can creat e a dat asheet form t hat shows fewer colum ns, uses filt ering t o hide cert ain records, prevent s record insert ions, uses different form at t ing, and so Form s More Form s Dat asheet . on. To creat e a dat asheet form , choose Creat e A split for m com bines t wo t ypes of form in one window. One port ion of t he window shows t he current record in a sim ple form . The ot her port ion of t he window shows a dat asheet wit h several records. To creat e a split form , choose Creat e Split Form . Form s A m oda l dia log is a special t ype of form . Rat her t han show dat a from a t able, t he m odal dialog asks you a quest ion. The idea's t hat you can pop it up at som e crit ical m om ent as part of an aut om at ed t ask. To use m odal form s, you'll need t o m ix in som e VBA code. You'll see an exam ple t hat uses a m odal form ( also known as a dialog form ) in Sect ion 17.4.3.

file:///C|/html/0596527608/access2007tm-CHP-12-SECT-3.html (11 of 12) [1/7/2007 7:11:42 AM]

Section 12.3. Creating Better Layouts

file:///C|/html/0596527608/access2007tm-CHP-12-SECT-3.html (12 of 12) [1/7/2007 7:11:42 AM]

Section 12.4. The Form Wizard

12.4. The Form Wizard By now, you've learned how t o creat e a num ber of com m on form s. Access gives you one ot her way t o build a form : using t he Form wizard. The Form wizard has an uncanny sim ilarit y t o t he report wizard you used in Chapt er 10. I t asks you a series of quest ions and t hen builds a form t o m at ch. However, t he quest ions are fairly rudim ent ary, and t he form it builds is lit t le m ore t han a good st art ing point for furt her cust om izat ion. Here's how t o put t he Form wizard t hrough it s paces: 1. Ch oose Cr e a t e

For m s

M or e For m s

For m W iza r d.

The first st ep of t he Form wizard appears. 2. Fr om t h e dr op- dow n list , ch oose t h e t a ble you w a n t t o u se . I n t he Available Fields list , t he wizard shows all t he fields t hat are in your t able. 3. Add t h e fie lds you w a n t t o in clu de , a s sh ow n in Figu r e 1 2 - 2 0 . W h e n you 'r e fin ish e d, click Next. You can choose fields from m ore t han one t able, provided t hese t ables are relat ed.

Figu r e 122 0 . To add a field, select it, and then click the > button file:///C|/html/0596527608/access2007tm-CHP-12-SECT-4.html (1 of 3) [1/7/2007 7:11:45 AM]

Section 12.4. The Form Wizard

to move it from the Available Fields list to the Selected Fields list. To add all the fields, click >>.

4. Ch oose a la you t opt ion for you r for m . Your layout opt ions include:









Form s Colu m n a r creat es a form wit h a st acked layout . I t 's sim ilar t o clicking Creat e Form in t he ribbon. Ta bu la r creat es a form wit h a t abular layout . I t 's sim ilar t o clicking Creat e Form s Mult iple I t em s in t he ribbon. Form s More D a t a sh e e t creat es a dat asheet form . I t 's sim ilar t o select ing Creat e Form s Dat asheet in t he ribbon. Ju st ifie d creat es a form t hat doesn't use any set layout . I nst ead, it packs cont rols closely t oget her, com bining several fields on a single line if t hey're sm all enough t o fit . A j ust ified form 's t he only kind of form you can't creat e direct ly from t he ribbon using anot her com m and. I t 's sim ilar t o t he layout - less form s you designed in Sect ion 12.3.2.

Note: Justified forms are difficult to modify later on. For example, if you need to add a field into the middle of a layout form, you're stuck with the painstaking task of moving many more fields out of the way to new positions. Often it's easier to recreate the form from scratch using the wizard. 5.

file:///C|/html/0596527608/access2007tm-CHP-12-SECT-4.html (2 of 3) [1/7/2007 7:11:45 AM]

Section 12.4. The Form Wizard

Ch oose on e of t h e pr e se t st yle s, a n d t h e n click N e x t . The st yles det erm ine t he form at t ing t hat Access applies t o your form . Unfort unat ely, it 's difficult t o get a feeling for what t he final result will look like unless you act ually t ry each opt ion. 6. En t e r a n a m e for you r for m . When t he Form wizard finishes, it im m ediat ely saves your form using t his nam e. 7. Ch oose " Ope n t h e for m t o vie w or e dit in for m a t ion " if you w a n t t o st a r t u sin g you r for m t o w or k w it h da t a , or " M odify t h e for m 's de sign " if you w a n t t o a dj u st it in D e sign vie w fir st . Th e n , click Fin ish . Access saves your form and opens it in Form view or Design view, depending on your choice.

file:///C|/html/0596527608/access2007tm-CHP-12-SECT-4.html (3 of 3) [1/7/2007 7:11:45 AM]

Chapter 13. Designing Advanced Forms

13. Designing Advanced Forms Form s suit a dat abase like pocket prot ect ors on a program m er. They st ream line day- t o- day t asks and give your dat abase a sharp, dist inct ive look. I n order t o be a m ast er dat abase builder, you need t o be able t o craft t op- not ch form s. I n t he previous chapt er, you learned how t o design several com m on t ypes of form s. I n t his chapt er, you'll t ake form building t o t he next level wit h a whole new arsenal of t echniques. First , you'll learn how t o creat e a form in t he no- holds- barred Design view, where you can t weak and polish every square inch of your form . Then, you'll t ake a t our of Access's different cont rols, and j azz up your form wit h links, t abbed panels, and but t ons. You'll also learn how t o work wit h linked t ables by creat ing special t ypes of form s called subform s t hat work in harm ony wit h ot her form s.

file:///C|/html/0596527608/access2007tm-CHP-13.html [1/7/2007 7:11:46 AM]

Section 13.1. Customizing Forms in Design View

13.1. Customizing Forms in Design View I n t he previous chapt er, you learned how t o quickly creat e different form s using t he ribbon's but t ons and t he Form wizard. But serious form gurus t ake a different approacht hey build a form by hand. There are t wo ways you go about t his t ask: ●

Cr e a t e a for m in La you t vie w . Choose Creat e Form s Blank Form . Then, drag t he fields you want from t he Field List pane ont o your form ( Figure 13- 1) . You learned everyt hing you need t o pull t his off in Chapt er 12. You can quickly creat e a st andard form wit h a st acked or t abular layout , but it doesn't give you any ext ra frills.

Figu r e 13-1. When you drop your first field onto a new form in Layout view, Access adds that field to a stacked layout and shows a smart tag icon (circled). If you want a tabular layout instead, then click this icon, and then choose "Show in Tabular Layout".



Cr e a t e a for m in D e sign vie w . Choose Creat e Form s Form Design. Now you'll st art wit h a blank form in t he design window. You can drag fields ont o your form from t he Field List pane ( j ust as you do in Layout view) , and you can add a wide variet y of m ore specialized cont rols from t he ribbon.

Note: If you don't see the Field List pane, then choose Form Layout Tools | Formatting

file:///C|/html/0596527608/access2007tm-CHP-13-SECT-1.html (1 of 17) [1/7/2007 7:12:03 AM]

Tools

Add Existing Fields (in Design view)

Section 13.1. Customizing Forms in Design View

or Form Design Tools | Design

Controls

Add Existing Fields (in Layout view).

Of course, while you're working wit h a form , you can easily j um p back and fort h bet ween t he t wo views. ( Just right - click t he t ab t it le, choosing t he view you want , or click t he view but t ons at t he window's bot t om - right corner.) You can add fields t o your form using eit her view. However, when you add fields in Layout view, Access aut om at ically posit ions t hem in a layout . When you add fields in Design view, t hey st art out layout - free. Access assum es t hat people who use Design view want m ore cont rol over how t heir fields are placed.

Tip: Remember, you can move a free-floating field into a layout after the fact by dragging it into place. Figure 12-13 (Section 12.3.3) shows how.

There's anot her, m ore im port ant difference bet ween Layout view and Design view. I n Design view, you can add one of over a dozen fancy cont rols, like but t ons, boxes, and labels. These cont rols m ake t he difference bet ween t he cookie- cut t er form s Access creat es aut om at ically, and form s t hat exhibit your own personal st yle.

13.1.1. Form Sections: The Different Parts of Your Form I n Chapt er 12, you learned t hat a report 's divided int o separat e sect ions ( like a report header, a det ails sect ion, a report foot er, and so on) , each of which appears in a specific place. The sam e's t rue for form s. However, newly creat ed form s st art life wit h only one sect ion: t he det ails sect ion, which defines t he cont ent for each record. I f you want t o add a t it le or logo at t he t op of your form , or som e sort of sum m ary inform at ion or m essage at t he bot t om , you'll want t o include a header and foot er sect ion. To add t hese elem ent s t o your form , right - click anywhere on t he form 's surface, and t hen choose Page Header/ Foot er. When working wit h form sect ions, rem em ber t o keep t hem sm all ( as shown in Figure 13- 2) . Each form sect ion should be j ust large enough t o fit t he cont ent you're displaying. I f you creat e an oversized form wit h a lot of blank space, t he result s look unprofessional. You'll get unnecessary scroll bars on your form 's sides, which let you scroll off int o not hingness.

Tip: You can't make a form smaller than the controls it contains. This fact's the source of a frequent stumbling block for form designers. If Access doesn't let you resize a form, then something, somewhere, is still too big. (If all else fails, check that you don't have a large box in the form header or form footer sections.)

Figu r e 13-2. Even though this form easily fits all its fields in the display area, it still has scroll file:///C|/html/0596527608/access2007tm-CHP-13-SECT-1.html (2 of 17) [1/7/2007 7:12:03 AM]

Section 13.1. Customizing Forms in Design View

bars. If you switch to Design view, you'll see whythe form's wider and longer than it needs to be.

Note: If your database is set to use overlapping windows instead of tabs (Section 1.3.6), then you'll see a slightly different problemyour form windows are unnecessarily large. In fact, they may not even fit in the main Access window, in which case Access chops off the edges.

13.1.2. Adding Controls to Your Form You first learned about cont rolsgraphical widget s like labels and t ext boxeswhen you creat ed advanced report s in Chapt er 12. Access gives you t he sam e abilit y t o use cont rols wit h form s. I n fact , you use t he sam e ribbon sect ion t o add t hem . However, m any of t he cont rols t hat didn't m ake m uch sense wit h report s really shine wit h form s.

Note: Behind the scenes, everything on a form's actually a control. Each time you add a field, you end up with two linked controls: a label that displays the field name, and a text box that holds the field value.

One of t he sim plest and m ost useful cont rols is t he hum ble label. Using t he label, you can add form at t ed t ext anywhere on your form . You could choose t o use labels t o highlight addit ional inst ruct ions, as shown in Figure 13- 3.

file:///C|/html/0596527608/access2007tm-CHP-13-SECT-1.html (3 of 17) [1/7/2007 7:12:03 AM]

Section 13.1. Customizing Forms in Design View

Figu r e 1 3 - 3 . Use labels to add helpful instructions (or cheeky commentary) to your forms. Line and rectangle controls add a little polish.

To add a cont rol, follow t hese st eps: 1. H e a d t o t h e r ibbon 's For m D e sign Tools | D e sign

Con t r ols se ct ion .

The Cont rols sect ion has one- st op shopping for all t he cont rols you can use. 2. Opt ion a lly, sw it ch on t h e Use Con t r ol W iza r ds bu t t on . Th is bu t t on a ct iva t e s t h e w iza r ds for con t r ols. Som e t ypes of cont rols, like but t ons and list s, com e equipped wit h helpful wizards. As soon as you drop one on your form , t he wizard pops up t o help you perfect it . Ordinarily, wizards are swit ched on. However, cont rol expert s who know exact ly what t hey want m ay find t hat t he wizards j ust slow t hem down. When t he Use Cont rol Wizards but t on ( found t he Form Design Tools | Design not highlight ed, t he Cont rol wizards leave you alone.

Cont rols sect ion's far- right side) is

3. Click t h e icon for t h e con t r ol you w a n t . On m ost people's screens, Access can't fit t he cont rol nam e on t he ribbon's cont rol but t on. ( Thirt y- inch m onit or owners, congrat ulat e yourselves and skip t o t he next paragraph.) Hover over each cont rol icon for a m om ent , and Access displays t he cont rol nam e in a t oolt ip. Once you click your icon, it rem ains highlight ed. Your m ouse cursor changes t o a cross wit h a sm all pict ure of t he cont rol superim posed. That change is your indicat ion t hat your cont rol's ready and wait ing for you t o drop it ont o t he form .

Tip: If this is your first time experimenting with controls, why not try the labelit's easy to master, and genuinely useful. 4. To pla ce you r con t r ol on t h e for m , dr a g t h e m ou se t o dr a w t h e con t r ol on t h e for m . I f you don't get it right t he first t im e, t hen you can always drag a cont rol t o a new posit ion, or drag it s borders t o resize it . I f you decide t hat you don't want t o add t he cont rol you picked, t hen j ust click t he Select but t on ( at t he far right of t he Cont rols sect ion) . I t looks like a m ouse point er. When you click Select , your m ouse Form Design Tools | Design point er ret urns t o norm al. You can now click on t he form t o select an exist ing cont rol. You don't creat e a new one.

file:///C|/html/0596527608/access2007tm-CHP-13-SECT-1.html (4 of 17) [1/7/2007 7:12:03 AM]

Section 13.1. Customizing Forms in Design View

Tip: For an even faster shortcut, just hit Esc to back out of control creation after you've selected a control. 5. I f you r con t r ol h a s a Con t r ol w iza r d a n d you ch oose t o u se Con t r ol W iza r ds ( se e st e p 2 ) , t h e w iza r d a ppe a r s n ow . Answer all t he quest ions t o configure your cont rol, or j ust hit Esc t o skip out of t he wizard and do all t he configurat ion on your own. 6. I f you 'r e a ddin g a la be l, su pply som e t e x t for t h e con t r ol. Aft er you drop a label ont o your form , Access wait s for you t o t ype in som e t ext ( which is set in t he Capt ion propert y) . I f you don't t ype anyt hing for your label, Access assum es you don't really want t he label, and j ust get s rid of it . 7. I f t h e Pr ope r t y Sh e e t isn 't a lr e a dy visible ( a t t h e r igh t side of t h e w in dow ) , click For m D e sign Tools | D e sign Tools Pr ope r t y Sh e e t t o sh ow it . To configure t he cont rol's m any set t ings, or propert ies, you need t o use t he Propert y Sheet . 8. Ch a n ge t h e a ppr opr ia t e se t t in gs in t h e Pr ope r t y Sh e e t . I f you've added a bound cont rol ( see t he box " Bound Cont rols) , select t he Dat a t ab, and t hen set t he Cont rol Source field t o t he nam e of t he field you want t o display.

Tip: If you have a label control that doesn't fit all the text you've entered, you can bump its size up in one step. Just right-click the control, and then choose Size boxesit won't work.

To Fit. Access resizes the label so it's just large enough to fit all its content. Don't try this with other controls like text

UP TO SPEED Bou n d Con t r ols A bound cont rol's a cont rol t hat displays t he value in a dat abase field. ( I t 's called a bound cont rol because it 's " bound" t ight ly linkedt o t he appropriat e field in your t able.) The m ost fam iliar exam ple's t he t ext box, but ot her bound cont rols include t he checkbox, t he list box, and so on. When you add a bound cont rol, you need t o specify t he linked field so Access knows what t o display. You can m ost easily add a bound cont rol by dragging a field from t he Field List pane and let t ing Access creat e t he cont rol for you. However, t here's no reason you can't choose t o creat e a bound cont rol by hand. Begin by dropping t he right cont rol t ype ( like a t ext box) ont o your form . Then, select t he Dat a t ab and look for t he Cont rol Source set t ing. This set t ing's where you fill in t he corresponding field. For exam ple, a t ext box wit h a Cont rol Source set t o Product Nam e displays t he cont ent s of t he Product Nam e field on your form . Of course, t his procedure works only if t he form 's dat a sourcet he t able or query on which you're building t he form has t he field you want t o use. To change a form 's dat a source, select Form in t he Propert y Sheet , click t he Dat a t ab, and t hen look for t he Record Source propert y. The Record Source propert y has t he nam e of t he linked t able or query or an SQL SELECT com m and ( Sect ion 6.2.3) t hat get s t he records you need. To choose a different t able or query, t ype in it s nam e. Or, click t he ellipsis but t on in t he Record Source box t o open a query window t hat let s you pick and choose exact ly t he fields you want t o use, from as m any linked t ables as necessary, wit h t he exact filt ering and sort ing opt ions you want .

9. Opt ion a lly, give you r con t r ol a be t t e r n a m e by se t t in g t h e N a m e pr ope r t y ( in t h e Ot h e r t a b) . I f you've j ust creat ed a new label, Access best ows a nam e like Label46. I f you want t o honor your cont rol wit h som et hing

file:///C|/html/0596527608/access2007tm-CHP-13-SECT-1.html (5 of 17) [1/7/2007 7:12:03 AM]

Section 13.1. Customizing Forms in Design View

m ore becom ing, j ust change t he t ext in t he Nam e propert y. You'll have an easier t im e finding your cont rol in t he drop- down list in t he Propert y Sheet next t im e you want t o change it . 10. For m a t you r con t r ol. Alt hough you can adj ust m any form at t ing det ails via t he Propert y Sheet , t he ribbon's m uch easier t o use. Use t he Form Font sect ion for basic font and color form at t ing, and use t he Form Design Tools | Design Design Tools | Design Cont rols chunk t o add a st ylized border around your cont rol.

Tip: Want to make controls stand out with a shadow or embossed edge? Select the control, and then choose an effect from the Form Design Tools | Design

Controls

Special Effect list. This method's a great way to make a basic rectangle control look a little different.

GEM I N TH E ROUGH Re u sin g You r Fa vor it e Bor de r Se t t in gs On t he Cont rols sect ion, t here's an oft en overlooked but t on nam ed Set Cont rol Default s. This but t on let s you reuse border set t ings over and over again. That way, if you com e up wit h a nift y border for one cont rol, you can quickly apply it t o ot hers. Here's how it works. Suppose you creat e a label and use t he but t ons in t he Cont rols chunk t o apply a carefully form at t ed border around it , wit h j ust t he right t hickness ( hairline) , color ( fuchsia) , and line st yle ( dot t ed) . You can reuse t hese set t ings by select ing t he newly creat ed label cont rol and t hen clicking Set Cont rol Default s. Now, t he next t im e you add a label t o t his form , it 'll aut om at ically have t he sam e border set t ings. The Set Cont rol Default s com m and works on a per- cont rol basis, so you can st ore different border set t ings for labels, pict ures, t ext boxes, and so on. Alt hough it 's an int erest ing frill, m any Access expert s prefer t o apply t he sam e form at t ing t o several cont rols by select ing t hem all at once, and t hen choosing t he border opt ions.

13.1.3. The Control Gallery: A Quick Tour Lat er in t his chapt er, you'll consider how t o creat e som e popular form designs wit h cont rols. But first , it 's wort h t aking a quick overview of all t he cont rols on t he rib- bon so you can see exact ly what 's available ( and what isn't ) . Table 13- 1 int roduces you t o every m em ber of t he cont rol fam ily.

Ta ble 1 3 - 1 . For m Con t r ols Con t r ol

D e scr ipt ion

Label

Displays fixed t ext . Perfect for capt ions, not es, and helpful inst ruct ions.

Text Box

Displays t he value of a field from a record. You can also use a t ext box t o show t he result of an expression, as described in Sect ion 11.5.

Check Box

Displays t he value of a Yes/ No field. I f it 's Yes, t he check box has a checkm ark.

Toggle But t on

Shows a but t on t hat can be in t wo different st at es: norm al and pressed. You swit ch it from one st at e t o t he ot her by clicking it . The t oggle but t on's a rarely used oddit y, but you can subst it ut e it for t he check box t o display t he value of a Yes/ No field. I n t his case, t he but t on's depressed if t he field value is Yes.

Com bo Box

Displays a list t hat pops int o view when you click t he drop- down arrow. This list can be a list of values you supply, or it can be drawn from anot her t able. Access aut om at ically uses a com bo box for lookup fields or linked t ables.

List Box

Displays a large box wit h a list of it em s. This list can be a list of values you supply, or it can be drawn from anot her t able. You can use list boxes and com bo boxes int erchangeablyt he key difference is t he fact t hat list boxes t ake m ore space and com bo boxes let you t ype in your own values t hat aren't in t he list .

file:///C|/html/0596527608/access2007tm-CHP-13-SECT-1.html (6 of 17) [1/7/2007 7:12:03 AM]

Section 13.1. Customizing Forms in Design View

At t achm ent

Shows t he first file in an at t achm ent field. I f t his file's a pict ure, t he pict ure's displayed direct ly on t he form . Ot herwise, all you see's a sm all icon t hat indicat es t he file t ype. I f t he at t achm ent field holds m ore t han one file, t hen you can st ep t hrough each one using t he arrows in t he m inibar ( which appears when you click t his field) , as described in Sect ion 12.1.2.3.

Opt ion Group and Opt ion But t on

The opt ion group's a rect angular cont ainer t hat holds one or m ore opt ion but t ons.

Hyperlink

Displays a fixed hyperlinkblue underlined t ext t hat , when clicked, t ransport s t he clicker t o a specific Web page. Sect ion 13.2.5 shows how it works.

Line and Rect angle

The line and rect angle cont rols are j ust decorat ion. Skillful designers use t hem t o separat e sect ions and highlight im port ant inform at ion.

I m age

Displays a pict ure t hat you supply. Perfect for logos and eye candy t hat set s your form apart . Set t he Size Mode propert y t o det erm ine whet her your pict ure's chopped down t o fit it s box ( Clip) , st ret ched t o fit ( St ret ch) , or resized wit hout changing t he shape ( Zoom , which is t he st andard set t ing) . You can even use t he Pict ure Tiling propert y t o repeat a pict ure over a larger surface. To keep your pict ures ( and dat abase files) sm all, use com pact .j pg files rat her t han bloat ed .bm p files.

Tab Cont rol

Displays several t abs of inform at ion. You can see t he cont ent in one t ab at a t im eyou click t o pick which t ab you want . This Windows st aple allows you t o pack m ore inform at ion int o a sm aller space. Sect ion 13.2.4 shows an exam ple.

Subform

Displays a form inside a form . Usually, a subform shows linked records from a relat ed t able. You'll see how t his works in Sect ion 13.3.1.

Chart

Creat es a basic chart using t he Chart wizard t hat 's included wit h Office. Alas, chart s aren't very well int egrat ed int o Access. I f you want t o provide a graphical view of your dat a, t hen you're bet t er off using a pivot chart ( see Chapt er 9) or j ust export ing your raw dat a t o Excel, which is m uch m ore capable.

Unbound Obj ect Fram e

Shows cont ent , which is known as an obj ect , from anot her program using a som ewhat old- fashioned st andard called OLE. You can use t his cont rol t o do t hings like em bed a spreadsheet , audio file, or Word docum ent wit hin your form . Most folks resist t he urge, because t he result s t end t o be awkward and confusing.

Bound Obj ect Fram e

Sim ilar t o t he unbound obj ect fram e, but t his cont rol ret rieves t he obj ect you want t o display from a field in t he current record. This feat ure seem s nift y, but t he quirky and out dat ed OLE st andard causes m ore t rouble t han it 's wort h. I f you want t his sort of feat ure, t hen you're far bet t er off using an at t achm ent field wit h an at t achm ent cont rol ( Sect ion 2.3.8) , wit h an at t achm ent cont rol, which is designed t o solve t hese problem s.

Page Break

I ndicat es where a page break should fall. This cont rol has an effect only when you usfe your form t o creat e a print out . Usually, you should st eer clear of t his cont rol in form s and use it exclusively in report s, which are t ailor- m ade for print ing.

Act iveX Cont rol

Act iveX is a cont rol building st andard t hat 's support ed by m any different program m ing plat form s. I f t here's a specialized widget t hat you need t o use in Access, you m ay be able t o buy an Act iveX cont rol from a com ponent com pany, and t hen drop it ont o your form s. Beware, t houghusing Act iveX cont rols oft en requires heft y am ount s of code, and it 's beyond t he scope of t his book.

FREQUENTLY ASKED QUESTIONS The Windows Control Face-Lift Why do m y cont rols look so old fashioned? Most people know Windows XP as t he operat ing syst em t hat ushered in a whole new era of slight ly different - looking but t ons. Microsoft , in it s relent less drive t o m ake m inor cosm et ic changes, used Windows XP t o redesign t he visual appearance of com m on cont rols like but t ons and checkboxes. To t he unt rained eye, t he differences bet ween Windows XP design frills and it s predecessors are slight . For exam ple, Microsoft replaced boxy grey but t ons wit h carefully rounded but t ons t hat glow wit h a hint of yellow shading when t he m ouse hovers over t hem . Most Windows pro- gram s t ake advant age of t he new look, but som e are st ill t rapped in t he past . I n previous versions of Access, it didn't m at t er whet her you were using Windows XP or an earlier version of t he operat ing syst em . Eit her way, your cont rols had t he old st yling. I n Access 2007, your form s aut om at ically get t he new Windows XP look ( assum ing you're running Windows XP or Windows Vist a as your operat ing syst em ) . However, t here's a possible except ion. I f you open a dat abase t hat you creat ed wit h an older version of Access, t hen your form s keep t heir original out dat ed appearance. Access doesn't want t o t am per wit h any aspect of your form 's appearance, in case it t hrows off your whole design. Fort unat ely, you can have t he final say. I f you've opened an old dat abase, here's how t o get t he new look: 1.

file:///C|/html/0596527608/access2007tm-CHP-13-SECT-1.html (7 of 17) [1/7/2007 7:12:03 AM]

Section 13.1. Customizing Forms in Design View

Choose Office but t on

Access Opt ions.

The Access Opt ions dialog box appears. 2. I n t he list on t he left , choose Current Dat abase. Access displays set t ings t hat pert ain t o t he current ly open dat abase file. 3. I n t he " Applicat ion Opt ions" sect ion, find t he set t ing " Use Windows- t hem ed Cont rols on Form s" . I f you want t he Windows XP st yles, t hen t urn on t he check- box here. I f you don't , t hen rem ove t he checkm ark. 4. Click OK.

13.1.4. Arranging Controls on Your Form By now, you're probably com fort able working wit h cont rols in Design view. Here's a quick refresher if your m em ory needs a lit t le j um p st art : ● ● ●

● ●

Cr e a t e a con t r ol. Use t he ribbon t o pick t he cont rol you want , and t hen draw it in t he right place. M ove a con t r ol. Just drag. You can also m ove several cont rols at once, as explained in Figure 13- 4. Re size a con t r ol. Drag t he edges of t he rect angle t hat surrounds it . I f you have a linked label- and- t ext - box com binat ion ( which Access creat es when you add a field) , t hen be careful t o click t he right part . Figure 11- 9 ( Sect ion 11.1.5) shows where t o click t o m ove j ust t he capt ion, j ust t he field value box, or bot h. M odify a con t r ol. Select it , and t hen, in t he Propert y Sheet , find t he set t ing you want t o change. D e le t e a con t r ol. Select it , and t hen hit Delet e t o wipe it out forever.

Figu r e 1 3 4 . To move multiple controls at once, start by clicking somewhere on the form surface. Drag a selection box around all the controls you want to move, as shown here. Then, once all the controls are highlighted, drag any one of them. All the controls move as a unit. (You could also hold down Shift, and click each control one by one.)

file:///C|/html/0596527608/access2007tm-CHP-13-SECT-1.html (8 of 17) [1/7/2007 7:12:03 AM]

Section 13.1. Customizing Forms in Design View

I f your cont rols aren't cont ained in a layout , it can be difficult t o get t hem neat ly arranged. I n an effort t o help, Access supplies som e short cut s t hat can line up rogue cont rols and iron out m inor variances. The following sect ions provide a few useful t ips for using t hese feat ures.

POWER USERS' CLINIC Breaking Free From the Grid When you place or m ove a cont rol in Design view, Access always lines it up wit h t he nearest part of t he grid. ( The grid lines are represent ed by all t hose dot s t hat appear underneat h your cont rols in Design view.) Access does t his lining up because it m akes it easier t o creat e a consist ent form . I f cont rols were com plet ely free- float ing, it would be difficult t o line t wo cont rols up next t o each ot her. Even if you don't have shaky hands, it 's hard t o cont rol t he m ouse t hat precisely! However, in som e sit uat ions, you m ay want t o nudge a cont rol j ust bet ween t he grid dot s. Usually, it 's because your form includes pict ures, and you're t rying t o creat e a snazzy effect . I n such cases, Access let s you free yourself from t he grid. Just choose Form Design Tools | Arrange Cont rol Layout Snap t o Grid. Ordinarily, t his but t on's highlight ed t o indicat e t hat cont rols are always lined up wit h t he grid. To t urn it off, click it . You can t urn it back on when you're finished by clicking it again. Show/ Hide I ncident ally, if you find t hat t he grid dot s are dist ract ing, you can hide t hem using Form Design Tools | Arrange Show Grid. And if you decide t hat you do want your cont rols t o line back up wit h t he grid, t hen j ust select t hem all, right To Grid. Access bum ps each cont rol over t o t he nearest grid line. Use Size click t he select ion, and t hen choose Align To Grid t o m ake sure t heir height s and widt hs also fit t he grid.

13.1.4.1. Aligning controls I f you have a group of cont rols t hat needs t o be neat ened up, select t hem all ( by drawing a select ion box, as shown in Figure 13- 4) , right - click t he select ion, and t hen choose an opt ion in t he Align subm enu. Use t he ever- popular " left " opt ion t o line all t he cont rols up along t heir left edges. You can also line up cont rols on t he right ( see Figure 13- 5) , t op, or bot t om edges.

Figu r e 1 3 - 5 . Top: These controls look messy. Bottom: Even though the controls aren't in a layout, you can line them up properly using the Align options. Here, someone Right command to pull them together used the Align against the right edge.

13.1.4.2. Sizing controls I f you have cont rols of different sizes, t hen you can t ell Access t o m ake t hem all t he sam e size. Select t hem all, right - click t he select ion, and t hen choose an opt ion from t he Size m enu. Use To Widest t o m ake all t he cont rols as wide as t he widest one of t he bunch ( see Figure 13- 6) . Alt ernat ively, you can shrink cont rols down by choosing To Narrowest , or change t heir height s wit h To Tallest and To Short est .

file:///C|/html/0596527608/access2007tm-CHP-13-SECT-1.html (9 of 17) [1/7/2007 7:12:03 AM]

Section 13.1. Customizing Forms in Design View

Figu r e 1 3 - 6 . The To Widest command makes all these text boxes (top) the same width (bottom), which creates a cleaner and more visually pleasing form.

13.1.4.3. Spacing controls I f you have cont rols t hat are scat t ered unevenly over t he form , you can reposit ion t hem so t hat a consist ent am ount of space appears bet ween t hem . To do so, select all t he cont rols, and t hen head t o t he ribbon's Form Design Tools | Arrange Posit ion sect ion. I n t he Posit ion sect ion, you'll find several but t ons t o adj ust t he spacing bet ween cont rols: ● ● ● ●

M a k e Ve r t ica l Spa cin g Equ a l spaces out cont rols so t hey're an even dist ance apart ( from t op t o bot t om ) . M a k e H or izon t a l Spa cin g Equ a l spaces out cont rols so t hey're an even dist ance apart ( from side t o side) . I n cr e a se Ve r t ica l Spa cin g and I n cr e a se H or izon t a l Spa cin g add a bit m ore space bet ween all t he cont rols you've select ed. D e cr e a se Ve r t ica l Spa cin g and D e cr e a se H or izon t a l Spa cin g rem ove a bit of space bet ween all t he cont rols you've select ed.

13.1.4.4. Controls that overlap I f you have overlapping cont rols, you m ay want t o decide which one's placed on t op and which one on t he bot t om . To do so, Posit ion sect ion, and t hen choose Bring t o select one of t he cont rols, head t o t he ribbon's Form Design Tools | Arrange Front ( t o m ove t he cont rol t o t he t op) or Send t o Back ( t o banish it t o t he background) . I t goes wit hout saying t hat m ost form s don't have overlapping cont rols. The except ion's if you're aim ing for a unique graphical effect , or if you're t rying t o use a rect angle t o fram e a bunch of cont rols ( in which case t he rect angle needs t o sit behind t he ot her cont rols) .

13.1.5. Anchoring: Automatically Resizing Controls Ordinarily, your cont rols have a fixed, unchanging size. This charact erist ic let s you precisely arrange a large num ber of cont rols next t o each ot her. However, fixedsize cont rols also have a downside. I f you resize t he Access window t o m ake it very large, t hen t he cont rols can't use t he ext ra space. Conversely, if you m ake t he Access window very sm all, t hen you're sure t o cut off part of your form . I n ot her words, fixed- size cont rols m ake for easy design, but t hey're inflexible. Most people don't worry t oo m uch about t hese lim it at ions. They design t heir form s t o fit com fort ably on an average- sized screen ( see t he box " How Big I s Your Screen?" in Sect ion 13.1.5.1) . However, if you have one or m ore fields t hat display a large am ount of dat alike a m em o field ( Sect ion 2.3.1.1) t hat 's chock- full of t ext you m ight want t o get a bit m ore am bit ious. Access 2007 int roduces a feat ure called anchoring, t hat let s you creat e cont rols t hat can grow t o fill ext ra space when t he Access window's resized. Anchoring's a lit t le t ricky t o get right , but if you have huge t ext fields, it 's wort h t he t rouble. Essent ially, anchoring let s you at t ach a cont rol t o t he sides of t he form . As a result , when t he form changes size, t he cont rol's dragged t o a new posit ion or resized. Figure 13- 7 shows an ordinary form t hat uses st andard anchoring set t ings. Not hing happens when t his form 's resized.

file:///C|/html/0596527608/access2007tm-CHP-13-SECT-1.html (10 of 17) [1/7/2007 7:12:03 AM]

Section 13.1. Customizing Forms in Design View

Figu r e 1 3 7 . Ordinarily, all controls are anchored to the form's top-left corner (top). If the form window changes size, nothing happens to the controls, because the topleft corner never moves (bottom).

I f you anchor a cont rol t o a form 's right side, it 's a different st ory. As t he form 's resized wider, t he cont rol hugs t he right side, m oving t o a new posit ion. Sim ilarly, if you at t ach a cont rol t o t he bot t om of t he window and m ake it t aller, t hen t he cont rol keeps close t o t he bot t om , no m at t er how sm all or large t he window becom es. The really excit ing bit 's what happens when you anchor a cont rol t o opposit e sides. I n t his case, it s posit ion doesn't change, but it s size does. I f you anchor a cont rol t o a form 's left and right sides, t hen t he cont rol widens as t he form widens. Figure 13- 8 shows how life changes when you anchor your cont rol t o different sides.

Tip: The amount of space between the control and the anchored side always remains the same.

file:///C|/html/0596527608/access2007tm-CHP-13-SECT-1.html (11 of 17) [1/7/2007 7:12:03 AM]

Section 13.1. Customizing Forms in Design View

Figu r e 13-8. This form includes controls that are anchored to different sides. The ID and Email fields are anchored to the top right, and the Notes field is anchored to the bottom right. As the form grows, the controls change position.

Theoret ically, you can use anchoring t o creat e all kinds of bizarre effect s. You could anchor cont rols t o all different sides of t he form , so t hey m ove and overlap as t he form changes size, scram bling t he form in com plet e confusion. More realist ically, people use anchoring t o achieve t wo effect s, which are dem onst rat ed in t he following t wo sect ions.

UP TO SPEED How Big Is Your Screen? When it com es t o m onit ors, size doesn't m at t er ( really) . What is im port ant is your m onit or's resolut ion. Resolut ion m easures how m any pixels ( t iny dot s) your m onit or displays. I f you have a larger resolut ion, t hen you can fit m ore cont ent int o view. The only drawback's t hat everyt hing onscreen appears sm aller. I f you m axim ize t he Access window and open a dat asheet , t hen you see m ore rows and colum ns at once on a high- resolut ion screen t han a lowresolut ion one. Ordinary people t end t o use a resolut ion of 800 x 600 or 1024 x 768, alt hough higher resolut ions aren't unusual. ( A resolut ion of 800 x 600 is 800 pixels wide and 600 pixels t all.) Your specific resolut ion isn't all t hat im port ant . But if you plan t o share your Access dat abase wit h ot her people, t hen you m ay want t o check t hat your form s look respect able at ot her com m on resolut ions. To check what resolut ion you're current ly using, m inim ize all your program s. Then, right - click t he Windows deskt op, and t hen choose Propert ies. The Display Propert ies window appears. Choose t he Set t ings t ab t o find out your current resolut ion, and t o t ry out ot her resolut ions t o see how t hey affect your form s' usabilit y.

13.1.5.1. Making controls as wide as the form

file:///C|/html/0596527608/access2007tm-CHP-13-SECT-1.html (12 of 17) [1/7/2007 7:12:03 AM]

Section 13.1. Customizing Forms in Design View

Ordinarily, you size a t ext box, and it s size never changes. But wit h anchoring, you can m ake cont rols st ret ch wider or narrower t o m at ch your Access window's size. And as long as you don't put any ot her cont rols in t he way, you don't have a problem wit h overlapping cont rols. Just follow t hese st eps: 1. Fir st , m a k e su r e you r for m doe sn 't h a ve e x t r a bla n k spa ce . I n D e sign vie w , sh r in k t h e w idt h of t h e de t a ils se ct ion so it 's j u st w ide e n ou gh t o fit you r con t r ols. I f you leave ext ra blank space, t hen it 's harder t o see anchoring at work. Flip back t o Figure 13- 2 for a quick review of how t o size form s properly. 2. Ch oose t h e con t r ols t h a t you w a n t t o e x pa n d a lon g w it h t h e w in dow 's size . I f you have t he form shown in Figure 13- 7, you m ay choose all t he t ext boxes. Hold down t he Shift key while you click t o select t hem all. Figure 13- 9 shows t he final result you're aft er.

Note: If your controls are in a layout (Section 12.3), you need to remove them from the layout before you apply anchoring. Although you can apply anchoring settings to an entire layout container, they won't work the way you want them too because they'll influence the size of both the field value boxes and the field captions.

Figu r e 1 3 - 9 . Top: These text boxes could stand to grow so they can accommodate long names and email addresses. But you don't want them to be so wide that people need to scroll from side to side if their monitors have a lower resolution than yours. Bottom: The solution's anchoring, so the text boxes always use the

file:///C|/html/0596527608/access2007tm-CHP-13-SECT-1.html (13 of 17) [1/7/2007 7:12:03 AM]

Section 13.1. Customizing Forms in Design View

available space, and not one whit more.

3. Size An ch or in g St r e t ch Acr oss Top. ( I f you pr e fe r t o a dj u st Ch oose For m D e sign Tools | Ar r a n ge you r a n ch or in g se t t in gs in La you t vie w , t h e n ch oose For m D e sign Tools | Ar r a n ge Posit ion An ch or in g St r e t ch Acr oss Top.) This act ion anchors your cont rol t o t hree sides of t he form : t he t op, left , and right . The t op anchoring j ust m akes sure t he cont rol st ays at t he sam e vert ical posit ion if t he form window grows t aller or short er. The anchoring t o t he left and right sides ensures t hat t he t ext box grows as t he form widens, and shrinks as it narrows.

13.1.5.2. Making a single control as large as possible I n t he previous exam ple, you saw how t o use anchoring t o m ake a cont rol grow horizont ally. You can also use anchoring t o m ake a cont rol grow vert ically, but t here's a cat ch. I n m ost form s, you have several cont rols placed one on t op of t he ot her. I f you're not careful, when a cont rol get s t aller, it st art s blot t ing out t he cont rol underneat h it . The solut ion's t o m ake sure t hat only one cont rol on t he form can grow vert ically. This cont rol ( probably a large field t hat 's st uffed wit h t ext ) t hen expands t o consum e all t he ext ra space. All t he cont rols above t his cont rol m ust be anchored t o t he t op of t he form . All t he cont rols underneat h it m ust be docked t o t he bot t om so t hey st ay out of t he way. Here's how t o put t his m odel int o pract ice: 1. I n D e sign vie w , sh r in k t h e w idt h of t h e de t a ils se ct ion so it 's j u st w ide e n ou gh t o fit you r con t r ols. As wit h all t ypes of anchoring, ext ra space is your enem y. 2. Se le ct t h e con t r ol t h a t you w a n t t o gr ow ve r t ica lly t o ge t t h e e x t r a spa ce . Consider t he form in Figure 13- 9, which shows cust om ers. I n t his case, it 's t he Not es field t hat has t he m ost t ext and would benefit m ost from t he ext ra space. Even if you anchor t he Not es field t o bot h sides, you'll st ill get only a bit of ext ra space. Bet t er t o use what ever blank space you can get at t he bot t om of t he form . 3. Ch oose For m D e sign Tools | Ar r a n ge

Size

An ch or in g

St r e t ch D ow n a n d Acr oss.

This act ion anchors your cont rol t o all four sides of t he form : t he t op, bot t om , left , and right . As a result , t he cont rol grows when t he form 's widened or height ened. I f you want t he cont rol t o grow vert ically but not horizont ally, you choose Anchoring St ret ch Down inst ead. 4. Se le ct t h e fir st con t r ol u n de r t h e con t r ol t h a t gr ow s ve r t ica lly. Ch oose An ch or in g

Bot t om Le ft .

This act ion anchors t he cont rol t o t he left and bot t om sides. That way, as t he form 's height ened, t he cont rol drops down t o m ake space for t he one above. 5. You could also use t he St ret ch Across Bot t om opt ion. I n t his case, t he cont rol's st ill anchored t o t he bot t om , but it grows horizont ally t o fit t he widt h of t he form .

file:///C|/html/0596527608/access2007tm-CHP-13-SECT-1.html (14 of 17) [1/7/2007 7:12:03 AM]

Section 13.1. Customizing Forms in Design View

Note: In the previous example, you didn't need to anchor the labels in front of every field, because they stayed fixed in place. However, in this example, you do need to use Bottom Left anchoring for all the labels that appear underneath the control that stretches vertically. (Otherwise, this label doesn't line up with its value box.) You never use one of the stretch anchoring options with a label, because you don't want your label to change size. 6. Re pe a t st e p 4 for e a ch con t r ol u n de r n e a t h . I f you forget a cont rol, you see a t ellt ale sign. When you resize t he form window sm aller, som e cont rols overlap because t he different anchoring set t ings don't agree. Assum ing you anchor everyt hing correct ly, you get t he result t hat 's shown in Figure 13- 10.

Figu r e 1 3 - 1 0 . Now, when the form gets taller, the Notes field gets the extra room.

13.1.6. Tab Order: Making Keyboard Navigation Easier When you're using a form t o edit a record, you need t o skip from one field t o anot her. You can j um p anywhere you want by using your m ouse, but hard- core keyboard j ockeys don't want t o wast e t im e raising t heir fingers from t he keys. Here's where t he Tab key com es int o t he pict ure. You probably already know t hat t he Tab key let s you m ove from one cont rol t o anot her in any Windows applicat ion. The Tab key also works in t he dat asheet , let t ing you skip from one colum n t o t he next . So it should com e as no surprise t hat t he Tab key also works in your form s. The first t im e you press Tab in a form , you m ay be in for an em barrassing surprise. I f you've spent a fair bit of t im e fiddling wit h your cont rols and rearranging t hem , t hen t he Tab key doesn't necessarily t ake you t o t he cont rol you expect . Figure 13file:///C|/html/0596527608/access2007tm-CHP-13-SECT-1.html (15 of 17) [1/7/2007 7:12:03 AM]

Section 13.1. Customizing Forms in Design View

11 illust rat es t he problem .

Figu r e 1 3 - 1 1 . You'd expect that you could press the Tab key here to jump from the FirstName field to the LastName field. But try it and you wind up in the Country field instead, halfway down the form.

Note: The Tab key always works correctly if you're using a tabular or stacked layout, because Access keeps it up to date as you move the controls around. It's only when you've taken your controls out of a layout that you'll see the problem described here.

Get t ing a form st raight ened out so t hat t he Tab key m oves from one cont rol t o t he next in an orderly fashion is called set t ing t he t ab order. Essent ially, every cont rol t hat support s t abbing has t hree im port ant propert ies ( which you can find in t he Ot her t ab in t he Propert y Sheet ) . These propert ies are: ●





Ta b St op det erm ines whet her a cont rol support s t abbing. I f set t o Yes, you can t ab t o t his cont rol. I f you change t his set t ing t o No, t hen it doesn't m at t er how m uch t abbing you doyou'll never get here. When you first add a cont rol, t his propert y's always set t o Yes. Au t o Ta b has an effect only if t he cont rol's using an input m ask ( see Sect ion 4.2) . I f you set Aut o Tab t o Yes, t hen as soon as you t ype t he last charact er int o t he m ask, you're aut om at ically t abbed t o t he next cont rol. This feat ure's handy for really fast dat a ent ry, but it can be annoying if you m ake a m ist ake, because you're t abbed out of t he cont rol before you can fix it . Ta b I n de x cont rols t he t ab orderin ot her words, where you go each t im e you hit Tab. When you first open a form , you st art at t he cont rol t hat has a t ab index of 0. When you hit Tab, you t hen m ove t o t he cont rol wit h t he next highest t ab index ( like 1) . This process cont inues unt il you reach t he cont rol wit h t he highest t ab index. Hit Tab again, and you'll st art back at t he beginning.

Note: The only controls that have these properties are controls that can accept focusin other words, controls you can click and interact with. Obviously, text boxes, checkboxes, and buttons support tabbing. However, labels and pictures don't, because there's no way to interact with these items.

Every t im e you add a new cont rol, Access gives it a new, higher t ab index. Even if you drop a new cont rol at t he t op of t he form , Access put s it at t he end of t he t ab order. To fix t his problem , you could select each cont rol in Design view, and t hen change t he Tab I ndex set t ing by hand. However, a m uch less t im e- consum ing alt ernat ive let s you set t he t ab order for t he ent ire form in one go. Here's how it works: 1. Righ t - click a bla n k spot on t h e for m de sign su r fa ce , a n d t h e n ch oose Ta b Or de r . file:///C|/html/0596527608/access2007tm-CHP-13-SECT-1.html (16 of 17) [1/7/2007 7:12:03 AM]

Section 13.1. Customizing Forms in Design View

The Tab Order dialog box appears. I t list s all t he cont rols on your form t hat support t abbing, from lowest t o highest Tab I ndex. 2. I n t h e Se le ct ion list , ch oose t h e se ct ion of you r for m you w a n t t o w or k w it h . I t 's a lm ost a lw a ys t h e de t a ils se ct ion . The Tab Order dialog box let s you set t he t ab order separat ely for each sect ion of your form . I f your form includes a header and foot er, you can choose t o work wit h t he header, foot er, or det ails sect ion. However, it 's very rare t o find a form t hat has cont rols t o support t abbing out side t he det ails sect ion. 3. I f you w a n t t o le t Acce ss t a k e a cr a ck a t se t t in g t h e cor r e ct t a b or de r , t h e n click Au t o Or de r . When you click Aut o Order, Access set s t he t ab order based on t he cont rols' posit ion. The order goes from left t o right , and t hen from t op t o bot t om . Most of t he t im e, t he Aut o Order feat ure get s you t he right t ab order ( or at least get s you closer t o it ) . 4. To m ove a sin gle con t r ol t o a n e w posit ion in t h e t a b or de r , dr a g it . This st ep's a bit t ricky. Figure 13- 12 shows how it works.

Figu r e 1 3 - 1 2 . To reposition a control in the tab order, begin by clicking the gray margin that's just to the left of the control. The entire row's selected. Next, drag the control to a new position on the list. In this example, the Country field's being moved down the tab order.

5. Click OK w h e n you 've got t h e t a b or de r pe r fe ct e d.

Tip: The tab order goes both ways. You can move one step forward in the tab order by pressing Tab, and you can move one step backward by pressing Shift+Tab.

file:///C|/html/0596527608/access2007tm-CHP-13-SECT-1.html (17 of 17) [1/7/2007 7:12:03 AM]

Section 13.2. Taking Control of Controls

13.2. Taking Control of Controls So far, you've seen how t o creat e a form from scrat ch, and add all t he cont rols you want . However, you haven't used t his newfound power t o do anyt hing special. Sure, you've picked up t he abilit y t o add ext ra labels, lines, and rect angles. But t hat kind of eye candy pales in com parison t o t he t ruly helpful feat ures Access let s you add t o your form s. Want t o prevent people from ent ering buggy dat a? Check. Want t o add Web page- st yle hyperlinks? No problem . The list of what you can do t o soup up your form s' abilit ies is alm ost endless. The following sect ions show you t he m ost popular ways t o t ake charge of t he cont rols on a form .

13.2.1. Locking Down Fields I n a dat abase, alm ost every piece of inform at ion's subj ect t o change. However, t hat doesn't m ean people should have free range over every field. Suppose Bout ique Fudge creat es a form nam ed Current Orders t hat let s people in t he warehouse review out st anding cust om er orders, sort ed by dat e. The warehouse personnel need t o review each order, pack it up, and t hen ship it out . The only change t hey need t o m ake is t o updat e t he order st at us ( t o indicat e when it 's been sent out ) , or add a record t o t he shipm ent log. Ot her det ails, like t he order dat e, t he order cont ent s, and t he cust om er who's receiving t he order, should be off lim it s. The warehouse people have no reason t o change any of t his inform at ion. Form s are powerful t ools in scenarios like t his, because t hey let you prevent changes in cert ain fields. That way, t here's no chance t hat a m isplaced keyst roke can wipe out a legit im at e piece of inform at ion. Every bound cont rol ( a cont rol t hat displays a field from your t able) provides t he following t wo propert ies t hat you can use t o cont rol edit ing. You can change t hese propert ies using t he Propert y Sheet in Design view ( Sect ion 11.4) . ● ●

Lock e d det erm ines whet her or not you can m ake changes in a field. I f Locked is set t o Yes, t hen you can't edit t he field value. However, you can st ill select t he t ext in a t ext box, and t hen copy it . En a ble d let s you deact ivat e a cont rol alt oget her. I f Enabled is set t o No, t he cont rol appears wit h dim m ed ( gray) t ext . Alt hough you can st ill see t he field value in a disabled cont rol, you can't int eract wit h it in any way. I f it 's a t ext box, you can't even select and copy t he t ext it cont ains.

Tip: If you want to prevent edits altogether, consider using the Allow Edits, Allow Deletions, and Allow Additions form properties instead, which are described in Section 12.3.6.

13.2.2. Prevent Errors with Validation I n Chapt er 4, you learned how t o prevent errors from creeping int o your t ables by using validat ion rules, default values, and input m asks. This bullet proofing's an essent ial part of dat abase design. However, validat ion rules don't help in som e sit uat ions because t he rules apply som et im es, but not always. You don't want t he sales people at Bout ique Fudge t o ent er a new order wit h an old dat e. Clearly, t hat 's a m ist akea new order should receive t oday's dat e. To t ry and st am p out t he problem , a clever dat abase designer like yourself m ay use t he following validat ion rule on t he OrderDat e field: 100 Then MsgBox "I hope you budgeted for this." End If

Not e t hat t he I f block always st art s wit h I f and ends wit h End I f. I nside t he I f block, you can put as m uch code as you want . This is t he condit ional codeit runs only if t he condit ion's t rue. An I f block can also evaluat e several different condit ions. Here's an exam ple t hat calculat es t he fully t axed price of a product , and t hen displays t hat in a label. The t rick's t hat t he t ax rat e depends on anot her field ( t he Count ry) , which is where t he condit ional logic com es int o play. ' Store the tax rate you want to use in this variable. Dim TaxRate If Country = "U.S.A." Then ' Taxes are charged for U.S. customers (7%). TaxRate = 1.07 ElseIf Country = "Canada" Then ' Even more taxes are charged for Canadian customers (14%). TaxRate = 1.14 Else ' Everyone else gets off with no tax. TaxRate = 1 End If ' Display the final total in a label. TotalWithTax.Caption = Price * TaxRate

Only one segm ent of code runs in an I f block. I n t his exam ple, Access works it s way t hrough t he block, t est ing each condit ion unt il one m at ches. As soon as it finds a m at ch, it runs t he condit ional block of code, j um ps down t o t he closing End I f, and t hen cont inues wit h any ot her code t hat 's in t he subrout ine. I f no condit ion m at ches, t hen Access runs t he code in t he final Else clause ( if you've added it ) . Figure 17- 2 shows t his code in act ion.

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-1.html (3 of 11) [1/7/2007 7:14:09 AM]

Section 17.1. Exploring the VB Language

Figu r e 17-2. Thanks to conditional logic, this subform shows the correctly calculated total price at all times, taking into account both the current price and the customer's country. It works by responding to the On Current event, which occurs every time a record's displayed in the form.

These exam ples only scrat ch t he surface of what careful condit ional logic can do. You can use And and Or keywords t o com bine condit ions, put one condit ional block inside anot her, and m uch m ore. I n Chapt er 15, you saw validat ion worked using field couldn't be em pt y. im plem ent t he ident ical t he code) :

an exam ple t hat perform ed a specific t ype of validat ion wit h cust om er records ( Sect ion 15.6.2) . This t wo fields: Want sEm ail and Em ailAddress. I f t he Want sEm ail field was set t o Yes, t hen t he Em ailAddress However, if Want sEm ail was set t o No, t hen a blank Em ailAddress was com plet ely accept able. You can validat ion logic using VB code, but t here's a t wist it uses t wo I f blocks ( a line- by- line explanat ion follows

1 Private Sub Form_BeforeUpdate(Cancel As Integer) ' Check if this person wants the email. 2

3

If WantsEmail = True Then ' Make sure the EmailAddress isn't blank or null. If EmailAddress = "" Or IsNull(EmailAddress) Then

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-1.html (4 of 11) [1/7/2007 7:14:09 AM]

Section 17.1. Exploring the VB Language

' This is considered invalid. ' Cancel the change and show a message. MsgBox "You can't be notified without an email address." Cancel = True End If

4 5 6

7 End If 8 End Sub

Here's how it works: ● ● ●



Lin e 1 declares a code rout ine t hat handles t he Before Updat e event of t he form . Not ice t hat t his event handler get s one piece of inform at iona t rue or false value nam ed Cancel, which you can set t o st op t he updat e. Lin e 2 st art s an I f block t hat checks if t he Want sEm ail checkbox has a check- m ark in it . Lin e 3 perform s a second check. I t 's a bit m ore com plex because t here are t wo t hings t hat can cause t he condit ional code t o run. I t runs if t he em ail address is a blank value ( which happens if som eone ent ers an em ail address, and t hen delet es it ) or if t he em ail address is null ( which m eans t hat an em ail was never ent ered in t he first place; see Sect ion 4.1.2 for a discussion of null values) . Lin e 4 shows an explanat ory error m essage. Rem em ber, t he code get s t o t his spot only if bot h t he I f blocks evaluat e t o t rue. I f eit her check t urns out false ( t he Want sEm ail checkbox isn't t urned on, or t he Em ailAddress is supplied) , Access breezes right on past .

Note: Technically, you could combine both these If blocks into a single If block by writing a more complex condition that checks for everything at once. However, getting this right (and understanding what you've written later on) is more difficult. Veteran programmers know that it's always better to write code clearly, even if that makes the code a little more verbose. ● ●

Lin e 5 cancels t he updat e using t he Cancel param et er t hat t he On Before Updat e event provides. That way, t he change doesn't go ahead and t he record rem ains in edit m ode. Lin e s 6 t o 8 finish up by closing bot h I f blocks, and ending t he subrout ine.

Access has m any event s you can cancel, like On Before Updat e. Look for t he Cancel param et er bet ween t he parent heses aft er t he subrout ine nam e. I f it 's t here, you can set it t o True t o st op t he act ion t hat 's about t o occur.

17.1.3. Repeating Actions with a Loop A loop is a t ool t hat let s you repeat an operat ion as m any t im es as you want . Visual Basic has several t ypes of loops you can use. The m ost popular are t he Do/ Loop block, and t he For/ Next block, bot h of which you'll see in t his sect ion. Here's an exam ple Do/ Loop block t hat 's sure t o infuriat e people: Do MsgBox "Ever ever get that nagging deja vu feeling?" Loop

When Access ent ers t his block of code, it st art s by displaying t he Message box and pausing your code. Once you click OK, t he code cont inues unt il Access reaches t he final Loop st at em ent at t he bot t om of t he loop. At t his point , Access aut om at ically j um ps back t o t he beginning ( t he Do st at em ent ) and repeat s your code, showing a second Message box. However, t here's one problem t his process cont inues forever! I f you m ake t he m ist ake of running t his piece of code, your dat abase will be locked up indefinit ely ( unt il you press t he em ergency- st op key com binat ion, Ct rl+ Break) . To avoid t his sit uat ion, you should build all loops wit h an exit condit ion, a condit ion t hat signals when t he loop should end. Here's a rewrit t en version of t he sam e loop t hat st ops aft er it 's shown a m essage five t im es: ' Keep track of how many times you've looped. Dim NumberOfTimes ' Start the count at 0.

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-1.html (5 of 11) [1/7/2007 7:14:09 AM]

Section 17.1. Exploring the VB Language

NumberOfTimes = 0 Do MsgBox "Ever ever get that nagging deja vu feeling?" ' Up the count by 1. NumberOfTimes = NumberOfTimes + 1 Loop Until NumberOfTimes = 5

The im port ant bit 's t he final clause at t he end of t he loop block, Unt il Num berOfTim es = 5. This clause defines a condit ion, and as soon as it 's t rue ( t he Num berOfTim es variables reaches 5) and Access reaches t he end of t he loop, it j um ps out and cont inues running t he rest of your subrout ine. I f you have t his t ype of code, where you're looping a fixed num ber of t im es, t hen you m ay be int erest ed in t he For/ Next loop. The For/ Next loop is exact ly t he sam e as t he Do/ Next loop, except t hat it has a built - in count er, which it increm ent s for you. Here's how you could rewrit e t he previous exam ple in a m ore com pact form wit h a For/ Next loop: Dim NumberOfTimes For NumberOfTimes = 1 To 5 MsgBox "Ever ever get that nagging deja vu feeling?" Next

The im port ant part 's Num berOfTim es = 1 To 5, which t ells Access t o st art Num berOfTim es at 1, t o increm ent it by 1 at t he beginning of each pass t hrough t he loop, and t o st op aft er t he fift h pass. The Do/ Loop block works well when you need t o m ove t hrough a collect ion of dat a. You can use t he loop t o keep going unt il you run out of inform at ion, even t hough you don't know how m uch inform at ion t here is when you first st art t he loop. You'll see an exam ple of t his t echnique at t he end of t his chapt er ( Sect ion 17.4.5) , when you perform a bat ch updat e on your dat abase using code. On t he ot her hand, t he For/ Next loop shines when you can det erm ine at t he out - set exact ly how m any t im es you want t o repeat a loop. You'll see an exam ple where t his is t rue lat er in t his chapt er ( Sect ion 17.1.5) , when you t est credit card num bers.

17.1.4. Creating Custom Functions You've already learned how t o creat e your subrout ines. But you haven't yet seen how t o creat e t heir big brot her, funct ions. Like a subrout ine, a funct ion's a self- cont ained piece of code t hat can hold as m any or as few st at em ent s as you want . And like subrout ines, you add funct ions t o m odules. I n fact , any num ber of subrout ines and funct ions can exist side by side in a m odule. Function DoSomething() ' Function code goes here. End Function

The key difference bet ween funct ions and subrout ines is t hat a funct ion produces a final result . I n ot her words, funct ions give you a piece of inform at ion t hat you m ay need. You set t he result by writ ing a line of code t hat assigns t he result value t o t he funct ion nam e. ( Essent ially, you pret end t hat t he funct ion nam e's a variable where you can st uff som e dat a.) Here's an exam ple: Function GetMyFavoriteColor() GetMyFavoriteColor = "Magenta" End Function

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-1.html (6 of 11) [1/7/2007 7:14:09 AM]

Section 17.1. Exploring the VB Language

This funct ion's nam ed Get MyFavorit eColor. The result 's t he t ext st ring " Magent a" . Calling a funct ion is slight ly different t han calling a subrout ine. To call a subrout ine, you use t he m odule nam e, followed by a period, followed by t he subrout ine nam e. You can use t he sam e t echnique wit h a funct ion, as shown here: MyModule.GetMyFavoriteColor

However, t here's a problem . This st ep t riggers t he Get MyFavorit eColor funct ion, causing it s code t o run, but it t osses away t he result ( t he st ring wit h t he t ext " Magent a" ) . I f you're int erest ed in t he result , t hen you can call your funct ion as part of an assignm ent st at em ent . The following code creat es a variable, uses it t o st ore t he result , and t hen displays t he result in a Message box: ' Create a variable to store the result in. Dim Color ' Call the function and hold on to the result in the variable. Color = MyModule.GetMyFavoriteColor ' Show the result in a Message box. MsgBox "Your favorite color is " & Color

I f you're really clever, you can short en t his code t o a single line and avoid using t he Color variable alt oget her: MsgBox "Your favorite color is " & MyModule.GetMyFavoriteColor

The Get MyFavorit eColor funct ion's part icularly sim ple because it doesn't use any argum ent s. But t here's no reason you can't get a lit t le fancier. Consider t he following cust om funct ion, which t akes t wo argum ent slengt h and widt hand calculat es t he t ot al area by m ult iplying t hem t oget her: Function Area(Length, Width) Area = Length * Width End Function

The t wo param et ers are defined in t he parent heses aft er t he funct ion nam e. You can add as m any param et ers as you want , as long as you separat e each one wit h a com m a. Here's how you call t his funct ion and show t he result . I n t his exam ple, fixed num bers are used for t he Lengt h and Widt h param et ers. However, t here's no reason you can't subst it ut e a field nam e, variable, or propert y t hat you want t o use wit h t he Area funct ion inst ead. MsgBox "The area of a 4x4 rectangle is " & Area(4, 4)

This displays t he m essage " The area of a 4x4 rect angle is 16." Neit her t he Get MyFavorit eColor( ) nor Area( ) funct ion shows you anyt hing part icularly im pressive. But in t he next sect ion of t his chapt er, you'll build a m uch m ore powerful cust om funct ion t hat t est s credit card num bers.

POWER USERS' CLINIC Using a Custom Function in a Query

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-1.html (7 of 11) [1/7/2007 7:14:09 AM]

Section 17.1. Exploring the VB Language

Once you've creat ed a funct ion, you can use it anywhere in your dat abase t o build queries and validat ion rules. The only requirem ent s are t hat your funct ion m ust be in a cust om m odule t hat you've added ( not a form m odule) , and it can't include t he word Privat e in t he declarat ion. I f your funct ion m eet s t hese rules, t hen you can call upon it j ust as easily as a built - in Access funct ion. You could creat e a query wit h a calculat ed field like t his ( assum ing t he query includes t wo fields nam ed Lengt hOfRoom and Widt hOfRoom , respect ively) : RoomArea: Area(LengthOfRoom, WidthOfRoom)

Or, you could build a t able validat ion rule like t his: Area(LengthOfRoom * WidthOfRoom) < 10000

See Chapt er 7 for som e m ore ideas about using funct ions in calculat ed fields, and Chapt er 4 for m ore inform at ion about validat ion rules. And if you want t o see t his specific exam ple in act ion, check out t he MyHouse dat abase t hat 's included wit h t he sam ples for t his chapt er.

17.1.5. Putting It All Together: A Function for Testing Credit Cards Now t hat you've m ade your way around t he Visual Basic language, it 's t im e t o wrap up wit h an exam ple t hat dem onst rat es everyt hing you've learned about VB ( and a lit t le bit m ore) . I n t his exam ple, you'll consider a cust om funct ion called Validat eCard t hat exam ines a credit card num ber. The Validat eCard funct ion ret urns one of t wo result s: True ( which m eans t he card num ber's valid) and False ( which m eans it 's not ) . I t 's im port ant t o underst and t hat a valid credit card num ber's sim ply a num ber t hat m eet s all t he not - so- secret rules of credit card num bering ( t he box in Sect ion 17.1.5 t ells you m ore) . This num ber m ay be at t ached t o a real credit card, or it m ay not . The Validat eCard funct ion's j ust sm art enough t o cat ch inadvert ent errors and not - so- bright com put er hackers. Truly sneaky people can find program s t hat let t hem generat e pot ent ially valid credit card num bers. Here's t he full code for t he Validat eCard funct ion. Each code st at em ent 's num bered so you can break it down one piece at a t im e ( a line- by- line explanat ion follows t he code) : 1 Function ValidateCard(CardNumber As String)

2 3

' This is the running total (created using Luhn's algorithm). Dim SumOfDigits SumOfDigits = 0 ' This keeps track of whether you're at an odd or even position. ' You start on an odd number position (1).

UP TO SPEED The Luhn Algorithm

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-1.html (8 of 11) [1/7/2007 7:14:09 AM]

Section 17.1. Exploring the VB Language

The Validat eCard uses som et hing called t he Luhn algorit hm , which was developed by an I BM scient ist in t he 1960s. The Luhn algorit hm works because credit card com panies follow it s rules. I n ot her words, t hey issue only num bers t hat are considered valid according t o t he Luhn algorit hm . For a com plet e explanat ion of t he Luhn algorit hm , check out ht t p: / / en.wikipedia.org/ wiki/ Luhn_algorit hm . Here's t he Reader's Digest version of what it does: 1. St art ing at t he end of t he end of t he credit card num ber, double t he value of every second digit . Leave t he even- num bered digit s alone. For exam ple, 1111 becom es 2121. 2. I f t his doubling process produces a num ber larger t han 9, add t he t wo digit s in t hat num ber t oget her. For exam ple, 1166 becom es 2136. The second- t o- last num ber 6 was doubled ( t o 12) and t he digit s ( 1 and 2) were t ot aled ( t o m ake 3) . 3. Add all t hese digit s t oget her. I f you're current ly left wit h 2136, t hen calculat e 2+ 1+ 3+ 6 ( which m akes 12) . 4. I f t he t ot al ends in 0 ( or, put anot her way, if t he t ot al's divisible by 10) , t he num ber's valid. Ot herwise it 's not . The Luhn algorit hm checks t o see if t he num ber you've supplied is a possible credit card num ber. However, t he Luhn algorit hm can only do so m uch. I t can't cat ch a credit card num ber t hat 's t echnically valid but not act ually hooked up t o an account ( and it obviously can't det erm ine whet her som eone's credit card account 's in good st anding and has t he required purchasing lim it ) .

4 5

Dim OddNumbered OddNumbered = True

6 7 8 9

Dim i For i = Len(CardNumber) To 1 Step -1 Dim CurrentNumber CurrentNumber = Mid(CardNumber, i, 1)

10 11 12

13 14 15 16 17 18 19

If OddNumbered = False Then ' Double the digit. CurrentNumber = CurrentNumber * 2 If CurrentNumber >= 10 Then ' If this number is two digits, add them together. ' This is the wacky part, because you need to use ' string conversion functions. Dim NumText As String NumText = CurrentNumber CurrentNumber = Val(Left(NumText, 1)) + Val(Right(NumText, 1)) End If End If ' Add the number to the running total. SumOfDigits = SumOfDigits + CurrentNumber ' Switch from odd to even or even to odd. ' This line of code changes True to False or

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-1.html (9 of 11) [1/7/2007 7:14:09 AM]

Section 17.1. Exploring the VB Language

' False to True OddNumbered = Not OddNumbered

20 21

Next

22 23 24 25 26

' If the sum is divisible by 10, it's a valid number. If SumOfDigits Mod 10 = 0 Then ValidateCard = True Else ValidateCard = False End If

27 End Function

Here's how it works: ●

● ● ●

Lin e 1 declares t he funct ion. Not ice t hat t he funct ion t akes one param et er, which is t he t ext wit h t he credit card num ber. This param et er's explicit ly ident ified as a st ring wit h t he As St ring clause. This way, you avoid errors where som eone m ight t ry t o pass in an act ual num ber. Lin e s 2 3 creat e t he variable t hat st ores t he running t ot al during t he whole process. Lin e s 4 5 creat e t he variable t hat keeps t rack of whet her you're on an odd num ber posit ion or an even num ber posit ion. Rem em ber, all second num bers m ust be doubled. Lin e s 6 7 st art a For/ Next loop. This loop looks a lit t le different from t he ones you saw earlier, because it has t he St ep - 1 clause at t he end. This clause t ells t he loop t o subt ract 1 from t he count er aft er every pass ( rat her t han adding 1, which is t he st andard behavior) . You can work your way from t he end of t he num ber t o t he front .

Note: The For/Next loop uses another trick. The lower limit's set using the Len function (Section 7.2.5), which gets the length of a piece of text. In other words, if the credit card is 11 digits, this code runs 11 times (once for each digit).



● ● ● ● ● ●

Lin e s 8 9 grab t he num ber at t he current posit ion, as indicat ed by t he loop count er. The Mid funct ion let s you snip out a single digit . ( You learned about t he Mid funct ion in Sect ion 7.2.5.) Lin e 1 0 checks if you're on a second num ber. Lin e s 1 1 1 7 run only if you're on a second num ber. I n t his case, t he num ber needs t o be doubled ( line 11) . I f t he doubled num ber has t wo digit s, t hese digit s m ust t hen be com bined ( lines 1315) . Lin e 1 9 adds t he current num ber t o t he running t ot al. I f you were in an even- num bered posit ion, t hen t he num ber hasn't been changed. I f you were in an odd- num bered posit ion, t hen it 's been doubled and com bined. Lin e 2 0 m akes sure t hat if you j ust processed an even- num bered posit ion, you're swit ched t o an odd- num bered posit ion ( and vice versa) . Lin e 2 1 ret urns t o line 6 and repeat s t he loop for t he next digit in t he credit card num ber. Lin e s 2 2 2 6 check t he final t ot al. I f it 's divisible by 10, it 's valid. To find out , t his code uses t he Mod operat or, which perform s division, and t hen get s t he rem ainder. ( I f t here's no rem ainder when you divide a num ber by 10, you know it divided evenly wit hout a problem .)

I t m ay t ake som e t im e t o work t hrough t he funct ion and figure out exact ly what 's going on, but in t he end it 's all about VB basics like condit ions, loops, and variables. I f you really want t o st udy t his exam ple, you can wat ch it in act ion, using t he debugging t echniques t hat are covered in Sect ion 17.2.1. Once you've finished creat ing a funct ion like Validat eCard, you can call it t o t est whet her a credit card checks out . Here's an exam ple t hat react s when credit card inform at ion's ent ered int o a t ext box nam ed CardNum ber: Private Sub CardNumber_BeforeUpdate(Cancel As Integer) If ValidateCard(CardNumber) Then MsgBox "Your card is valid." Else MsgBox "Your card is invalid. " & _ "Did you forget a number, or are you trying to cheat us?" Cancel = True End If End Sub

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-1.html (10 of 11) [1/7/2007 7:14:09 AM]

Section 17.1. Exploring the VB Language

To t ry it out , run t his code and supply one of your credit card num bers in t he CardNum ber field, as shown in Figure 17- 3. Or send your credit card num bers t o t he aut hor so he can conduct his own ext ensive t est ing.

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-1.html (11 of 11) [1/7/2007 7:14:09 AM]

Section 17.2. Dealing with Trouble

17.2. Dealing with Trouble I t would be nice t o pret end t hat Access always sails t hrough your code wit hout t he slight est hiccup. But t he t rut h is, errors do occur, and t hey occur oft en. This fact shouldn't fright en you. Aft er all, one of t he reasons you're using Visual Basic code inst ead of ordinary m acros is so t hat you can det ect and respond t o errors gracefully.

Figu r e 1 7 3 . This form shows the ValidateCard function at work on the AddCreditCard form in the Boutique Fudge database. Whenever the CardNumber field's changed, a subroutine checks if it's valid, and cancels the change if it isn't.

You'll face t wo t ypes of errors wit h your code: ● ●

M ist a k e s. These errors are coding errors t hat you int roduce accident ally. Usually, you cat ch t hese while t est ing your dat abase. ( I f you're lucky, t he Visual Basic edit or spot s t he problem as soon as you t ype it in, and t hen warns you wit h a m essage.) Un e x pe ct e d lim it a t ion s. These errors arise under specific circum st ances t hat you m ay not have ant icipat ed. Say you creat e t wo form s: Order, and Order_ Subform . Order_Subform 's designed t o be used as a subform in Order, and it includes code t hat accesses t he cont rols in Order. However, if som eone opens Order_Subform direct ly, t he Order form isn't available, and t his code fails.

As a conscient ious program m er, it 's your j ob t o correct all your m ist akes and deal wit h unforeseen lim it at ions in t he best possible way. Visual Basic gives you t wo t ools t o help out . You can use debugging t o diagnose bizarre problem s and fix t hem , and you can use error handling code t o cat ch unexpect ed problem s, and alert ot her people.

17.2.1. Debugging Debugging's a nift y feat ure t hat let s you walk t hrough your code, wat ch what it does, and spot errors. Code debugging's sim ilar t o m acro debugging ( Sect ion 15.1.3) in t hat it let s you run your logic one st at em ent at a t im e. However, code debugging's m uch m ore powerful, because it let s you m ake your way t hrough com plex rout ines, loops, and condit ional st at em ent s. I t even let s you see what 's current ly st ored in your variables.

Tip: Debugging's real benefit is that it helps you test your assumptions. Every programmer has assumptions about how a piece of code works. However, if code did exactly what you expected, you wouldn't ever have an error. With debugging, you can find the exact point where code does something that you don't expectwhen a calculation provides a strange result, a conditional statement sends you the wrong way, a loop's repeated one time too many, and so on. Then you can correct the mistake. file:///C|/html/0596527608/access2007tm-CHP-17-SECT-2.html (1 of 6) [1/7/2007 7:14:15 AM]

Section 17.2. Dealing with Trouble

The easiest way t o perform debugging's t o set a breakpoint a special m arker t hat t ells Access where you want t o st art debugging. When Access reaches a line of code t hat has a breakpoint , it pauses your code. Access t hen let s you st ep t hrough t he code at your own pace, one line at a t im e. Here's how t o use a breakpoint : 1. Fin d t h e fir st lin e in you r code t h a t you w a n t t o de bu g. I f you want t o debug an ent ire rout ine, st art wit h t he opening Sub or Funct ion st at em ent . I f you want t o look at a specific sect ion of your code, go t here. 2. Click t h e m a r gin on t h e le ft t o pla ce a br e a k poin t on t h is lin e ( Figu r e 1 7 - 4 ) . Each breakpoint 's a signal t hat t ells Access you want t o st art debugging here. Som e lines can't accom m odat e a breakpoint . These lines don't cont ain execut able code, line blank spaces, com m ent s, and variable declarat ions. Everyt hing else is fair gam e.

Figu r e 17-4. Every breakpoint looks like a red circle. You can remove a breakpoint by clicking it. In this example, the breakpoint (circled) is placed at the beginning of the ValidateCard function.

Note: When you close your database and open it later, all your breakpoints disappear. 3. Tr igge r you r code .

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-2.html (2 of 6) [1/7/2007 7:14:15 AM]

Section 17.2. Dealing with Trouble

You can get your code t o run in t he norm al way. I f you're debugging an event handler for a but t on click, open t he appropriat e form , and t hen click t he but t on. When Access reaches your breakpoint , it pauses and swit ches int o break m ode. Everyt hing in your applicat ion's put on hold. Once you're in break m ode, you have several opt ions: ●

You ca n sin gle - st e p t h r ou gh you r code . That m eans you run one st at em ent at a t im e, pausing aft er each st at em ent . To t ry t his out , press t he F8 key. This act ion runs t he current st at em ent ( which is highlight ed wit h t he yellow arrow) , m oves t o t he next execut able st at em ent , and t hen pauses again ( Figure 17- 5) . You can cont inue for as long as you want , pressing F8 t o run each line of code.

Tip: Single-step debugging lets you follow how your code works. If you try it with the ValidateCard function shown earlier, you'll see how Access moves through the loop several times, and how it branches into different conditional sections depending on whether it's processing a number in an odd or even position.

Figu r e 1 7 - 5 . In this example, the breakpoint stopped the code at the beginning of the ValidationCard function. Then, the person debugging this code hit F8 a few times to move on through the code. Right now, the code's paused at the beginning of the For/Next loop (circled).

● ●

You ca n st op r u n n in g you r code . Press t he St op but t on ( it looks like a square) in t he Visual Basic t oolbar t o shut your code down. You ca n m a k e ch a n ge s. I f you find what 's wrong, you can edit your code, and t hen keep running wit h t he new changes. Of course, t here are cert ain t ypes of edit s t hat force Access t o st op debugging. I f you m ake one of t hese changes, t hen you see a Message box t hat warns you t hat " This act ion will reset your proj ect ." I f you click OK, t hen Access st ops your code j ust as if you had clicked t he Visual Basic t oolbar's St op but t on. You ca n se e w h a t 's st or e d in side a va r ia ble . To do so, j ust hover over t he variable nam e som ewhere in your code ( Figure 17- 6) .

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-2.html (3 of 6) [1/7/2007 7:14:15 AM]

Section 17.2. Dealing with Trouble

Figu r e 1 7 6 . By hovering over the CurrentNumber variable, you can see that it's currently storing the number 4. You can hover over variables on any line in your code, not just the current line. However, you'll see only the current contents of the variable. If you use F8 to single-step through your code, then you can watch a value change as you perform operations.



You ca n r e su m e n or m a l e x e cu t ion . I f you've found t he source of your problem and you don't want t o keep debugging, j ust hit F5 ( or click t he Visual Basic t oolbar's Play but t on) . Access runs t he current line, and t hen cont inues on it s m erry way ( at least unt il it m eet s anot her breakpoint ) .

Tip: You can pull off a wacky trick with the yellow arrow. You can use it to run code in a completely different place. Just drag the yellow arrow to the line you want to run next, and then hit F5 to switch out of debug mode, and resume running your code normally.

The Visual Basic edit or has m any m ore debugging t ools. However, breakpoint s are really all you need t o st art exploring what 's t aking place under t he hood when you run your code.

17.2.2. Error Handling Som e errors occur t hrough no fault of your own. Perhaps you're t rying t o perform a t ask wit h inform at ion som eone else gave you, and t hat inform at ion j ust isn't valid. I m agine what happens if som eone calls Validat eCard and passes in a credit card num ber t hat cont ains let t ers and punct uat ion! Alt hough t his sort of error can occur as a result of som ebody else's carelessness, it 's up t o you t o deal wit h it in t he best way possible. You need t o explain t he problem wit h a helpful Message box, and end t he current t ask ( or j um p ahead t o t he next st ep) . You can t ake care of t his j ob wit h error handling code.

Tip: The best way to perfect a piece of code's to use debugging to find and fix all its problems. Once you've finished this process, you can add error handling code to deal with the unexpected problems. If you add error handling code earlier, then you may find it a bit harder to debug your application.

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-2.html (4 of 6) [1/7/2007 7:14:15 AM]

Section 17.2. Dealing with Trouble

Ordinarily, when Access encount ers an error, it j um ps t o t he offending code, ent ers break m ode, and shows you an error m essage. This behavior's helpful if you're planning t o debug t he problem , but it 's a bit t raum at ic for t he ordinary people who m ay be using your dat abase. Not only have t hey never seen code before, t hey're in danger of changing it and int roducing a new problem . I nst ead, you need a way t o deal wit h t he error t he way you want , using code. Visual Basic has a special st at em ent t hat t ells Access how t o deal wit h errors. I t 's t he On Error st at em ent . The On Error gives you several opt ions. You can t ell Access t o skip over any errors and t ry t o run t he next line of code like t his: On Error Resume Next

This opt ion's alm ost always a bad idea. I f one error's occurred, m ore are likely t o follow. At worst , t his could cause your program t o do som et hing you don't int end it t o do. You can also t ell Access t o j um p t o a specific place in your code. Here's an exam ple: On Error Goto ErrorHandlingCode

This exam ple t ells Access t o j um p t o t he sect ion nam ed ErrorHandlingCode as soon as it encount ers any problem . You need t o ident ify t his sect ion by adding t he sect ion nam e, followed by a colon ( : ) on a separat e line, like t his: ErrorHandlingCode: ' If an error occurs, Access starts running your code here.

You can m ost easily underst and how t his error handling syst em works when you consider how you can use it in t he Validat eCard funct ion: Function ValidateCard(CardNumber As String) On Error Goto ErrorHandlingCode ' (The code for Luhn's algorithm goes here.) Exit Function ErrorHandlingCode: MsgBox "Oops. Did your credit card number have letters?" ValidateCard = False End Function

Here are several im port ant det ails. First , t he On Error st at em ent 's placed at t he very beginning of t he code rout ine, so you can cat ch m ist akes in any of t he code t hat follows. Second, not ice t hat aft er t he num ber- checking code finishes, an Exit Funct ion st at em ent ends t he rout ine. That st at em ent prevent s Access from drift ing int o t he error handling code t hat follows if an error hasn't happened. Finally, t he error handling code shows a Message box t hat explains t hat som et hing went wrong, and ret urns a result t hat clearly indicat es t he problem . People m ost oft en handle errors t his way. Just rem em ber t o always use an Exit Sub or Exit Funct ion st at em ent t o m ake sure you don't run your error handling code by accident .

Note: As written, the person using the AddCreditCard form may get two error messagesone explaining the letters-or-punctuation problem, and the second stating the obvious fact that validation failed. If this message seems like unnecessary punishment, then you can move the error-handling code out of the ValidateCard function and into the On Update event handler code, which is where it really belongs. That way, the On Update event handler can choose exactly how to deal with the problem. To see the slightly rear-ranged code, check out the downloadable samples for this chapter.

You have only one ot her opt ion for handling errors. You can t ell Access t o st op im m ediat ely and ent er debug m ode using t his st at em ent : On Error Goto 0

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-2.html (5 of 6) [1/7/2007 7:14:15 AM]

Section 17.2. Dealing with Trouble

Of course, t his behavior's already t he st andard error handling behavior. You need t o use t his st at em ent only if you're swit ching back and fort h bet ween different error handling approaches in t he sam e rout ine.

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-2.html (6 of 6) [1/7/2007 7:14:15 AM]

Section 17.3. Deeper into Objects

17.3. Deeper into Objects There com es a point in every Access program m er's life when you realize you've learned enough about t he VB language t o get by. From t hat point on, you spend m ost of your t im e learning about different obj ect s, which is a m uch larger t ask. Access has several dozen built - in obj ect s which, t aken t oget her, m ake up what program m ers call an obj ect m odel. Along wit h t he cont rol and form obj ect s you know so well, it has obj ect s represent ing queries, proj ect s, report s, sm art t ags, print ers, and m uch m ore. You can't cover all t hese obj ect s in a single chapt er. Even if you could, you'd find t hat m any of t hem j ust don't int erest you. However, you need t o know enough so t hat you can hunt down t he feat ures you need when you're t ackling a part icularly st icky VB challenge. You can explore t he Access obj ect m odel in several ways: ● ●

You can use t he Access Help. ( See Sect ion 16.4 for inst ruct ions about where t o look.) You can use t he online VBA ( Visual Basic for Applicat ions) reference t hat Microsoft provides. ( Surf over t o ht t p: / / m sdn. m icrosoft .com / office/ reference/ vba.)

Even if you work your way t hrough t he sprawling Access obj ect m odel, t here are st ill m any m ore obj ect s out t here. I f you're a black belt VB program m er, t hen you m ay choose t o creat e your own obj ect s. And even if you aren't , you m ay decide t o use anot her com ponent t hat gives you even m ore obj ect s t o play wit h.

Note: In programmer-speak, a component's just a file that has some objects you can use in your code. The file acedao.dll has the objects you can use to interact directly with your database (see Section 17.4.5).

Lat er in t his chapt er, you'll learn how t o use DAO ( t he dat a access obj ect s) t o int eract wit h your dat abase. DAO's such a com m on part of Access program m ing t hat m ost people t reat it as a built - in part of t he Access obj ect m odel. But t echnically, DAO consist s of a set of obj ect s provided by a separat e com ponent , which Access provides. Many m ore com ponent s are wait ing for you t o discover t hem . To use a new com ponent , you need t o add a reference t o t hat com ponent in your dat abase. To do so, in t he Visual Basic edit or's m enu, choose Tools References. You'll see t he References dialog box shown in Figure 17- 7.

Figu r e 1 7 - 7 . To add a reference to a component you want to use, find it in the list, and then place a checkmark next to it. The currently referenced

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-3.html (1 of 7) [1/7/2007 7:14:21 AM]

Section 17.3. Deeper into Objects

components appear at the top of the list. Here, you can see the objects that are automatically referenced in every databasethe objects built in Visual Basic, those that come with Access, and the data access objects you can use to read and edit the database directly (Section 17.4.5).

The References dialog box's problem is t hat you need t o know exact ly what com ponent you want t o use. The Available References list 's full of neat - sounding com ponent s t hat aren't designed for use in Access, and won't work right wit h your code. Am ong t he com ponent s you can use are ones from Microsoft t hat let you int eract wit h files, show Web pages, and int eract wit h ot her Office applicat ions. However, you won't get far experim ent ing on your own. I nst ead, you'll need t o find sam ple code online or in t he Access Help.

FREQUENTLY ASKED QUESTIONS Launching Other Windows Programs

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-3.html (2 of 7) [1/7/2007 7:14:21 AM]

Section 17.3. Deeper into Objects

How do I open Word ( or Excel, or Not epad, or Dance Dance Revolut ion) ? Visual Basic includes a funct ion nam ed Shell t hat let s you launch anot her program . To use t he Shell funct ion, you need t o supply t he com plet e pat h t hat point s t o t he program file. Here's an exam ple t hat runs t he Windows Calculat or Shell "C:\Windows\Calc.exe"

When you use Shell, Windows launches t he program you asked for, and your code keeps running. However, your code doesn't have any way t o act ually int eract wit h t he program . You can't force it t o do som et hing or find out if it 's been closed. Shell seem s like a convenient funct ion, but it has a m aj or problem . I n order t o use t he Shell funct ion, you need t o know exact ly where a program 's locat ed. You can't j ust say, " Launch Microsoft Word" or " Open t his docum ent ." I nst ead, you need t o dig down deep int o your hard drive t o find t he program file you need ( which is usually som ewhere in t he Program Files area of your com put er) . Even worse, once you get t he Shell funct ion working on your com put er, t here's no guarant ee it 'll work on som eone else'saft er all, t he sam e program could be inst alled som ewhere com plet ely different . So what can you do inst ead? You could use a hyperlink ( Sect ion 13.2.5) , which launches t he right program aut om at ically when it 's clicked. But som e program s, including t he ot her m em bers of t he Microsoft Office fam ily, give you a m uch bet t er opt ion. They provide t heir own obj ect s t hat you can m anipulat e in Visual Basic code. Wit h t hese obj ect s, you can use t hese program s wit hout worrying about where t hey're inst alled. You can also do way m ore wit h t hem by set t ing different propert ies and calling various m et hods. You can t ell Word t o open a docum ent , add som e t ext t o it , send 10 copies t o t he print er, and t hen quit . The obj ect s t hat m ake t his process work are beyond t he scope of t his book, but here's a very sim ple exam ple t hat launches Word, shows t he Word window, and t hen loads up a docum ent t hat 's nam ed Got hicWedding.doc: Dim Word As Object Set Word = CreateObject("Word.Application") Word.Visible = True Word.Documents.Open CurrentProject.Path & "\GothicWedding.doc"

I f t his t echnique int rigues you, check out Word's Help, where you can learn m uch m ore about t he Word obj ect m odel. Anot her helpful resource is Microsoft 's Office Developer Cent er at ht t p: / / m sdn.m icrosoft .com / office.

17.3.1. The DoCmd Object The DoCm d obj ect is t he single m ost useful obj ect in t he Access program m ing world. I t provides one- st op shopping for a variet y of t asks, like opening form s and report s, launching ot her program s, finding records, and running m acros. Unlike t he obj ect s you've seen so far, t he DoCm d obj ect doesn't have any propert ies. I nst ead, it 's m ade up of m et hods t hat perform different act ions. I f you want t o open a form nam ed Product Cat alog, you can use t he OpenForm m et hod like t his: DoCmd.OpenForm "ProductCatalog"

Like m ost of t he DoCm d m et hods, OpenForm can use several opt ional param et ers. Visual Basic prom pt s you by showing t he list of possible param et ers as you t ype. Here's an exam ple t hat skips over t he second and t hird param et ers ( not e t he com m as wit h no values in bet ween) but supplies a filt er in t he fourt h param et er, and a dat a m ode in t he fift h param et er. DoCmd.OpenForm "ProductCatalog", , ," ID=5", acFormReadOnly

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-3.html (3 of 7) [1/7/2007 7:14:21 AM]

Section 17.3. Deeper into Objects

This com m and opens t he Product Cat alog form , applies a filt er t o show only t he record wit h t he I D of 5, and uses read- only m ode t o prevent any changes.

Note: This example uses a acFormReadOnly, which is a constant. Constants are numeric values that are given more helpful names. So instead of remembering that the number represents read-only mode, you can use the more readable acFormReadOnly constant. Any time you see a variable that starts with ac or vb and you haven't created it yourself, the odds are that it's a constant. Of course, you still need to know the constant names to use them, but IntelliSense can help you out, as shown in Figure 17-8.

Figu r e 17-8. When you get to the data mode parameter, the Visual Basic editor pops up a list of all the valid constants that you can use. To find out what they really mean (if it's not obvious), you need to consult the Access Help.

I f t he OpenForm m et hod looks fam iliar, t hat 's because you've already seen t he sam e funct ions wit h t he OpenForm m acro act ion ( Sect ion 15.3.1) . I n fact , all t he m et hods of t he DoCm d obj ect line up wit h t he m acro act ions you learned about in Chapt er 15. Table 17- 1 list s t he m ost useful ones.

Ta ble 1 7 - 1 . Use fu l M e t h ods of t h e D oCm d Obj e ct

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-3.html (4 of 7) [1/7/2007 7:14:21 AM]

Section 17.3. Deeper into Objects

M e t h od

D e scr ipt ion

ApplyFilt er

Applies a filt er t o a t able, form , query, or report , t o focus on t he records you're int erest ed in.

Beep

Makes som e noise. Usually, you use t his t o get at t ent ion if a problem occurs.

Close

Closes t he current dat abase obj ect ( or a specific one you indicat e) .

CopyDat abaseFile

Gives you a quick way t o m ake a dat abase backup.

FindRecord, FindNext , and GoToRecord

Gives you different ways t o search for t he record you want .

Hourglass

Swit ches t he hourglass m ouse point er on ( or off) . You can use t his m et hod t o let som eone know t here's a t im e- consum ing t ask underway, and she should chill.

OpenForm , OpenQuery, OpenReport , and OpenTable

Opens t he appropriat e dat abase obj ect , in what ever view m ode you want , wit h filt er set t ings and ot her opt ional det ails. As you learned in Chapt er 15, you can also use OpenReport t o print a report , and OpenQuery t o run an act ion query.

Print Out

Offers one way t o print t he dat a from t he current dat abase obj ect .

Quit

Exit s Access.

RunCom m and

A fill- in- t he- gaps com m and t hat let s you run various Access com m ands available on t he ribbon. You j ust need t o supply t he right const ant . Sect ion 17.4.4 shows an exam ple where som eone uses Run- Com m and t o save t he current record im m ediat ely.

RunMacro

Runs a m acro.

RunSQL

Execut es a raw SQL st at em ent ( see Sect ion 6.2.3) . You can't use t his com m and t o get inform at ion out of your dat abase. I nst ead, it let s you run com m ands t hat change records or t ables.

ShowAllRecords

Rem oves t he current filt er set t ings so you can see all t he records in a t able, form , query, or report .

17.3.2. Converting a Macro to VB Code I f you want t o learn a lit t le m ore about Visual Basic and t he DoCm d obj ect , t hen you can t ake an exist ing m acro and convert it int o a pure code subrout ine. Here's how: 1. I n t h e n a viga t ion pa n e , se le ct t h e m a cr o you w a n t t o u se . 2. M a cr o Con ve r t M a cr os t o Visu a l Ba sic. ( You ca n a lso con ve r t t h e e m be dde d Se le ct D a t a ba se Tools m a cr os in a for m by ope n in g t h a t for m , a n d t h e n ch oosin g D a t a ba se Tools M a cr o Con ve r t For m 's M a cr os t o Visu a l Ba sic.) A window wit h t wo opt ions appears ( Figure 17- 9) .

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-3.html (5 of 7) [1/7/2007 7:14:21 AM]

Section 17.3. Deeper into Objects

Figu r e 1 7 - 9 . You see this tiny window if you ask Access to convert the FindHayEater macro.

3. I f you w a n t t o a dd ba sic e r r or h a n dlin g ( a s de scr ibe d in Se ct ion 1 7 .2 .2 ) , t h e n m a k e su r e " Add e r r or h a n dlin g t o ge n e r a t e d fu n ct ion s" is t u r n e d on . A lit t le bit of error handling's always a good idea. 4. I f you w a n t t o t u r n you r m a cr o com m e n t s in t o VB com m e n t s, m a k e su r e " I n clu de m a cr o com m e n t s" is se le ct e d. I f you've t aken t he t im e t o add som e explanat ory t ext , it 's wort h keeping it around. 5. Click Con ve r t . Access creat es a new m odule for t he convert ed code, and gives it a nam e like Convert ed Macro- [ YourMacroNam e] . I nside t he m odule, Access creat es a funct ion wit h t he sam e nam e as your m acro. I f you convert a m acro group ( Sect ion 15.4) , Access adds one subrout ine for each m acro in t he group. Once t he conversion process is com plet e, Access opens your m odule in t he Visual Basic edit or so you can review t he code. The following exam ple shows t he result of convert ing a m acro from Chapt er 15 ( shown in Sect ion 15.3.1) which searches for specific t ext in t he Anim alTypes t able: Function FindHayEater( ) On Error GoTo FindHayEater_Err DoCmd.OpenForm "AnimalTypes", acNormal, "", "", , acNormal DoCmd.GoToControl "Diet" DoCmd.FindRecord "=""hay""", acAnywhere, False, , _ False, acCurrent, False FindHayEater_Exit: Exit Function FindHayEater_Err: MsgBox Error$ Resume FindHayEater_Exit End Function

You'll not ice t hat t he convert ed code m akes heavy use of t he DoCm d obj ect in fact , alm ost every line uses t he DoCm d obj ect . First , it uses t he OpenForm m et hod t o open a form , t hen it uses t he GoToCont rol m et hod t o swit ch t o t he Diet field, and finally file:///C|/html/0596527608/access2007tm-CHP-17-SECT-3.html (6 of 7) [1/7/2007 7:14:21 AM]

Section 17.3. Deeper into Objects

it looks for t he first record t hat has t he t ext " hay." This line looks a lit t le weird because it doubles up it s quot at ions m arks ( " " ) . Quot at ions m arks have a special m eaning t o Visual Basic ( t hey show where t ext begins and ends) . I f you act ually want t o insert a quot at ion m ark in your t ext , you need t o put t wo quot at ion m ark charact ers in a row. St range, but t rue. The code ends wit h an error- handling rout ine nam ed FindHayEat er_Err, which sim ply shows t he problem in a Message box, and t hen ends t he rout ine.

Note: When you convert a macro into code, Access always generates a function (Section 17.1.4), not a sub-routine. However, the function doesn't return a result, so it's not really necessary. (Presumably, Access works this way to give you the flexibility to decide later on that you want to return a value.)

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-3.html (7 of 7) [1/7/2007 7:14:21 AM]

Section 17.4. Using VB to Run a Better Business

17.4. Using VB to Run a Better Business Over t he last 16 chapt ers, you've com e t o know and love t he Bout ique Fudge dat a- base, which dem onst rat es a pract ical sales dat abase t hat t racks cust om ers, product s, and orders. However, alt hough t he Bout ique Fudge dat abase st ores all t he inform at ion you need, it st ill doesn't int egrat e seam lessly int o com pany life. And before you can fix it , you need t o underst and why it com es up short . Most people who work in a business like Bout ique Fudge aren't t hinking about t ables and dat a operat ions ( like insert ing, updat ing, and delet ing records) . I nst ead, t hey're t hinking about t asks, like placing an order, shipping an order, and handling a cust om er com plaint . Many t asks m at ch quit e closely wit h a dat a operat ion, in which case you really don't have a problem . The " regist er a new cust om er" t ask's clearly j ust a m at t er of opening t he Cust om ers t able, and t hen insert ing a new record. You can t ake care of it wit h a sim ple form . However, t he " place an order" t ask's a lit t le t rickier. This t ask involves insert ing records in m ore t han one t able ( t he Orders and Order- Det ails t ables) , and using dat a from relat ed t ables ( t he Product s and Cust om ers t ables) t o com plet e t he order. You can creat e an ordinary form t o do t he j ob, but t he form doesn't quit e work t he way salespeople want ( see Figure 17- 10) . The sam e's t rue when it com es t o t he " ship an order" t ask. This t ask requires several st epschanging t he st at us of t he order, logging t he shipm ent , and updat ing t he unit s- in- st ock num bers. You could deal wit h t his t ask as several separat e dat a operat ions, but it 's a lot nicer if you creat e a single form t hat t akes care of t he whole process. Now VB's t ruly useful. Wit h t he right code, you can design an int elligent form t hat fit s t he way people work. An int elligent form isn't j ust a way t o add, edit , and insert records in a t ableit 's a t ool t hat helps run your business.

Figu r e 17-10. This form lets you insert records into the Orders and OrderDetails tables. However, it lacks a few frills people expect in an

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-4.html (1 of 15) [1/7/2007 7:14:33 AM]

Section 17.4. Using VB to Run a Better Business

order formlike a way to automatically fill in the price of each product you're ordering, the ability to calculate totals as you go, and an option to add a new product on the fly.

I n t he following sect ions, you'll consider how t o build bet t er form s wit h som e code- powered feat ures. The following form s are covered: ● ● ●

Pla ce Or de r let s you creat e a new order. I t works in conj unct ion wit h t he PlaceOrder_Subform , which let s you add individual it em s t o t he order. AddPr odu ct let s you creat e a new product . You can use it direct ly from Place- Order form t o add a product in m id- order. Sh ipOr de r s let s you updat e an order wit h shipm ent inform at ion. I t also works wit h a form nam ed ReviewOrderDet ails t o show t he it em s in t he order.

You can check out t he final result wit h t he downloadable dat abases for t his chapt er ( Sect ion 3.4.2.3) .

Tip: It's always a good idea to name your form according to the task it performs (placing an order, shipping a task, and so on), rather than the table it uses. This design helps you remember who's using each form, so you can tailor it to the right audience.

17.4.1. Keeping a Running Total Few souls are brave enough t o place an order wit hout knowing exact ly how m uch it cost s. A t ypical order form shows how

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-4.html (2 of 15) [1/7/2007 7:14:33 AM]

Section 17.4. Using VB to Run a Better Business

m uch each line it em cost s ( by m ult iplying t he price and quant it y inform at ion) and t he ever- im port ant grand t ot al ( Figure 1711) .

Figu r e 17-11. The PlaceOrder form, with subtotals and a grand total.

Note: The PlaceOrder form also introduces a few refinements you already know about, like putting customer address information on a separate tab, moving the automatically generated fields (the order ID and the order date) to the bottom of the window where they won't distract anyone, and setting their Locked property (Section 13.2.2) to Yes to prevent changes. The form also has its Data Entry property (Section 12.3.6) set to Yes, so you start creating a new order as soon as you open the form.

The line t ot al's t he only det ail t hat doesn't require code. I n fact , you can solve t his problem by adding a t ext box t hat uses t he following expression t o t he PlaceOrder_Subform : =Quantity * Price

This expression works because t he inform at ion you need ( Price and Quant it y) is locat ed on t he sam e form as t he calculat e field. However, t he grand t ot al isn't as st raight forward. file:///C|/html/0596527608/access2007tm-CHP-17-SECT-4.html (3 of 15) [1/7/2007 7:14:33 AM]

Section 17.4. Using VB to Run a Better Business

To be even a bit nicer, you can com bine t his wit h t he Form at funct ion ( Sect ion 7.2.5) t o m ake sure you get t he right num ber of decim al places and a currency sym bol ( $) : =Format(Quantity * Price, "Currency")

I n order t o calculat e t he grand t ot al, you need t o use t he Quant it y and Price inform at ion in t he OrderDet ails t able. Unfort unat ely, t he PlaceOrder form doesn't have any easy way t o get t his inform at ion. Not only is t his inform at ion shown som ewhere else ( in a subform ) , but it also involves several separat e records. Even if you ret rieve t he Quant it y and Price inform at ion from t he subform , you can get only t he values for t he current record, not for t he whole list of ordered it em s. To solve t his problem , you need t o use a specialized Access funct ion called a dom ain funct ion. A dom ain funct ion can process an ent ire t able and ret urn a single piece of inform at ion. ( To learn m ore, see t he box below.)

UP TO SPEED Become a Master of Your Domain (Functions) The dom ain funct ions are like t he grouping funct ions you use in a t ot als query ( Sect ion 7.3) . These funct ions t ake a range of records, and t hen perform a calculat ion or lookup t o arrive at a single value. Access includes eight dom ain funct ions: ● ● ● ● ● ●

D Su m calculat es t he sum of m ult iple values. You can use it t o calculat e an order's t ot al price. D Avg calculat es t he average of m ult iple values. You can use it t o calculat e a product 's average price. D Cou n t count s t he num ber of m at ching records. You can use it t o count t he num ber of it em s in an order, or t he num ber of orders a cust om er m ade. D M in and D M a x find t he sm allest or largest value in a series. You can use t his funct ion t o find bargainbasem ent or t op- priced product s. D Fir st and D La st ext ract t he first or last value in a series. I f you sort a list of orders by dat e, t hen you can get t he oldest or m ost recent order. D Look u p finds a value t hat m eet s specific crit eria. You can use it t o hunt t hrough a t able and find t hr product nam e for a given product I D.

All t he dom ain funct ions t ake t he sam e t hree param et ers. The first param et er's t he field ( or calculat ed expression) you want t o ret rieve or use in your calculat ion. The second param et er's t he t able or query you're using. The t hird param et er cont ains any filt er condit ions you want t o use t o narrow down t he num ber of rows. I f you're t rying t o find t he average price of all t he beverages sold by Bout ique Fudge, t hen you use t he Price field ( as t he first param et er) , Product s t able ( t he second param et er) , and filt er it t o include j ust t hose product s in t he Beverages cat egory ( t he t hird param et er) .

To calculat e t he t ot al of all t he it em s in an order, you use t he DSum funct ion. The inform at ion you need's in t he OrderDet ails t able, but you want t o select only t hose records where t he OrderI D field m at ches t he current order. Finally, you need t o add t oget her t he cost of each it em . And as you know from before, you calculat e t he cost of a line by m ult iplying t oget her t he Price and Quant it y fields. Wit h t his inform at ion in m ind, you can creat e t he following calculat ed field: =DSum("Price*Quantity","OrderDetails","OrderID=" & [ID])

The first argum ent 's t he calculat ed field t hat you're t aking from each record. The second argum ent 's t he nam e of t he t able you're using. The t hird argum ent filt ers out j ust t hose records t hat m at ch t he current order. I f t he current order has an I D of 455, t hen t he final param et er m at ches all OrderDet ails records where OrderI D= 455. Once again, you can wrap t he whole t hing wit h t he Form at funct ion if you want t he final num ber t o look like a currency value.

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-4.html (4 of 15) [1/7/2007 7:14:33 AM]

Section 17.4. Using VB to Run a Better Business

This calculat ed field does t he t rick, but you need one m ore enhancem ent . Ordinarily, Access com put es calculat ed fields t he first t im e a record's shown. However, you need t o m ake sure t hat t he grand t ot al's recalculat ed every t im e you m ake a change in t he list of ordered it em s. To accom plish t his, you need t o call t he Form . Recalc m et hod when an OrderDet ails record's insert ed, updat ed, or delet ed. Here's t he code t hat does t he t rick: Private Sub Form_AfterInsert( ) Forms("PlaceOrder").Recalc End Sub Private Sub Form_AfterUpdate( ) Forms("PlaceOrder").Recalc End Sub Private Sub Form_AfterDelConfirm(Status As Integer) Forms("PlaceOrder").Recalc End Sub

Now you can creat e and fill out an order, wit hout wondering how m uch it 's going t o cost .

17.4.2. Getting Price Information As you learned in Chapt er 5, som et im es a t able needs t o st ore point - in- t im e dat ainform at ion t hat 's copied from one t able t o anot her because it m ight change over t im e. A good exam ple is product prices, which evolve over t im e. ( " Evolve" is a polit e way t o say, " increase relent lessly." ) So a product 's current isn't necessarily t he price at which you ordered it last week. I n order t o keep t rack of how m uch you owe t he com pany, t he selling price of a product needs t o be st ored in t he OrderDet ails t able. However, t his syst em creat es a headache when you fill out an order. Choosing an order it em 's easy enoughyou j ust need t o select t he product from a lookup list . However, t he lookup list set s t he Product I D field only for t he OrderDet ails record. I t 's up t o you t o figure out t he correct price, and t hen copy it from t he Product s t able t o your new record. Fort unat ely, you can m ake t his m uch easier. You can react t o t he On Change event in t he Product I D list , which is t riggered every t im e a product 's select ed. Then, you can use t he DLookup dom ain funct ion t o find t he corresponding price, and insert it in t he Price field aut om at ically. Here's t he code t hat does it : Private Sub ProductID_Change( ) Price = DLookup("Price", "Products", "ID=" & ProductID) Quantity = 1 End Sub

This code also set s t he Quant it y field t o 1, which is a reasonable st art ing point . I f necessary, you can edit t he Price and Quant it y fields aft er you pick your product . Or, t o creat e a m ore st ringent form , you can set t he Locked propert y of t he Price cont rol t o Yes, so t hat no price changes are allowed ( as in t he Bout ique Fudge dat abase) . This way, when you creat e an order, you're forced t o use t he price t hat 's current ly in affect , wit h no discount ing allowed.

Note: You can use the same technique to fill in other point-in-time data. You can grab the address information for the current customer, and use that as a starting point for the shipping address. And you can even use the DLookup function to create more sophisticated validation routines. You could use this technique with the Cacophoné Music School database, to look up prerequisites and maximum class sizes before letting a student enroll in a class.

17.4.3. Adding a New Product During an Order Bout ique Fudge is a cust om er- driven com pany. I f som eone want s an innovat ive product t hat 's not yet in t he product cat alog ( like fudge- dunked pot at oes) , t he com pany's willing t o creat e it on dem and.

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-4.html (5 of 15) [1/7/2007 7:14:33 AM]

Section 17.4. Using VB to Run a Better Business

Ordinarily, t he Product I D lookup list doesn't allow t his sort of on- t he- fly product creat ion. I f you t ry t o t ype in a product t hat doesn't exist , t hen you get a st ern reprim and from Access. However, adding new list it em s on t he go is a com m on Access program m ing t echnique, and dedicat ed event 's designed t o help you out : t he On Not I n List event . I f you t ype in a product t hat doesn't exist and you're using t he On Not I n List event , t hen Access st art s by running your event handling code. You can creat e t he it em if you want , show a different m essage, or correct t he problem before Access com plains. The On Not I n List event has t wo param et ers: NewDat a and Response. NewDat a is t he inform at ion t hat was t yped int o t he list box, which isn't found in t he list . Response is a value you supply t o t ell Access how t o deal wit h t he problem . Here's t he basic skelet on of t he subrout ine t hat Access creat es if you choose t o handle t he On Not I n List event for t he field nam ed Product I D: Private Sub ProductID_NotInList(NewData As String, Response As Integer) End Sub

When t he On Not I n List event occurs, you should first ask t he person using t he form if t hey m eant t o ent er a product t hat doesn't exist . You can t ake t his st ep using t he fam iliar MsgBox funct ion in a slight ly different way. First , you need t o add a second param et er t hat t ells Access t o creat e a Message box wit h Yes and No but t ons. Then, you need t o get hold of t he ret urn value from t he MsgBox funct ion t o find out which but t on was clicked: Dim ButtonClicked ButtonClicked = MsgBox("Do you want to add a new product?", vbYesNo)

This code creat es a variable nam ed But t onClicked, and t hen shows t he m essage. When t he person closes t he Message box ( by clicking Yes or No) , Visual Basic put s a num ber int o t he But t onClicked variable t hat t ells you what happened. The num ber's 6 if Yes was clicked, or 7 if No was clicked. But rat her t han deal direct ly wit h t hese num bers and risk m aking a m ist ake, you can use t he helpful const ant s vbYes ( which equals 6) and vbNo ( which equals 7) . Here's t he part ially com plet ed code for t he On Not I n List event handler. I t shows t he m essage asking if a new it em should be added ( Figure 17- 12) , and t hen cancels t he edit if t he person using t he form chooses No: Private Sub ProductID_NotInList(NewData As String, Response As Integer) ' Show a Yes/No message and get the result. Dim ButtonClicked ButtonClicked = MsgBox("Do you want to add a new product for " & _ NewData & "?", vbYesNo) ' Visual Basic gives you hand vbYes and vbNo constants ' that you can use to find out what button was clicked. If ButtonClicked = vbNo Then ' Cancel the edit. ProductID.Undo ' Tell Access not to show the error message. ' You've already dealt with it. Response = acDataErrContinue Else ' (Put some code here to add a new product.) End If End Sub

Then you supply t he code t hat adds t he new product . I n t his exam ple, it doesn't m ake sense for your code t o add t he product com plet ely on it s ownaft er all, a product needs ot her inform at ion ( like price and cat egory det ails) before it 's considered valid.

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-4.html (6 of 15) [1/7/2007 7:14:33 AM]

Section 17.4. Using VB to Run a Better Business

I nst ead, you need t o show anot her form for adding product s. The DoCm d.OpenForm m et hod's t he key: ' Tell Access not to worry, because you're adding the missing item. Response = acDataErrAdded ' Open the AddProduct form, with three additional arguments. DoCmd.OpenForm "AddProduct", , , , , acDialog, NewData

Figu r e 1712. FudgeDunked Potatoes is not a currently offered product. When you type it in, and then hit Enter, your code asks whether you really intend to add this product.

The t wo addit ional argum ent s you use wit h t he OpenForm m et hod are quit e im port ant : ●



a cD ia log opens t he form in dialog m ode, which m eans Access put s t he code in t he Product I D_Not I nList on hold unt il t he AddProduct form 's closed. That st ep's im port ant because once t he adding process is finished, you'll need t o run m ore code t o updat e t he PlaceOrder form . N e w D a t a t akes t he newly t yped- in inform at ion, and set s it in t he AddProduct . OpenArgs propert y. That way, t he AddProduct form can ret rieve t his inform at ion when it st art s up, and t hen adj ust it self accordingly.

Here's t he code you need in t he AddProduct form t o copy t he newly ent ered product nam e ( t he value you passed using t he NewDat a variable in t he previous code snippet ) int o t he Product Nam e field when AddProduct first loads:

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-4.html (7 of 15) [1/7/2007 7:14:33 AM]

Section 17.4. Using VB to Run a Better Business

Private Sub Form_Open(Cancel As Integer) ProductName = Form.OpenArgs End Sub

Figure 17- 13 shows what t his form looks like. Once you finish ent ering all t he product inform at ion, you can close t he Add- Product form . At t hat point , a lit t le m ore code runs in t he Product I D_Not I nList subrout ine. This code's placed im m ediat ely aft er t he DoCm d.OpenForm st at em ent . I t s j ob is t o updat e t he new order it em t o use t he product you've j ust ent ered:

Figu r e 1 7 1 3 . The AddProduct form lets you supply the rest of the information for the new product you want to create. Notice how the form opens as a popup form, and Access automatically assumes you're inserting a new record (not reviewing existing products). Access acts this way because the Pop Up and Data Entry properties of the form are both set to Yes.

' Cancel the edit. That's because you need to refresh the list ' before you can select the new product. ProductID.Undo ' Refresh the list. ProductID.Requery ' Now find the ProductID for the newly added item using DLookup. ProductID = DLookup("ID", "Products", "ProductName='" & NewData & "'")

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-4.html (8 of 15) [1/7/2007 7:14:33 AM]

Section 17.4. Using VB to Run a Better Business

Note: This code works even if you cancel the new product by hitting the AddProduct form's Esc key. In this case, the DLookup function can't find anything, so it returns a null (empty value) to the ProductID field. As a result, you get the familiar Access warning message telling you the product you picked isn't in the list.

There's one m ore det ail. By t he t im e t he On Not I n List event occurs, t he On Change event 's already t aken place. So you j ust m issed your chance t o run t he code you used earlier t o insert t he corresponding price int o t he Price field in t he list of order it em s. Fort unat ely, you can solve t his problem quit e easily. You j ust need t o add one m ore line of code t hat t ells Access t o go ahead and run t he event handler ( t he Product I D_Change subrout ine) again: ProductID_Change

To see t he com plet e code for t his exam ple in one place, refer t o t he sam ple Bout ique Fudge dat abase for t his chapt er.

17.4.4. Managing Order Fulfillment Now t hat you've perfect ed t he ordering process, you can t urn your at t ent ion t o what happens next . I n t he Bout ique Fudge dat abase, every record in t he Orders t able has an Order- St at us field t hat keeps t rack of t he, well, st at us. Newly creat ed order records have a New st at us. I n t he st ock room , t he warehouse workers look for orders wit h t he New st at us, and pick one t o st art working on. At t hat point , t hey change t he st at us of t his order t o I n Progress, so nobody else t ries t o ship it at t he sam e t im e. Finally, when t he order's com plet e, t hey change it t o Shipped, and t hen record t he exact t im e in t he ShipDat e field. Logically, t his m odel m akes sense. However, it 's a bit t ricky using ordinary t ables and form s. I n order t o follow t his workflow, t he warehouse st aff needs t o m odify t he st at us of an order record several t im es, rem em ber t o record t he ship dat e, and avoid changing ot her det ails. I f t hey m iss a st epsay t hey never put t he order int o I n Progress st at usit 's possible t hat m ore t han one em ployee could t ry t o com plet e t he sam e order. The solut ion's t o creat e a ShipOrders form t hat guides t he warehouse workers t hrough t he right st eps. I nit ially, t his form shows a list of orders wit h m inim al inform at ion ( Figure 17- 14) .

Figu r e 171 4 . The list of orders is sorted so that the oldest orders (which should be processed first) appear at the top of file:///C|/html/0596527608/access2007tm-CHP-17-SECT-4.html (9 of 15) [1/7/2007 7:14:33 AM]

Section 17.4. Using VB to Run a Better Business

the list. Each field's Locked property's set to Yes, so nobody can edit any data. However, next to each order is a Process button that starts the order fulfillment process. (You could also add filtering to this form, so that you see only orders with certain statuses.)

When som eone clicks t he Process but t on, several st eps need t o t ake place. Here's a st ep- by- st ep walk- t hrough of t he code, one chunk at a t im e. First , your code needs t o refresh t he record. That st ep cat ches whet her som eone else has st art ed processing t he order on anot her com put er: Private Sub ProcessOrder_Click() Form.Refresh

Next , your code needs t o check t he record's st at us. I f it 's anyt hing ot her t han New, t hat order isn't available for processing:

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-4.html (10 of 15) [1/7/2007 7:14:33 AM]

Section 17.4. Using VB to Run a Better Business

' The StatusID for New is 2. If StatusID 2 Then MsgBox "This order is not available."

Ot herwise, you need t o swit ch t he st at us t o I n Progress and save t he record right away, t o m ake sure no else t ries t o get it : Else ' The StatusID for In Progress is 3. StatusID = 3 ' Save the change. DoCmd.RunCommand acCmdSaveRecord

Note: It's extremely important to save the record (using the DoCmd.RunCommand method, as shown here) in this sort of situation. Otherwise, the order record remains in edit mode, and the new status isn't saved in the database. Other people might start processing it, because they have no way of knowing that you've changed the status.

Now it 's t im e t o launch t he ReviewOrderDet ails form , which displays a read- only view of all t he it em s in t he order ( Figure 1715) . The form 's opened in dialog m ode, which locks up t he ShipOrders form unt il t he order fulfillm ent process is com plet e: DoCmd.OpenForm "ReviewOrderDetails", , , _ "OrderID =" & ID, , acDialog End If End Function

The ReviewOrderDet ails form gives t he warehouse st aff t wo choices. I f t hey click Ship, t hen Access changes t he order st at us t o Shipped, and t he process is com plet e: Private Sub Ship_Click( ) ' Close this form. DoCmd.Close ' Switch back to the ShipOrders form. DoCmd.OpenForm "ShipOrders" ' Update the order. ' The StatusID for Shipped is 4. Forms("ShipOrders").StatusID = 4 DoCmd.RunCommand acCmdSaveRecord End Sub

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-4.html (11 of 15) [1/7/2007 7:14:33 AM]

Section 17.4. Using VB to Run a Better Business

Figu r e 1 7 1 5 . You don't need to include pricing details in the ReviewOrderDetails form. It's simply designed to give the warehouse people the information they need as efficiently as possible. The ReviewOrderDetails form also uses a query join to get some related data, like the PartNumber, from the Products table.

I n t he ReviewOrderDet ails form , t he propert ies Cont rol Box and Close But t on are bot h set t o No. That way, t he window doesn't give t he warehouse st aff any way t o close it except t o click t he Ship or Cancel but t ons. ( I f you don't use t his approach, t hen you need t o writ e ext ra code t hat reset s t he order's st at us if som eone clicks t he X icon in t he t op- right corner t o close t he ReviewOrderDet ails form .)

Tip: This spot's also a good place to use DoCmd.OpenReport to print out a report that creates a shipping insert with a list of all the products in the order.

But if t hey click Cancel ( perhaps because t hey've discovered t hey don't have t he right it em s in st ock) , sim ilar code's used t o ret urn t he order t o New st at us: Private Sub Cancel_Click( ) ' Close this form. DoCmd.Close ' Switch back to the ShipOrders form. DoCmd.OpenForm "ShipOrders" ' Update the order. Forms("ShipOrders").StatusID = 2 DoCmd.RunCommand acCmdSaveRecord End Sub

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-4.html (12 of 15) [1/7/2007 7:14:33 AM]

Section 17.4. Using VB to Run a Better Business

This part com plet es t he code you need t o coordinat e order processing. Like t he form s you learned about in Part Four of t his book, t he form s in t his exam ple draw all t heir inform at ion from your dat abase's t ables. But unlike t hose Part Four exam ples, t hese use code t o perform som e of t he work aut om at ically. This difference changes your form s from m ere dat a- ent ry t ools int o supercharged workflow t ools.

Tip: You could also create a special status value to denote orders that have been attempted but couldn't be completed (like On Hold or Waiting For Stock). That way, the warehouse employees would know not to keep trying the same orders. If you take this step, then make sure you modify the code in the ProcessOrder_Click subroutine, so people can process orders with this status.

17.4.5. Updating Stock Numbers Thanks t o t he ever- so- sm art ShipOrders form you saw in t he previous sect ion, business is running sm oot hly at Bout ique Fudge. However, one day t he warehouse em ployees com e t o senior m anagem ent wit h a com plaint . Alt hough orders are sailing t hrough wit hout a hiccup, t he product invent ory inform at ion isn't keeping up. No one rem em bers t o adj ust t he Unit sI nSt ock inform at ion, so it 's becom ing increasingly useless. A t ruly aut om at ed solut ion would aut om at ically updat e t he Unit sI nSt ock inform at ion whenever an order ships. And aft er all, isn't t hat what Access is designed t o do best ? This challenge is ent irely unlike t he ot her problem s you've solved so far, because it forces you t o m ake a change in a com plet ely different set of recordsrecords t hat aren't being displayed in any form . You already know t hat you can use t he dom ain funct ions ( Sect ion 17.4.1) t o ret rieve inform at ion from ot her t ables. But unfort unat ely Access doesn't have a sim ilar set of funct ions t hat let s you m ake changes. I nst ead, you need t o t urn t o a com plet ely new set of obj ect s, called t he dat a access obj ect s ( or j ust DAO for short ) . DAO let s you perform any dat a t ask you want , independent of your form s. However, DAO is a bit com plex: ●



You n e e d t o u se D AO in a ve r y spe cific w a y. I f you use t he m et hods in t he wrong order or leave out a st ep, t hen you run int o an error. Oft en, it 's easiest t o st art wit h an exam ple t hat works ( like t he sam ple code included wit h t his chapt er) , copy it , and t hen alt er it as needed. D AO doe sn 't u se qu e r y obj e ct s. I nst ead, it forces you t o writ e SQL st at em ent s. You learned how t o writ e a basic SQL com m and in Chapt er 6 ( Sect ion 6.2.3) .

DAO involves t wo essent ial t echniques. First , t here's t he Current Db.Excecut e m et hod, which let s you run a direct SQL com m and by supplying it in a st ring: CurrentDb.Execute MyUpdateCommand

This m et hod's a quick and dirt y way t o m ake dat abase changes, like sweeping updat e, delet e, or insert operat ions. The second essent ial t echnique's t o ret rieve records using a specialized obj ect called t he Recordset . To use a Recordset , you m ust begin by using t he Current Db. OpenRecordset m et hod, and supplying a st ring wit h an SQL select com m and: Dim Recordset Set Recordset = CurrentDb.OpenRecordset(MySelectCommand)

The Recordset represent s a group of records, but it let s you access only one at a t im e. To m ove from one record t o t he next , you use t he Recordset .MoveNext m et hod. To check if you've reached t he end, you exam ine t he Recordset .EOF propert y, which st ands for end- of- file. When t his propert y's True, you've passed t he last record. You m ost oft en use a Recordset in a loop. You can use Recordset .EOF as t he loop condit ion, so t hat t he loop ends as soon as file:///C|/html/0596527608/access2007tm-CHP-17-SECT-4.html (13 of 15) [1/7/2007 7:14:33 AM]

Section 17.4. Using VB to Run a Better Business

Access reaches t he end of t he Record- set . I nside t he loop, you can ret rieve field values for t he current record. At t he end of each pass, you m ust call MoveNext t o m ove on: Do While Recordset.EOF = False ' Display the value of the ProductName field. MsgBox Recordset("ProductName") ' Move to the next record. Recordset.MoveNext Loop

Wit h t hese bare essent ials in m ind, you can m ake your way t hrough t he following code, which adj ust t he product st ock values based on a recent ly shipped order. ( A line- by- line analysis follows t he code.) 1 Sub UpdateStock( )

2

' If an error occurs, jump down to the DataAccessError section. On Error GoTo DataAccessError

' Create a SELECT command. 3 Dim Query 4 Query = "SELECT ProductID, Quantity FROM OrderDetails WHERE OrderID=" & ID

5 6

' Get a recordset using this command. Dim Recordset Set Recordset = CurrentDb.OpenRecordset(Query)

7

' Move through the recordset, looking at each record. ' Each record is a separate item in the order. Do Until Recordset.EOF

8 9 10

11 12 13

' For each item, get the product ID and quantity details. Dim ProductID, Quantity ProductID = Recordset("ProductID") Quantity = Recordset("Quantity") ' Using this information, create an UPDATE command that ' changes the stock levels. Dim UpdateCommand UpdateCommand = "UPDATE Products SET UnitsInStock = UnitsInStock-" & _ Quantity & " WHERE ID=" & ProductID

14

' Run the command. CurrentDb.Execute UpdateCommand

15

' Move to the next order item (if there is one). Recordset.MoveNext

16

Loop

17 18

' Time to clean up. Recordset.Close CurrentDb.Close

19

Exit Sub

20 DataAccessError:

21

' You only get here if an error occured. ' Show the error. MsgBox Err.Description

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-4.html (14 of 15) [1/7/2007 7:14:33 AM]

Section 17.4. Using VB to Run a Better Business

22 End Sub

Here's what t akes place: ● ● ●

● ● ● ●

● ● ● ● ●

Lin e 1 declares a new subrout ine. Because t his code's fairly com plex, it m akes sense t o put it in a separat e subrout ine, which you can call when t he Ship but t on's clicked and t he order's shipped. Lin e 2 t ells Access t o head down t o t he end of t he subrout ine if an error t akes place. Errors are always possible wit h dat a access code, so it 's good t o be on guard. Lin e s 3 4 creat e t he SQL com m and you need t o select t he OrderDet ails records for t he current order. ( See Sect ion 6.2.3.1 for m ore about SQL SELECT com m ands.) Lin e s 5 6 execut e t hat com m and, and get all t he m at ching records in a Recordset . Lin e 7 begins a loop t hat m oves t hrough t he ent ire Recordset . Lin e s 8 1 0 get t he Product I D and Quant it y fields for t he current OrderDet ails record ( t he first one in t he Recordset ) . Lin e s 1 1 1 3 use t his inform at ion t o build a SQL UPDATE com m and. The com m and subt ract s t he num ber of it em s ordered from t he t ot al num ber in st ock. A sam ple com plet ed com m and looks like t his: UPDATE Product s SET Unit sI nSt ock = Unit sI nSt ock- 4 WHERE I D= 14. This subt ract s 4 unit s from product 14. Lin e 1 4 perform s t he updat e. Lin e s 1 5 1 6 m ove t o t he next record and repeat t he updat e process ( unt il no m ore order it em s rem ain in t he Recordset ) . Lin e s 1 7 1 8 perform cleanup. Lin e 1 9 exit s t he procedure. I f you m ade if here, congrat ulat ionseveryt hing worked wit hout a hit ch! Lin e s 2 0 2 2 are only processed if an error occurs som ewhere. I n t his case, t he error descript ion's shown in a Message box.

This code's a fair bit m ore am bit ious t han anyt hing you've seen so far. However, it builds on all t he skills you've honed over t he last t hree chapt ers. Once again, t he best way t o get com fort able wit h t his code is t o download t he sam ple dat abase, see it in act ion, and t ry changing it . Happy experim ent ing!

NOSTALGIA CORNER DAO vs. ADO I n an effort t o m ake life m ore confusing, Microsoft int roduced a second dat a access t echnology nam ed ADO m any m oons ago. Bot h DAO and ADO let you perform dat a t asks using handy obj ect s. The key difference bet ween t hem is t hat Microsoft designed ADO t o be an all- purpose dat a access t echnology t hat works wit h ot her dat abase product s, like SQL Server, while DAO's a st rict ly Access- only affair. Som e Access program m ers t hink ( incorrect ly) ADO's t he successor t o DAO, and a bet t er choice when writ ing code for an Access dat abase. ( I n fact , Microsoft m ay even have said t hat at one point , but t hey've dest royed all t he evidence.) Today, t he official st ory's t hat DAO's t he bet t er way t o go, because it 's fine- t uned for Access. That m eans DAO's easier t o use, and offers bet t er perform ance in m ost cases. The only people who use ADO are seasoned VB program m ers who already know how it works, and don't want t o bot her learning DAO, or people who need an exot ic feat ure t hat ADO provides but DAO doesn't .

file:///C|/html/0596527608/access2007tm-CHP-17-SECT-4.html (15 of 15) [1/7/2007 7:14:33 AM]

Part VI: Sharing Access with the Rest of the World

Part VI: Sharing Access with the Rest of the World Ch a pt e r 1 8 : Sh a r in g a D a t a ba se w it h M u lt iple Use r s Ch a pt e r 1 9 : I m por t in g a n d Ex por t in g D a t a Ch a pt e r 2 0 : Con n e ct in g Acce ss t o SQL Se r ve r Ch a pt e r 2 1 : Con n e ct in g Acce ss t o Sh a r e Poin t

file:///C|/html/0596527608/access2007tm-PART-VI.html [1/7/2007 7:14:34 AM]

Chapter 18. Sharing a Database with Multiple Users

18. Sharing a Database with Multiple Users Now t hat you've creat ed t he perfect dat abase, you'd probably like t o share it wit h friends and colleagues. I n t he hands of a single person, Access is a t op- not ch t ool for m anaging inform at ion. But when you share t he love wit h a group of people, it becom es an even bet t er way t o work t oget her. Sharing dat abases is part icularly im port ant if your dat abase plays a behind- t he- scenes role in an organizat ion. I m agine you creat e a dat abase t hat t racks com pany proj ect s and t heir due dat es. ( Oft en, a dat abase like t his st art s out as a t im esaving convenience in t he hands of an Access fan wit h a lit t le t oo m uch free t im e.) Before long, ot her depart m ent s want in so t hey can keep t rack of t heir own proj ect s. And t he possibilit ies don't st op t here; if you share t he dat abase wit h a wide enough audience, you can link t oget her all sort s of relat ed t asks. Em ployees can log t he hours t hey work on each proj ect . Product t est ers can subm it out st anding issues t hat affect a proj ect . Team leaders can ident ify t im e- t axing proj ect s, head honchos can calculat e salary bonuses, and t he CEO can get a bird's eye view of all t he work t hat 's t aking place in t he com pany. Before long, it becom es difficult t o im agine life wit hout your Access dat abase. I n t his chapt er, you'll learn how t o share your dat abase wit h a sm all t eam . You'll consider t he pot ent ial pit falls, and you'll learn what you need t o do t o keep everyt hing running sm oot hly.

file:///C|/html/0596527608/access2007tm-CHP-18.html [1/7/2007 7:14:36 AM]

Section 18.1. Opening Up Your Database to the World

18.1. Opening Up Your Database to the World When you decide t o share your dat a, t he first decision you need t o m ake is whet her or not ot her people need t o change any of t he inform at ion. As you'll see, passing copies of your dat abase around is easy. But get t ing people t o work on t he sam e dat abase file at t he sam e t im e is a t rickier proposit ion. Overall, you can t ake four basic approaches t o get your dat a out t o t he m asses: ●







Ex por t you r da t a . You can t ake t he dat a in your dat abase and export it t o anot her form at ( like an HTML Web page or an Excel spreadsheet ) . This is t he way t o go if t he people who need t o see your dat a don't have Access. You'll learn how t o export dat a in Chapt er 19. Copy you r da t a ba se . You can give ot hers a copy of your dat abase. For exam ple, if Uncle Earl has a copy of Access, you can em ail him your list of fam ily addresses. The lim it at ion wit h t his approach is t hat t here's no easy way t o sync up t he changes in different copies. I f Uncle Earl adds a few new people t o your dat abase, your original rem ains t he sam e. I f you change t he original, Uncle Earl's copy is out of dat e. Sw it ch t o a se r ve r soft w a r e . You can m ove your dat a t o an indust rial- st rengt h sever product like SQL Server or SharePoint . Once you do, a virt ually unlim it ed num ber of people will be able t o get at t he dat a. Each person uses his or her own copy of Access t o connect t o t he server t hat has t he cent ral reposit ory of inform at ion. The obvious drawback t o t his approach is com plexit yset t ing up eit her of t hese product s is an am bit ious t ask even for t echnically savvy people. You'll t ry t wo of t he best opt ions in Chapt er 20 ( SQL Server) and Chapt er 21 ( SharePoint ) . Use t h e m u lt iu se r fe a t u r e s in Acce ss. You can place your dat abase in a shared locat ion ( like a net work drive) so several people can use it sim ult aneously. This way, everyone's working wit h t he sam e set of dat a ( and Uncle Earl's changes don't get lost ) . Wit h t his m et hod, Access has t o keep everyone's work coordinat ed. I f your group is sm allsay, wit h no m ore t han 40 people using your dat abase at oncem ult iuser sharing should work. But if your group is large, Access isn't t he best choice. I nst ead, you need a server product t hat 's built from t he ground up for high volum e, m ult iuser access. ( The next sect ion gives you a handy checklist t o help you decide if t his approach is for you.)

This chapt er focuses exclusively on t he last it em in t he list t he m ult iuser support t hat 's hardwired int o Access. But before you get st art ed, it 's im port ant t o underst and t he lim it s you'll face so you can assess whet her or not Access sharing can m eet your needs.

18.1.1. How Access Sharing Works The dat abase sharing feat ures in Access are easy t o underst and. First , you place your dat abase file in a locat ion where everyone can get t o it like a folder you're sharing on your com put er, or ( bet t er yet ) a spot on a server com put er on your com pany net work. Now, anyone who want s t o use t he dat abase sim ply needs t o open t he dat abase file. Sounds easy, right ? Not so fast . Before you rearrange your ent ire com pany around a single dat abase file, you need t o crunch a few num bers. Here are som e indicat ions t hat suggest Access sharing will work for you: ●

N o m or e t h a n 4 0 pe ople u se t h e da t a ba se a t on ce . The key part is how m any people are using t he dat abase at once. You're free t o share t he sam e dat abase wit h hundreds of users, so long as t hey don't all open it at t he sam e t im e.

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-1.html (1 of 2) [1/7/2007 7:14:39 AM]

Section 18.1. Opening Up Your Database to the World

Note: This number (40) is a sensible recommendation, not a set-in-stone rule. Some Access gurus have designed databases that can withstand 90 to 100 simultaneous users. However, without some serious (and complex) optimizations, you're likely to hit a brick wall much sooner. ●

N o m or e t h a n 1 5 pe ople ch a n ge t h e da t a ba se a t t h e sa m e t im e . Reading t he dat abase is easy, but updat ing it present s som e serious challenges. One obvious problem occurs if m ore t han one person t ries t o change t he sam e record at t he sam e t im e, but in different ways. And because of t he way Access is designed, even changes t hat shouldn't clash wit h one anot her can slow down your overall perform ance. You'll t ackle t his issue lat er in t his chapt er when you consider locks ( Sect ion 18.3.3) .

Note: This number (15) is just a conservative guideline. If different people are making changes in completely different tables, you may be able to squeeze in more updates at once. Conversely, if everyone wants to change the same few records, you may run into trouble even earlier. If in doubt, try it out. ●





Th e st r u ct u r e of t h e da t a ba se ch a n ge s in fr e qu e n t ly. I n ot her words, you don't expect t o regularly redesign your t ables, add new fields, or t weak relat ionships. I deally, you'll perfect all your t ables before you share t he dat abase. And for best result s, only one person should have t he role of Chief Table Designer and be responsible for changing t he dat abase st ruct ure when needed. D iffe r e n t pe ople t e n d t o w or k w it h diffe r e n t t a ble s. I f everyone who uses t he dat abase is perform ing t he sam e t ask ( and accessing t he sam e t able) , you've got a problem . But if one person m aint ains t he product cat alog, five m ore ent er orders, and anot her six log shipm ent s, you're in a m uch bet t er sit uat ion. Even t hough everyone's using t he sam e dat abase at once, t heir work doesn't overlap. You r da t a ba se isn 't m ission - cr it ica l. Dat a is always im port ant . But if you're running an ecom m erce com pany wit h a Web sit e t hat 's live 24 hours a day, you can't afford even a m om ent ary glit ch. Unfort unat ely, Access can't guarant ee t hat kind of st abilit y. Alt hough it 's rare, a sudden net work problem or a com put er failure t hat happens while som eone's in t he m iddle of m aking a change could conceivably dam age your dat abase.

Note: All Access fans should perform regular database backups throughout the day. You can use a scheduling tool (like Windows Task Scheduler) to automate this process.

I t 's no exaggerat ion t o say t hat shared Access dat abases are t he backbone of m any sm all com panies. But if you've reviewed t he lim it at ions of Access sharing and decided t hat Access can't fill your needs, it 's t im e t o st ep up t o a m ore powerful product like SQL Server. ( Don't panica free version is available, and you can m anage your dat a in t he fam iliar Access int erface.) You'll learn about SQL Server in Chapt er 20 and SharePoint Server in Chapt er 21. On t he ot her hand, if Access does fit your needs, congrat ulat ionsyou're m om ent s away from t ransform ing your lonely, single- person dat abase int o a resource your ent ire com pany can use. Just read on.

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-1.html (2 of 2) [1/7/2007 7:14:39 AM]

Section 18.2. Preparing Your Database

18.2. Preparing Your Database I f you've m ade it t his far, you've decided t hat t he m ult iuser feat ures in Access are everyt hing you need. However, before your dat abase goes public, you m ay want t o m ake a few changes. The m ost im port ant of t hese is split t ing t he dat abasea crit ical but oft en overlooked st ep t hat gives your shared dat abase ext ra reliabilit y.

Note: When you're sharing your data, it's essential to use a split database. Sharing an ordinary database can lead to all sorts of odd quirks that will make your database go wonky.

18.2.1. Understanding Split Databases A split dat abase is a dat abase t hat has it s obj ect s divided int o t wo separat e files: ● ●

Th e ba ck - e n d da t a ba se cont ains t he raw dat ain ot her words, t he t ables and not hing but . Th e fr on t - e n d da t a ba se cont ains everyt hing you use t o work wit h t he t ables. This includes all t he ot her t ypes of dat abase obj ect s, like queries, report s, form s, and m acros.

Once you've split your dat abase, you place t he back- end dat abase in a shared locat ion ( like a net work drive) . However, t he front - end dat abase works a lit t le different ly. You copy it t o every com put er t hat 's going t o use t he back- end dat abase. Figure 181 shows how it works. Split dat abases offer several advant ages: ●



Pe r for m a n ce . When you use a split dat abase, each client has a copy of t he obj ect s t hey need t o uselike form sready and wait ing on t heir com put er. That m eans you don't need t o ret rieve t he sam e inform at ion from t he shared dat abase, which would t ake m ore t im e ( and generat e m ore t raffic on your net work) . I nst ead, t he only t hing you need t o get from t he shared dat abase is t he dat a you want t o work wit h. Ea sie r u pda t in g. I t 's relat ively safe for people t o change t he dat a in a shared dat abase, but Access isn't as good at sort ing out t he confusion if m ult iple people t ry t o change t he design of your dat abase obj ect s. A split dat abase avoids t his problem , because t he obj ect s t hat need t o be t weaked m ost oft en, like queries, report s, and form s, are locat ed in t he front end. I f you want t o m odify t hese obj ect s ( or add new ones) , you can safely change t he front end on one com put er, and t hen dist ribut e it t o everyone who needs it . This approach isn't j ust easierit 's also m ore reliable, because t here's no chance of an unset t ling phenom enon called dat abase corrupt ion occurring ( Sect ion 18.4) .

Figu r e 18-1. In a system with a split database, you have one back end, which file:///C|/html/0596527608/access2007tm-CHP-18-SECT-2.html (1 of 15) [1/7/2007 7:14:52 AM]

Section 18.2. Preparing Your Database

centralizes the data, and several front endsone for each person connecting to your database.



D iffe r e n t pe ople , diffe r e n t fr on t e n ds. When you use a shared dat abase, you can creat e different front ends for different t ypes of peoplefor exam ple, t he m arket ing depart m ent needs report s t hat show sales inform at ion, and t he warehouse people need a form t hat shows out st anding orders. You can even use t his approach t o m ake sure people don't see form s, report s, and t ables t hat don't apply t o t hem , which reduces t he risk of m inor errors ( like when t he CEO accident ally wipes out t he ent ire product cat alog) . But don't go t oo wildt he m ore front ends you creat e, t he m ore you'll need t o m aint ain.

Note: Technically speaking, you won't make your database more secure by giving people less capable front ends. After all, savvy Access users could just create their own front ends and use them to get unlimited access to the back-end database. However, even though the front end can't stop a malicious attacker, it can minimize the danger of a careless or overly curious user.

You have t wo ways t o split a dat abase. You can use a wizard, or you can do it by hand using t he im port ing and export ing feat ures in Access. The next sect ions describe bot h m et hods.

WORD TO THE WISE Finding a Home for Your Database on the Network Before you split your dat abase, you should know where you want t o place t he back- end dat abase file. One ( som ewhat risky) opt ion is t o share it direct ly from your own com put er. All you need t o do is drag your dat abase t o t he Shared Docum ent s folder or creat e a new shared folder. The exact process differs depending on your version of Windows and t he way your com put er is configured, but t hese inst ruct ions do t he t rick on m ost Windows XP boxes: 1. Fire up Windows Explorer. 2. Find t he locat ion where your dat abase is st ored, right - click t hat folder, and t hen choose Propert ies. 3.

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-2.html (2 of 15) [1/7/2007 7:14:52 AM]

Section 18.2. Preparing Your Database

Swit ch t o t he Sharing t ab, and t hen choose Share t his Folder. 4. Opt ionally, configure an alt ernat e nam e t hat will be used for t he folder, and t hen set a lim it on how m any people can access t he folder at one t im e. 5. Click OK. Now ot her people can get t o your com put erand your dat abaseby browsing t hrough My Net work Places. I f t his process seem s a lit t le t oo easy t o be t rue, well, it is. The problem is t hat your com put er isn't an ideal net work server. I f you t urn off your com put er t o go on vacat ion, everyone is abrupt ly locked out of your dat abase. Sim ilarly, if you're busy running Revenge of t he Dem on Spawn Legion Part I V while ot her people are t rying t o use your dat abase, t heir dat abase perform ance ( and your gam ing experience) suffers. An even m ore serious problem occurs if you reboot your com put er, at which point everyone who is current ly using t he dat abase is rudely disconnect ed. This is guarant eed t o lose som ebody's work, and it m ay even cause dat abase corrupt ion ( Sect ion 18.4) . For all t hese reasons, it 's st rongly recom m ended t hat you place your dat abase on a server com put er. A server com put er isn't necessarily any different from your com put erin fact , it m ay j ust be an ordinary Windows com put er t hat 's plugged int o t he net work. The difference is t hat no one uses t his com put er direct ly. I nst ead, it 's left alone so it can concent rat e on t he im port ant j ob of doling out dat a t o everyone who needs it .

18.2.2. Splitting a Database with the Wizard The easiest way t o split a dat abase is t o use t he handy wizard t hat Access includes for j ust t his purpose. The wizard creat es a new back- end dat abase and m oves all t he t ables out of t he current dat abase and int o t he back end. The current file is left wit h all t he ot her dat abase obj ect s, and so it becom es t he front end. Here's how t o use t he wizard: 1. Ope n a n y da t a ba se t h a t h a s bot h t a ble s a n d som e ot h e r obj e ct s ( lik e qu e r ie s, r e por t s, or for m s) . You can t ry t hese st eps wit h t he Bout ique Fudge and Cacophoné St udios dat abases you used in previous chapt ers. 2. Be for e you be gin , it 's a good ide a t o m a k e a da t a ba se ba ck u p. Hey, you never know when som et hing could go wrong. To m ake your backup, j ust copy t he Access dat abase file t o anot her Manage Back Up Dat abase t o get Access t o do it for you) . folder ( or choose Office but t on 3. Ch oose D a t a ba se Tools

M ove D a t a

Acce ss D a t a ba se .

The first window of t he Dat abase Split t er wizard appears ( see Figure 18- 2) .

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-2.html (3 of 15) [1/7/2007 7:14:52 AM]

Section 18.2. Preparing Your Database

Figu r e 1 8 2 . The first step of the wizard is fairly unremarkable. It describes how the wizard works and reminds you to make a backup before you go any further.

4. Click Split D a t a ba se . A window appears t hat prom pt s you t o pick a locat ion and file nam e for t he back- end dat abase. Rem em ber, you need t o choose a locat ion t hat everyone in your com pany or organizat ion can access. ( See t he box " Point ing t o a Net work Locat ion" in Sect ion 18.2.2, for som e t ips.)

Note: Alternatively, you can save the back end on your computer for the time being, and then move it to the shared location later on (at which point you'll need to update the table links, as described in Section 18.2.3). 5. Ch oose a file n a m e for t h e ba ck - e n d da t a ba se , a n d t h e n click Split ( Figu r e 1 8 - 3 ) . Access begins export ing t he t ablesin ot her words, copying t hem from t he current dat abase t o t he new back- end dat abase file. This could t ake som e t im e. When Access is finished, it shows t he m essage " Dat abase successfully split ." I t has successfully creat ed t he back- end dat abase. The dat abase t hat you st art ed wit h ( t he one t hat 's current ly open) is now t he front - end dat abase. I t no longer cont ains t he t ables wit h all t he dat a; inst ead, it has a set of t able links t hat let you pull t he dat a out of t he back- end dat abase. ( You'll learn how t hese t able links work in t he following sect ion.)

Figu r e 1 8 - 3 . Access file:///C|/html/0596527608/access2007tm-CHP-18-SECT-2.html (4 of 15) [1/7/2007 7:14:52 AM]

Section 18.2. Preparing Your Database

recommends adding_be to the end of your database's file name to identify the back end. For example, JoesTaxidermy. accdb becomes JoesTaxidermy_be. accdb.

UP TO SPEED Poin t in g t o a N e t w or k Loca t ion You have t wo ways t o point t o a place on a net work. The first opt ion is t o use a m apped net work drive, which t akes a net work locat ion and gives it a drive let t er on your com put er. Mapped net work drives look j ust t he sam e as ordinary drivesfor exam ple, you can have a drive C: t hat represent s your hard drive, a drive D: t hat represent s your CD- ROM, and a drive F: t hat represent s a place on t he net work. The problem wit h m apped net work drives is t hat t hey m ay be configured different ly depending on t he com put er. For exam ple, t he drive you t hink of as F: m ay appear as drive H: on som eone else's com put er. As a result , t he front - end dat abase t hat works on one com put er won't be able t o find t he back- end dat abase it needs on anot her. Fort unat ely, t his problem is easy t o fix. You j ust need t o point t he front end t o t he appropriat e back- end locat ion, as described in Sect ion 18.2.3. I f you want t o avoid t his confusion alt oget her, you can use a UNC pat h inst ead of a m apped net work drive. UNC ( universal nam ing convent ion) is a st andard way t o creat e pat hs t hat point t o locat ions on t he net work. The advant age of UNC pat hs is t hat t hey don't vary from one com put er t o t he next . I n ot her words, t he UNC pat h t hat works on one com put er will also work on any ot her com put er on t he net work. You can recognize a UNC pat h by it s st art ing charact erst wo backslashes. Here's t he basic form : \\NetworkedComputerName\SharedFolderName

An exam ple of a UNC pat h is \ \ SalesCom put er\ Dat abase. When you browse t o a com put er t hrough My Net work Places, Access creat es a UNC pat h t hat point s t o t he locat ion you choose. Som e Access expert s report bet t er result s when t hey use UNC pat hs t o t ell Access where t o find a dat abase. I n rare, difficult t o- reproduce sit uat ions, using t he m apped net work drive synt ax can cause Access t o give a " t oo m any users" error when you at t em pt t o open a shared dat abase, even when you're well wit hin t he m axim um user lim it ( a t heoret ical 255 users) .

6. N ow it 's t im e t o dist r ibu t e t h e fr on t e n d t o e ve r yon e w h o n e e ds t o u se t h e da t a ba se .

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-2.html (5 of 15) [1/7/2007 7:14:52 AM]

Section 18.2. Preparing Your Database

I t 's up t o you how you want t o share your front end. You could em ail it , burn it on a CD and hand it out , or j ust pop it in a shared locat ion. However, it 's im port ant t hat everyone underst ands t hey need t o copy t he front end t o t heir com put er before t hey use it .

Note: If you distribute the front end by placing it on the network, you run the risk that people will launch the front end straight from the network, without copying it to their computers first. Left unchecked, this introduces all the problems of ordinary (non-split) databases, like hampered performance and greater risk for errors.

FREQUENTLY ASKED QUESTION What About Old Versions of Access? What happens if som e of m y coworkers have older versions of Access? I n an ideal world, everyone has a copy of t he lat est and great est version of AccessAccess 2007. I n t he real world, you're likely t o find low- t ech renegades who st ill love Windows 95. I f you support Access 2003 lovers, you need t o st ore t he back end in t he Access 2003 form at . ( See Sect ion 1.2.2 for inform at ion about how t o save a copy of your dat abase in a different form at .) As for t he front end, you'll probably want t o keep t wo versionsone for t he Access 2007 club and anot her for Access 2003 folks. You'll lose out on som e feat ures in t he Access 2003 form at , but you don't need t o lock t he t echnologically challenged out of your dat abase.

18.2.3. How Linked Tables Work The concept of a split dat abase seem s st raight forward enough. One file ( t he back end) st ores t he raw dat a, while anot her ( t he front end) gives you t he t ools for working wit h it . But t here's one det ail t hat you haven't considered yet nam ely, how does t he front end get access t o t he t ables in t he back end? The secret is t able linking. Linking let s one dat abase see a t able in anot her dat abase file. You can use linking in any dat abasein fact , you can choose t o use it even if you won't be sharing your dat abase. For exam ple, you can divide your t ables int o t wo or m ore dat abase files t o get around t he size lim it ( which is 2 GB, or gigabyt es, per dat abase file) . Or, you can use it t o help you organize a sprawling dat abase wit h dozens of t ables. Finally, you m ay also find it helps you separat e public inform at ion from supersecret det ails. I f you put t he t ables wit h t he secret inform at ion in a separat e dat abase, you're free t o share copies of your m ain dat abase wit hout worrying about sensit ive dat a get t ing int o t he wrong hands. Thanks t o linking, all t he back- end t ables st ill appear in t he front - end dat abase ( see Figure 18- 4) . However, t he act ual dat a is in a separat e file. When you open or ot herwise int eract wit h a linked t able, Access heads t o t he linked file t o get t he inform at ion you need.

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-2.html (6 of 15) [1/7/2007 7:14:52 AM]

Section 18.2. Preparing Your Database

Figu r e 1 8 - 4 . These tables have an arrow icon next to them, which indicates they're linked tables. They aren't actually stored in the current database file, but Access knows where to find the information when it needs it.

The only disadvant age t o linked t ables is t hat t here's always a chance Access will go looking for a linked t able in anot her dat abase file, but not be able t o find it . This happens if t he back- end dat abase file is m oved t o anot her folder or if it 's renam ed.

Note: If your database has a bad link, when you attempt to open the table (or another object that uses the table, like a query or a report), you get a message informing you that Access can't find the file you need.

Fort unat ely, it 's easy t o updat e your links. Here's how: 1. D a t a ba se Tools Ch oose D a t a ba se Tools t h e n ch oose Lin k e d Ta ble M a n a ge r ) .

Lin k e d Ta ble M a n a ge r ( or r igh t - click a n y lin k e d t a ble , a n d

The Linked Table Manager window appears, wit h a list of all t he linked t ables in your dat abase ( Figure 18- 5) . 2. Pla ce a ch e ck m a r k n e x t t o e a ch lin k you n e e d t o ch a n ge . I f you need t o updat e all your links, click Select All.

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-2.html (7 of 15) [1/7/2007 7:14:52 AM]

Section 18.2. Preparing Your Database

Figu r e 18-5. This database has eight linked tables. All the links point to the same back-end database, which is common but isn't required.

I n m ost cases, all your links will point t o t he sam e dat abase file. But if you need t o point your t ables t o different files, t hen select " Always prom pt for new locat ion." 3. Click OK. Access pops open t he fam iliar file select ion window. Browse t o t he dat abase file t hat has your linked t able, select it , and t hen click OK. I f you choose " Always prom pt for new locat ion," Access shows a separat e file select ion window for each link. Look at t he window t it le t o find out what t able you're updat ing. I f you didn't choose " Always prom pt for new locat ion," you can updat e all your links in one st ep.

TROUBLESHOOTING MOMENT The Mysterious "File Already in Use" Error Now t hat you've creat ed a shared dat abase, you expect it t o support a whole crowd of people. That 's why it com es as quit e a shock when you get t he crypt ic " file already in use" error. Aft er all, aren't shared dat abases supposed t o rem ain available even when som eone else is using t hem ? This error occurs because som eone has already opened t he dat abase in Exclusive m ode. Exclusive m ode ( discussed in Sect ion 18.3.4) let s a single person t ie up t he dat abase and lock out everyone else. The t rick is t hat under cert ain circum st ances, Access can use Exclusive m ode even when you don't t ell it t o. The m ost com m on problem occurs when som eone doesn't have t he correct perm issions for t he shared folder where t he shared dat abase is st ored. ( Perm issions are a Windows securit y concept t hat det erm ines how users are allowed t o use files and folders.) Specifically, a problem occurs if you are t he first person t o open t he dat abase, and you don't have perm ission t o creat e new files. I n t his sit uat ion, Access can't creat e t he .laccdb file t hat t racks locks ( see Sect ion 18.3.3) . Wit h t he .laccdb file, Access has no way t o coordinat e m ult iple users. I nst ead, it quiet ly swit ches t o Exclusive m ode, which freezes out everyone else. The obvious solut ion is t o ident ify everyone who needs t o use t he dat abase, and t hen m ake sure t hey're allowed t o creat e new files in t he shared folder. Of course, t his problem wouldn't be nearly as confusing if Access could warn you when it 's not able t o open a dat abase norm ally and needs t o use Exclusive m ode.

18.2.4. Manually Splitting a Database You don't need t o use t he wizard t o split your dat abase. You can m ove t ables int o a separat e dat abase file on your own, and t hen creat e links by hand. The m ain reason t hat you'd use t his approach is because you want t o split your dat abase int o m ore piecesfor exam ple, you want one front end and four- back end files.

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-2.html (8 of 15) [1/7/2007 7:14:52 AM]

Section 18.2. Preparing Your Database

There are som e good reasons for subdividing your back end. They include: ● ● ●

Be t t e r r e lia bilit y. Essent ially, if one file is dam aged, t he ot hers will st ill live on unaffect ed. Be t t e r se cu r it y. Using t he t ools of t he Windows operat ing syst em , you can cont rol who can open a specific file. You can use t his t o your advant age wit h split dat abases t o lock people out of part s of t he back end where t hey don't belong. Le a vin g r oom t o gr ow . As m ent ioned earlier, Access lim it s dat abases t o 2 GB. I f you plan t o st ore large am ount s of records wit h at t achm ent s ( like pict ures) , it 's a good idea t o m ake sure plent y of space is available now and for t he foreseeable fut ure.

To split a dat abase by hand, you need t o use t he im port ing and export ing feat ures in Access. The following st eps show you how t o split t he Bout ique Fudge dat abase int o t hree separat e pieces so you can keep t he credit card inform at ion separat e from t he rest of t he dat a. ( I f you want t o follow along, you can find t he dat abase wit h t he sam ple cont ent on t he " Missing CD" page at www.m issingm anuals.com .) 1. Cr e a t e t h e ba ck - e n d da t a ba se s t h a t you n e e d. I n t his exam ple, you need t wo back ends: one for t he credit card det ails ( call t his Bout iqueFudgeSecret s_be.accdb) and one for all t he ot her det ails ( nam ed Bout iqueFudge_be.accdb) . Before you go any fart her, creat e bot h of t hese dat abases in Access and place t hem in t he shared locat ion, but leave t hem em pt y for now. 2. Ope n t h e ba ck - e n d da t a ba se file . The next t ask is t o add t he correct t ables t o each back- end dat abase. You do t his using Access's im port ing wizard. St art wit h Bout iqueFudgeSecret s_be.accdb. I t 's easy because it requires j ust a single t able. 3. Ch oose Ex t e r n a l D a t a

I m por t

Acce ss.

The I m port wizard begins ( see Figure 18- 6) .

Note: In this example, you're importing the tables you need into the back end. You could also try the same trick in reverse, by exporting the tables out of the front end. However, export operations are more limited than import operations, because they let you transfer only a single table at a time.

Figu r e 18-6. In the first step of the Import wizard, you choose the file that has

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-2.html (9 of 15) [1/7/2007 7:14:53 AM]

Section 18.2. Preparing Your Database

the tables you want to import, and then you decide whether to copy the tables or just create links.

4. Spe cify t h e loca t ion of you r fr on t - e n d da t a ba se in t h e " File n a m e " box . I n t his exam ple, t hat 's Bout iqueFudge.accdb, which current ly cont ains t he whole shebang ( t ables, queries, form s, and report s) . 5. Ch oose t h e fir st opt ion , " I m por t t a ble s … in t o t h e cu r r e n t da t a ba se ." The second opt ion let s you creat e linked t ables. You'll use it lat er in t his process. 6. Click OK. The I m port Obj ect s window appears, wit h a list of everyt hing in your dat abase ( see Figure 18- 7) . 7. Se le ct t h e t a ble s you w a n t t o im por t , a n d t h e n click OK. The Bout iqueFudgeSecret s_be dat abase needs j ust a single t able: Credit Cards. Once you click OK, Access copies t he t ables int o your dat abase. You can now close t he dat abase file. 8. Re pe a t st e ps 2 t o 7 for a n y ot h e r ba ck - e n d da t a ba se file s. I n t his exam ple, you need t o open Bout iqueFudge_be.accdb, and im port all t he t ables except Credit Cards. Once you've finished t ransferring t he dat a t o your back ends, it s t im e t o updat e t he front end.

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-2.html (10 of 15) [1/7/2007 7:14:53 AM]

Section 18.2. Preparing Your Database

Figu r e 1 8 7 . The Tables tab lists all the tables in your database. Select the ones you want to import by clicking them once.

9. Ope n t h e fr on t - e n d da t a ba se . I n t his exam ple, t hat 's Bout iqueFudge.accdb. 10. D e le t e a ll t h e t a ble s. Don't be shyaft er all, you've already copied t hem t o t heir new hom es in t he back- end files. Once you're finished, it 's t im e t o t ake t he last st ep and creat e t he links you need in your front end. I f your t ables are linked t oget her, st art wit h t he child t ables first . 11. Ch oose Ex t e r n a l D a t a

I m por t

Acce ss.

The I m port wizard st art s again. 12. Poin t t h e im por t w iza r d t o you r fir st ba ck - e n d file , ch oose " Lin k t o t h e da t a sou r ce ," a n d t h e n click OK. St art wit h t he Bout iqueFudgeSecret s_be.accdb file. 13. Ch oose a ll t h e t a ble s, a n d t h e n click OK. Access creat es t he corresponding linked t ables in your dat abase. Each t able appears wit h t he t ellt ale arrow icon next t o it in t he navigat ion pane t o let you know it uses a link.

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-2.html (11 of 15) [1/7/2007 7:14:53 AM]

Section 18.2. Preparing Your Database

Re pe a t st e ps 1 1 t o 1 3 for e ve r y ba ck - e n d da t a ba se . I f you st art ed wit h Bout iqueFudgeSecret s_be, it 's t im e t o m ove on t o Bout iqueFudge_be, which cont ains all t he ot her t ables you need. I f you've followed all t hese st eps, you wind up wit h t hree dat abase files t hat work t oget her: Bout iqueFudgeSecret s_be.accdb wit h t he credit card inform at ion, Bout iqueFudge_be.accdb wit h t he rest of t he t ables, and Bout iqueFudge.accdb wit h t he queries, form s, and report s. I f you want t o see t he finished product , check out t he downloadable sam ples for t his chapt er. And j um p ahead t o Sect ion 18.5 t o learn how you can apply different securit y set t ings t o t he different back ends.

18.2.5. Locking Down Your Front End Before you let your dat abase out int o t he wild, you need t o t hink about what can go wrong. I n t he hands of less savvy Access users, your lovingly craft ed form s and report s can get scram bled. I t 's a com m on com plaint wit h m ult iuser Access dat abases: Sooner or lat er, a curious or careless person changes som et hing t hat 's bet t er left alone, and t hat person's front end st ops working. Alt hough you can't wat ch over everyone's shoulder, you can prevent m ischief by locking down your front end. That way, ot her folks won't be allowed t o m odify t he design of form s and report s. ( Of course, t hey can st ill use t he front end t o review and edit dat a.) The secret t o locking down your front end is t o change t he front - end dat abase from an .accdb file t o an .accde file. Alt hough t here's only one let t er of difference, t he .accde form at rest rict s people in several ways: ● ● ● ●

They They They They code

can't m odify form s or report s. I n fact , t hey can't even open t hese obj ect s in Design view. can't creat e new form s and report s. can't renam e exist ing form s and report s ( alt hough t hey can delet e t hem ) . can't edit or even look at your VBA code and m acros. I n fact , all code is com piled, which m eans it 's convert ed from t he st at em ent s you learned about in Chapt ers 16 and 17 t o a short hand t hat only t he com put er can underst and.

Note: Access gives you the same feature for the older .mdb database format. To lock down changes in an .mdb, you create an .mde file.

Making an .accde file is as easy as can be. Just follow t hese st eps: 1. Ope n you r fr on t - e n d da t a ba se . 2. M a k e su r e t h a t you r da t a ba se is r u n n in g in fu ll t r u st m ode . I f you haven't opened it from a t rust ed locat ion ( Sect ion 15.2.4) , you need t o click t he Opt ions but t on in t he securit y warning m essage bar, choose Enable Cont ent , and t hen click OK. Sect ion 15.2.2 has m ore on t his procedure. 3. Ch oose D a t a ba se Tools

D a t a ba se Tools

M a k e ACCD E.

The Save As dialog box appears. 4. Su pply t h e file n a m e for you r .a ccde file . Access won't change your original dat abaseinst ead, it m akes a copy in t he new form at . When you creat e an .accde file, m ake sure you keep t he original .accdb in your hands. That 's because sooner or lat er you'll need t o m ake changes. Access doesn't give you any way t o change an .accde file back t o it s original form at , so your only choice is t o go back t o t he original form at , m ake your changes, and t hen export a new .accde file.

Note: If you lose your original .accdb file, there's no way to change your forms and reports. You're stuck with a database that's frozen in

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-2.html (12 of 15) [1/7/2007 7:14:53 AM]

Section 18.2. Preparing Your Database

time. However, as a last resort, you can try the Web, where other companies provide utilities that can (usually) transform an .accde file back to an .accdb file.

FREQUENTLY ASKED QUESTION When Not to Use an ACCDE I s t he .accde form at for front ends only? You can t urn any dat abase int o an .accde file. However, you should t hink t wice before you use anyt hing ot her t han a front end. That 's because it 's difficult t o updat e an .accde file t hat has dat a. To underst and t he problem , im agine you creat e an .accde file for an all- in- one dat abase t hat sells discount hair care product s. This dat abase includes all t he raw dat acust om er list s, available services, and invoicesand it cont ains t he form s and report s t hat m ake your life easier. There's no division bet ween t he back end and front end. A few weeks lat er, you decide t o add a new report t hat shows cust om ers subgrouped by t he color of t heir highlight s. Of course, you can't edit t he .accde file direct ly, so you polish off t he report in t he original .accdb file, and creat e a new .accde. But wait t here's a problem . Your original .accdb file st ill has t he old dat a. You're now st uck wit h t wo incom plet e files: an .accde wit h t he new dat a but t he old form s and report s, and a new .accde wit h t he right form s and report s but t he wrong dat a. To rem edy t his sit uat ion, you need t o perform a t im e- consum ing im port operat ion, as described earlier ( Sect ion 18.2.4) . To avoid t hese dat a synchronizat ion headaches, use t he .accde form at t he way it 's int ended t o be usedt o lock down front ends t hat don't have any t ables.

18.2.6. Sharing a Database with People Who Don't Own Access Wouldn't it be nice if people could work wit h your dat a and use your form s and report s wit hout needing t he full Access soft ware on t heir com put ers? I t m ay seem like j ust a dream , but t here's a way. Microsoft provides a scaled- down version of Access t hat 's called t he Access runt im e engine. Rat her t han buying a separat e copy of Access for each person who needs t o use your dat abase, you can give t hem all a copy of t he Access runt im e engine. Then, t hey can use t he runt im e engine t o load up your dat abase and use it s form s and report s t o review and edit dat a. The Access runt im e engine doesn't have t he full feat ures of Access. Not ably, it doesn't include t he ribbon or t he navigat ion pane. I n fact , it doesn't provide any way for people t o change t he configurat ion or design of t he dat abase. ( That 's a j ob for you, t he dat abase designer.) The only t hing you can do wit h t he Access runt im e is use t he form s and report s t hat you've included in your front end.

Note: When using a well-designed front end with the Access runtime, people may not even realize that they're running Access.

So how can you get your hands on t he Access runt im e engine? At t he t im e of t his writ ing, it wasn't yet released. However, Microsoft has prom ised t o m ake it available in early 2007 ( and unlike Access 2003, Microsoft prom ises t hat t he Access 2007 runt im e engine will be available on t heir Web sit e, and not bundled wit h t heir Visual St udio program m ing t ool) . To get t he lat est updat e on t he st at us of t he Access runt im e engine, click over t o t he " Missing CD" page at www.m issingm anuals.com . I n t he m eant im e, you can t ake a look at what a dat abase looks like when it 's in t he hands of t he runt im e engine. Here's how: 1. Ope n you r da t a ba se a n d m a k e su r e it h a s a st a r t u p for m ( Se ct ion 1 4 .2 .2 ) . The Access runt im e engine doesn't have a navigat ion pane, so you need t o have a st art up form in order for t he user t o be able t o do anyt hing. That st art up form will probably be a swit chboard ( Sect ion 14.2.1) wit h but t ons t hat lead t o ot her form s.

Access Opt ions. Pick t he Current Dat abase sect ion on t he left . Finally, set To set t he st art up form , choose Office but t on t he Display Form set t ing t o t he form you want t o show aut om at ically when t he dat abase is opened. 2.

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-2.html (13 of 15) [1/7/2007 7:14:53 AM]

Section 18.2. Preparing Your Database

Re n a m e you r da t a ba se 's file e x t e n sion fr om .a ccdb t o .a ccdr . ( Pr e su m a bly, t h e r st a n ds for r u n t im e .) 3. D ou ble - click you r da t a ba se t o r u n it in r u n t im e m ode . You 'll se e you r st a r t u p for m , bu t n o r ibbon or n a viga t ion ( Figu r e 1 8 - 8 ) . Don't worry. You can renam e your Access file t o .accdb t o get it back t o norm al.

Tip: The Access runtime engine is a truly useful way to share your databases without buying a zillion Access licenses and confusing people with all the features of the full Access user interface. If you're using Access to coordinate life in a small business, check it out.

Figu r e 18-8. This .accdr file uses the fancy switchboard you saw in Section 14.2.3.2.

NOSTALGIA CORNER The Death of Data Access Pages Access 2003 had a feat ure called dat a access pages for creat ing a Web page front end t o your dat abase. The idea was a powerful oneusing t hese Web pages, anyone could review inform at ion in your dat abase or m ake a change, even wit hout t he Access soft ware. Unfort unat ely, Access and t he Web have a t roubled relat ionship. As you've already learned, Access can handle only so m any sim ult aneous users at one t im e. The Web has no such lim it at ion. I n fact , j ust put t ing a dat abase on t he I nt ernet is an invit at ion for hordes of people t o t ry t o use it at t he sam e t im e. For t his reason, as well as for several ot hers ( such as t he difficult y in cust om izing dat a access pages and t he lack of com pat ibilit y wit h ot her browsers) , Microsoft discont inued t he feat ure in Access 2007. I f you st ill want a Web face for your dat abase, Access doesn't have m any t ools t o help you. Your best bet is t o m ove your dat abase t o a server product like SQL Server, and use anot her developm ent t ool t o build your Web page. Serious coders love ASP.NET ( see www.asp.net ) , an all- in- one Microsoft t oolkit for building t he sim plest t o t he m ost sophist icat ed Web sit es.

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-2.html (14 of 15) [1/7/2007 7:14:53 AM]

Section 18.2. Preparing Your Database

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-2.html (15 of 15) [1/7/2007 7:14:53 AM]

Section 18.3. Playing Well with Others

18.3. Playing Well with Others Mult iuser access is a perpet ual j uggling act . I f all people want t o do is read inform at ion, life is easy. But som e significant challenges appear t he m om ent people want t o m ake changes. For exam ple, what happens when t wo people t ry t o change t he sam e record at t he sam e t im e? Or when you t ry t o change a record while som eone else t ries t o delet e it ? Or, if you want t o read t he lat est inform at ion while an updat e's in progress? Clearly, Access needs a way t o m anage t he chaos. I n t his sect ion, you'll learn what Access does t o keep everyt hing under cont rol, and how you can adj ust it s set t ings. You'll also learn how t o st ave off t he dangers of dat a corrupt ion.

18.3.1. Seeing Changes As They Happen Pict ure t he following scenario. You're on t he phone wit h a big- spending cust om er of Bout ique Fudge. Using your t rust y Access dat abase, you run t hrough t he product s t hat are available, giving your cust om er t he price of each one. But unbeknownst t o you, t he head chef is looking at t he sam e t able at t he sam e t im eand raising t he prices on t he m ost popular dishes. The quest ion is t his: When do you not ice t he price increase? Access deals wit h sit uat ions like t his using aut om at ic refreshes. Once every 60 seconds, Access checks t he back- end dat abase t o find out what 's changed. Access t hen updat es t he corresponding inform at ion on your screen, whet her you're looking at a form , a query, or direct ly at a t able. I n t he Bout ique Fudge exam ple, t he new prices appear t he next t im e Access perform s a refreshand no lat er t han 60 seconds aft er t he changes are m ade. There are a few except ions t o t he refresh rule: ● ●



W h e n you st a r t e dit in g a r e cor d ( by click in g in side on e of t h e fie lds) , Acce ss im m e dia t e ly r e fr e sh e s j u st t h a t r e cor d. This ensures t hat you always st art wit h t he m ost up- t o- dat e copy of a record before you begin m aking changes. I f you ca n 't w a it 6 0 se con ds, a n d you 'r e ge t t in g n e r vou s t h a t som e t h in g's ch a n ge d sin ce t h e la st r e fr e sh , you ca n t r igge r a n im m e dia t e r e fr e sh u sin g t h e H om e Re cor ds Re fr e sh All com m a n d. And, if you click t he downward- point ing arrow part of t his but t on, you can choose t o refresh only t he current record where your cursor is posit ioned ( choose Refresh inst ead of Refresh All) . Re por t s don 't u se a u t om a t ic r e fr e sh e s. I f you run a report , wait , and t hen decide you want t o updat e your result s, you have t wo choices. You can close t he report and reopen it , or you can use t he Refresh but t on.

I f you don't like t he 60- second rule, you can fine- t une how oft en Access perform s it s aut om at ic refreshes. To do so, choose Access Opt ions. I n t he Access Opt ions window, choose t he Advanced cat egory of set t ings, and t hen scroll Office but t on down t he list unt il you see t he " Refresh int erval" box ( Figure 18- 9) .

Note: The refresh interval is an Access setting that affects all the shared databases you open on that computer. If you want everyone to use the same refresh interval, you need to tell them all to update their Access settings.

The short er t he refresh int erval, t he fast er you'll see ot her people's changes. However, short er refresh int ervals also creat e m ore net work t raffic. Most Access fans find t hey can safely lower t he refresh int erval wit hout a problem , unless t hey're using a slow net work.

Figu r e 18-9. The refresh

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-3.html (1 of 7) [1/7/2007 7:14:59 AM]

Section 18.3. Playing Well with Others

interval controls how often Access checks a shared database for changes. You can choose a value (in seconds) from 1 to 32,766.

18.3.2. Dealing with Editing Conflicts Shared dat abases are a bit of a free for all. Ordinarily, Access doesn't im pose any lim it s on m ult iuser changes. I f you're lucky, people will m ake t heir changes in an orderly fashion, one aft er t he ot her. But sooner or lat er, changes will overlap, wit h pot ent ially frust rat ing consequences. Here's an exam ple t hat shows what happens when t wo changes overlap: 1. You open a query t hat shows all t he product s in t he Bout ique Fudge dat abase. 2. You find a recorda t op- selling cheesecake known as The Chocolat e Abysst hat needs changing. You click inside t he Descript ion field t o st art your edit . 3. At t he sam e t im e, Bill Evans in t he sales depart m ent fires up a form t hat also uses t he Product s t able. He browses t o t he sam e record, andrealizing t he pot ent ial for bet t er profit sst art s t o change t he price. Now t wo people are current ly working wit h t he sam e record. What happens next depends on who com m it s t heir change first . 4. Assum e Bill get s t he j ob done first . Quick as a flash he raises t he price, and t hen heads on t o anot her record. 5.

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-3.html (2 of 7) [1/7/2007 7:14:59 AM]

Section 18.3. Playing Well with Others

Back on your com put er, you've finished t ouching up t he Descript ion field. You m ove t o anot her record. Ordinarily, t his is t he point where Access com m it s your edit , saving it t o t he back end dat abase. But in t his case, Access not ices a conflict nam ely, t he version of t he record you're working wit h isn't t he sam e as t he version t hat 's current ly in t he dat abase. 6. Access warns you about t he problem , and gives you t hree opt ions ( see Figure 18- 10) .

Figu r e 1 8 - 1 0 . Between the time you started the edit and the time you tried to apply it, someone else made changes. Access lets you choose how you handle the conflict.

You have t hree ways t o resolve a conflict : ●





Sa ve Re cor d is t he easiest and m ost reckless opt ion. I f you choose it , Access overwrit es t he record in t he dat abase wit h your version. The problem is t hat t his opt ion oblit erat es t he changes t hat t he ot her person m ade. I n t he previous exam ple, t he new descript ion will be saved in t he dat abase, but t he price change will be lost because Access reapplies your old, out - ofdat e price. D r op Ch a n ge s cancels your edit . Access will refresh t he record t o show t he m ost recent inform at ion, and t hen you can t ry m aking your change all over again. This opt ion is reasonable if you can repeat t he edit easilyit 's not as good an opt ion if you've finished a det ailed revision of a large t ext field. Copy t o Clipboa r d cancels your edit , j ust like Drop Changes. However, t he values you changed are copied t o t he clipboard, which m akes it easier t o reapply t hem , as shown in Figure 18- 11.

Figu r e 181 1 . If you copied your last edit to the clipboard, you need two steps to put it back into place. First, paste it into another program (like Word, file:///C|/html/0596527608/access2007tm-CHP-18-SECT-3.html (3 of 7) [1/7/2007 7:14:59 AM]

Section 18.3. Playing Well with Others

shown here). Then, select just the data you want to use, and copy it back to the clipboard by pressing Ctrl+C. Finally, switch back to Access, head over to the field you want to change, and then paste the new value by pressing Ctrl+V.

The best of t he t hree choices is usually t o copy changes t o t he clipboard and t ry t o repeat t he edit . Unfort unat ely, you can't force people t o do t he right t hing. Lazy workers m ay choose t he quicker Save Record opt ion, which quiet ly wipes out som eone else's work. Worst of all, t he person who m ade t he original change has no way t o know it 's been t hrown away. I f you have a high num ber of overlapping edit s in your organizat ion, you'll need t o spend a good bit of t im e t eaching everyone t he right way t o handle it .

Note: Access fans often wish they had a way to merge changesthat is, to update only the fields you changed. In the previous example, this option would let you apply a new description without disturbing the previous user's price change, because both updates affect different fields. However, Access doesn't provide this option. One reason is that there's no way to know if the two sets of changes will be consistent. And there's nothing worse than having a record that contradicts itself.

POWER USERS' CLINIC Splitting Tables for Safer Edits

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-3.html (4 of 7) [1/7/2007 7:14:59 AM]

Section 18.3. Playing Well with Others

One way t o reduce t he num ber of overlapping edit s is t o split t ables int o sm aller pieces. The basic idea is t o t ake a single t able t hat has lot s of fields, and divide it int o t wo sm aller t ables, each cont aining only som e of t he fields. For exam ple, you can t ake a Cust om ers t able and divide it int o a Cust om erAddress t able and a Cust om erFinancial t able. Every record in Cust om erAddress is linked t o a single record in Cust om erFinancial using a one- t o- one relat ionship ( Sect ion 5.3.1) . You'll need bot h records t o get all t he cust om er inform at ion. The best t im e t o split a t able is when you know t hat a t ypical edit will involve t he fields in j ust one t able. Maybe you know t hat cust om er service oft en needs t o updat e address inform at ion, while t he billing depart m ent works wit h t he financial inform at ion, split t ing t he t able is a great idea. The cust om er service depart m ent will use t he Cust om erAddress t able alm ost exclusively, and t he billing depart m ent will use t he Cust om erFinancial t able. The chance of overlapping edit s is great ly reduced, because t he work is split bet ween t wo t ables.

18.3.3. Using Locks to Stop Overlapping Edits I f overlapping changes are causing t oo m any headaches, you have an opt ion. You can use a soft ware t rick called a lock t o prevent overlapping edit s. Essent ially, a lock uses t he sam e concept t hat prot ect s t wo people from ending up in t he sam e bat hroom st all. When one person ent ers, he or she swit ches on t he lock, and everyone else has t o wait unt il t he deed is done. Sim ilarly, when a person at t em pt s t o change a record, Access st art s by grabbing a lock on t hat record. Anyone else who want s t o m ake a change is forced t o wait unt il t he first operat ion is finished. The easiest way t o use locks is t o swit ch t hem on t hrough t he Access set t ings. To do so, choose Office but t on Access Opt ions. Then, choose t he Advanced cat egory, and look for t he " Default record locking" set t ing. You have t hree choices: ● ●



N o lock s is t he st andard set t ing in Access. When you use t his opt ion, Access won't use locking at all, and overlapping edit s are possible. All r e cor ds t ells Access t o lock t he ent ire t able whenever som eone begins edit ing a record. This set t ing is ext rem ely rare. Because it locks every record, it prevent s anyone else from working wit h t he t able when j ust one edit is t aking place. This lim it at ion can bring any organizat ion t o a grinding halt . Edit e d r e cor d locks individual records as t hey're being edit ed. This prevent s overlapping edit s.

The last opt ion is t he m ost com m on locking choice. When you use individual record locking, Access won't let you begin edit ing a record if som eone else is current ly m odifying it . When you t ry, Access displays an icon t hat indicat es t he record is locked, as shown in Figure 18- 12.

Figu r e 181 2 . The don't-gothere symbol warns you to wait rather than edit a record that's already in use. If you still try to type in the field, Access stubbornly

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-3.html (5 of 7) [1/7/2007 7:14:59 AM]

Section 18.3. Playing Well with Others

ignores you.

Locks prevent your dat abase from becom ing a m ess of scram bled inform at ion, but t hey im pose ot her headaches. I t t akes ext ra work for Access t o keep t rack of every- one's lockit has t o play t he role of an overworked washroom at t endant who doles out t he washroom keys. Access keeps t rack of locks by creat ing a .laccdb file. For exam ple, t he first t im e som eone opens t he shared dat abase Bout iqueFudge_be. accdb, Access creat es a file nam ed Bout iqueFudge_be.laccdb. ( The l st ands for locking.) When t he last person closes t he dat abase, Access rem oves t he locking file.

Tip: If you look in the shared folder and don't see a .laccdb file, you know that no one is currently using the database, or someone's opened it in Exclusive mode (Section 18.3.4).

Locks also slow ot her people down, forcing t hem t o wait for t he inform at ion t hey want . A careless user can t ie up a record indefinit ely, leaving it in edit m ode.

Note: If you head out for a lunch break, you may end up tying up the entire company without even knowing it. Even worse, although other wouldbe editors will see that the record is locked, they have no way to know who the culprit is. Their only recourse is to wait…and wait.

I f you decide t o use locking, it 's a m uch bet t er idea t o apply it t hrough individual form s rat her t han swit ch it on for every dat abase using t he Access opt ions. You could use t he st andard " No locks" set t ing for your ent ire dat abase, but configure all t he form s t hat use a part icularly im port ant t ablesay, I nvoicest o use locking. To change t he way a form works wit h locking, open t he Propert y Sheet and look for t he Record Locks propert y. I t support s t he sam e t hree set t ings: No Locks ( t he default ) , All Records, and Edit ed Record.

Note: This trick leaves an open back door. If someone decides to make a change by directly opening the table, they'll bypass the locking that you've implemented in your forms. As always, it's easy to guide people to the right path but harder to force them to stay on it.

18.3.4. Opening a Database in Exclusive Mode One of t he lim it at ions of shared dat abases is t hat you can't change t he design of your t ables while ot her people are using t he dat abase. Before you can m ake m ore radical alt erat ions, you need t o open t he dat abase in Exclusive m ode. Exclusive m ode t em porarily rest rict s a shared dat abase t o a single person. While you have t he dat abase open in Exclusive m ode, no one else will be able t o access it , no m at t er what front - end dat abase t hey use. You have a few precious m om ent s t o m ake t he m ore radical changes t hat you wouldn't norm ally be able t o do. Here's how t o open a dat abase in Exclusive m ode: 1. Te ll e ve r yon e e lse t o close t h e da t a ba se . You can't open a dat abase in Exclusive m ode if it 's current ly in use. I n a big com pany, t his is t he hardest part . Syst em adm inist rat ors som et im es resort t o m ass em ailing t o let everyone know t hat it 's t im e t o shut down. Anot her choice is t o t each t he people who use your dat abase t o close it every night before t hey leave, which let s you slip in a lat e- night updat e wit hout disrupt ion. 2. Ch oose Office bu t t on

Ope n .

The Open window appears.

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-3.html (6 of 7) [1/7/2007 7:14:59 AM]

Section 18.3. Playing Well with Others

Se le ct t h e da t a ba se file you w a n t t o ope n , a n d t h e n click t h e dr op- dow n a r r ow on t h e Ope n bu t t on . A list of specialized opt ions appears for opening your file, as shown in Figure 18- 13. 4. Ch oose Ope n Ex clu sive . Access opens t he dat abase. You can now m ake changes wit h no rest rict ions. But work fast t he longer you keep t he dat abase open in Exclusive m ode, t he longer ot her people will need t o wait t o get on wit h t heir work.

Note: You can configure Access so that it always tries to open every database in Exclusive mode. However, you rarely have a good reason to use this setting, because it defeats the purpose of database sharing.

Figu r e 181 3 . If you open a file in Exclusive mode, no one else can open it until you close it. If you open a file in readonly mode, you can't make any changes.

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-3.html (7 of 7) [1/7/2007 7:14:59 AM]

Section 18.4. Data Corruption

18.4. Data Corruption Dat a corrupt iont he t erm st rikes fear int o t he heart of t he hardiest Access guru. Hopefully, t he people who use your dat abase will be well behaved, t he net work it sit s on will rem ain reliable, and your dat abase will never be in danger. But j ust in case life isn't as kind t o you, it 's im port ant t o be prepared. Dat a corrupt ion is a cat ch- all t erm t hat describes what happens when part of a dat abase file is dam aged. I m agine Jessica Baxt er is in t he m iddle of applying a large updat e when a power failure hit s ( or an office prankst er pulls out her net work cable) . The back- end dat abase will be left in an invalid st at e, because only part of Jessica's inform at ion will have been successfully received. As a result , t he record she was working wit h m ay be scram bled beyond recognit ion. And if you're part icularly unlucky, t he problem can affect m ore t han one record or even m ake t he whole dat abase act a lit t le odd.

18.4.1. Diagnosing (and Fixing) Corrupt Databases Every Access expert should have basic dat a corrupt ion survival skills. First , you need t o be able t o spot when a dat abase has gone bad. Here are som e t ellt ale signs: ●





Cr ypt ic e r r or m e ssa ge s t h a t a ppe a r for n o good r e a son , lik e " ou t of m e m or y." ( Keep in m ind t hat you shouldn't confuse t his wit h t he always- com m on cat egory of crypt ic error m essages t hat appear for a legit im at e reason, like t he " file already in use" error described in Sect ion 18.2.4.) Row s t h a t con t a in gibbe r ish , lik e # # # or ???. Oft en, you'll find t hese values in t he last few rows of a corrupt ed dat abase, which indicat es t hat t he rest of t he dat a is probably kosherit 's j ust t he new addit ions t hat ran int o t rouble. A com ple t e in a bilit y t o u se t h e da t a ba se . I f you get t he dreaded " unrecognizable dat abase form at " error, you know disast er has st ruck.

Once you ident ify t hat a dat abase is corrupt ed, it 's t im e t o nurse it back t o healt h. The first resort is always t he com pact and repair feat ure, which cleans up a host of problem s and shrinks large, bloat ed dat abases back t o m ore reasonable sizes. To t ry out t his feat ure, open your dat abase in Exclusive m ode ( Sect ion 18.3.4) , and t hen choose Office but t on Manage t ake som e t im e, part icularly wit h a large dat abase.

Com pact and Repair Dat abase. The process could

The com pact and repair feat ure fixes only t ables, not form s or report s. However, if you've been sensible and have creat ed a split dat abase, t he back end won't have any of t hese t ypes of obj ect s anyway.

Note: Before you try to fix a corrupt database, make an immediate backup. That way you can try several repair strategies.

Som et im es, t he com pact and repair feat ure won't solve t he problem , or it m ay j ust part ly rehabilit at e your dat abase file. At t his point , it 's t im e t o t ake over wit h ot her repair t echniques. I f t he rem aining problem s are relat ively m inor ( like a few rows wit h suspicious dat a) , you m ay be able t o sim ply delet e t he offending inform at ion and recreat e it . But som et im es Access refuses t o show corrupt ed records wit hout bom barding you wit h error m essages. I f t his is t he case, select all t he good records and copy t hem t o anot her t able. Then, delet e t he t able wit h t he corrupt dat a and renam e your copy t o t ake it s place. file:///C|/html/0596527608/access2007tm-CHP-18-SECT-4.html (1 of 2) [1/7/2007 7:15:02 AM]

Section 18.4. Data Corruption

As a final resort , you can creat e a new blank dat abase, and t ry t o im port t he t ables from t he back end, using t he im port ing t echnique described in Sect ion 18.2.4. This forces Access t o recreat e each obj ect and rebuild every index. Even if t his doesn't work com plet ely, you m ay find t hat you can im port m ost of t he t ables. As a last resort , you'll need t o revert back t o t he last backup. You do keep backups, right ?

18.4.2. Preventing Corruption As scary as dat a corrupt ion is, following a few guidelines can ensure it rem ains a rare occurrence: ●



● ●





St ick t o t he sensible default s described in Sect ion 18.1.1. I f dozens of people t ry t o m ake changes at once, you m ult iply t he chance of a problem . Always split your dat abase ( Sect ion 18.2) t o light en t he load on your back end and t o keep form s and report s out of harm 's way. Use a reliable net work. I f your net work connect ion isn't dependable, an updat e can get int errupt ed, which is a prim e cause of dat a corrupt ion. Teach users t o close t he dat abase when t hey're finished using it or even when t hey're t aking a lunch break. Use t he com pact and repair feat ure on your back- end dat abase regularly ( choose Manage Com pact and Repair Dat abase from t he Office m enu) . As m ore and m ore people m ake changes, dat abase files grow larger and m ore disorganized. The com pact and repair com m and rearranges your dat abase t o be m ore efficient , sm aller, and less likely t o run int o t rouble. Make backups as oft en as possible. Depending on how quickly you m ake changes, a daily backup m ay be sufficient . But t here's no reason you can't m ake a backup every hour or even m ore oft en if needed.

Tip: Make sure you keep a collection of the most recent backups. If you keep only a single backup file, you run the risk that you may back up a database that's already corrupted, and you won't have an older copy to fall back on.

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-4.html (2 of 2) [1/7/2007 7:15:02 AM]

Section 18.5. Securing Your Database

18.5. Securing Your Database I n m ost shared dat abases, different people perform different t asks. The easiest way t o keep everyone on t he right t rack is t o creat e several dist inct front ends, one for each group of people. This let s you gent ly guide people along in t he t asks t hey perform . However, cust om izing t he front end doesn't rest rict t he abilit ies of a det erm ined t roublem aker. I n a large com pany t hat relies on a m ult iuser dat abase, you don't j ust t hink about guiding peopleyou also worry about rest rict ing t hem . Sadly, Access 2007 provides a lim it ed securit y m odel. You have t he abilit y t o lock st rangers out of a dat abase wit h a password, but you don't have t he m ore finegrained feat ures you need t o rest rict a single user from using cert ain t ables or perform ing cert ain act ions. As you'll see in t he following sect ions, t here are possible workarounds, but none works as well as t he securit y provided by a server- side dat abase product like SQL Server.

Tip: Once again, Access gives you just enough to make shared databases work, but not much more. It's up to you to decide whether Access works for your organization. Small outfits are likely to find that it's perfectly fine, while large organizations may want a server product.

18.5.1. Password-Protecting Your Database The password prot ect ion feat ure in Access offers sim ple, no- frills securit y. You choose a single password for your dat abase, and from t hat point on it can't be opened wit hout t he password. Even bet t er, t he dat a in your dat abase file is scram bled using a key t hat 's generat ed from your password. This ensures t hat even if high- t ech hackers peer direct ly int o your dat abase file wit h a specialized t ool, t hey won't be able t o ret rieve any dat a.

NOSTALGIA CORNER Workgroup Security Gets Locked Out

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-5.html (1 of 8) [1/7/2007 7:15:07 AM]

Section 18.5. Securing Your Database

Old- hand Access expert s m ay rem em ber t hat previous versions of Access included a m uch m ore useful form of userlevel securit y called workgroup securit y. Wit h workgroup securit y, Access keeps a separat e file t hat ident ifies what each user and group is allowed t o do wit h t he dat abase. Workgroup securit y is easier t o im plem ent t han file- based securit y, and a lot m ore flexible. I n fact , it seem s like t he perfect solut ion. Unfort unat ely, workgroup securit y was never t ruly secure. Well- published workarounds could be used t o circum vent it . Most of t he t im e, t his wasn't a problem because Access expert s weren't really worried about st opping skilled hackers. I nst ead, t hey were m ore concerned wit h keeping ordinary people under cont rol. However, in recent years Microsoft has becom e increasingly obsessed wit h securit y. When Microsoft prepared Access 2007, it decided it could no longer support a securit y feat ure t hat wasn't t ruly secure, especially when bet t er opt ions are available in ot her product s, like t he free version of SQL Server ( see Sect ion 20.1.2) . For t hat reason, Microsoft rem oved support for workgroup securit y in .accdb files. You can st ill use workgroup securit y if you use older . m db files ( see Sect ion 1.2.2 t o learn about t he difference) , but t hat 's only a good idea if you need t o keep support ing a dat abase t hat you designed wit h an older version of Access. New dat abases should always be creat ed as .accdb filesaft er all, Access has earm arked it as t he dat abase form at of t he fut ure.

Note: In Access 2007, password protection gets serious. Now, Access uses state-of-the-art encryption to ensure that skilled hackers can't crack open your files with specialized toolsat least not unless they're willing to devote a huge amount of time to the task.

I t 's ridiculously easy t o apply a password. Here's how: 1. Ch oose Office bu t t on

Ope n .

To apply a password, you need t o open your dat abase in Exclusive m ode. This st ep is necessary because Access can't encrypt a dat abase while it 's in use. 2. Se le ct t h e file you w a n t t o ope n , click t h e dr op- dow n a r r ow on t h e Ope n bu t t on , a n d t h e n ch oose Ope n Ex clu sive . Access opens t he dat abase in Exclusive m ode. 3. Ch oose D a t a ba se Tools

D a t a ba se Tools

En cr ypt w it h Pa ssw or d.

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-5.html (2 of 8) [1/7/2007 7:15:07 AM]

Section 18.5. Securing Your Database

Access asks you t o supply a password ( Figure 18- 14) . 4. En t e r you r pa ssw or d, a n d t h e n click OK. To ensure t hat your dat abase is secure, you need t o choose a st rong password. Good passwords are long ( t en let t ers or m ore) , can't be found in t he dict ionary ( because at t ackers use dict ionaries t o launch aut om at ed at t acks) , use m ixed case, and include special charact ers ( like num bers, punct uat ion, and ot her sym bols) . The password hellodat a is a poor choice, while w0nDER_wh@t _32 is m uch m ore reliable.

Figu r e 1 8 1 4 . Just to be sure, Access asks you to enter the password twice.

Access uses t he password t o encrypt your dat abase, and t hen saves t he m odified dat abase aut om at ically. Now, t he next t im e you open your dat abase you'll be asked t o supply t he password first . I f you decide t hat you don't need password prot ect ion lat er on, click Rem ove Dat abase Password and Encrypt ion.

18.5.2. Passwords and Split Databases I t 's fairly obvious how passwords work wit h ordinary dat abases, but a few int erest ing quirks are at work wit h shared dat abases. First , you always use t he password t o prot ect t he back- end dat abaseaft er all, it 's t he dat a t hat you need t o prot ect , not your form s and report s. But here's t he int erest ing bit : When you creat e a front end t hat links t o a password- prot ect ed back end, Access quiet ly st ores t he password in t he front end. That m eans t hat as along as you use t he right front end, you don't need t o supply t he password at all.

Note: In order to successfully use a password with a back-end database, you must apply the password before you split the database. Otherwise, Access won't store the password in the front end, and the linked tables won't work.

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-5.html (3 of 8) [1/7/2007 7:15:07 AM]

Section 18.5. Securing Your Database

Technically speaking, t his m odel doesn't provide indust rial- st rengt h securit y, because a craft y hacker could st eal t he password by digging t hrough t he front - end dat abase file. However, as long as you m ake sure your front ends don't get int o t he wrong hands, you have som e int erest ing possibilit ies: ●

● ●

You ca n k e e p t h e pa ssw or d se cr e t , w h ich pr e ve n t s pe ople fr om a cce ssin g t h e ba ck e n d dir e ct ly. I nst ead, t hey'll need t o rely on t he front end you dist ribut e, which has t he password em bedded. You ca n pr ot e ct t h e fr on t e n d w it h a n ot h e r pa ssw or d. That way, a sneaky hacker who st eals your front end will st ill be locked out of t he dat abase. You ca n split t h e ba ck - e n d da t a ba se in t o se pa r a t e file s ( a s de scr ibe d in Se ct ion 1 8 .2 .4 ) . That way, you can give each file a separat e password and prevent people from accessing t he wrong t ables. Unless t heir front end has a link t o t he back- end dat abase t hey need, t hey won't be able t o use it s t ables.

18.5.3. Using Windows File Security Password prot ect ion isn't your only securit y choice. You can also use Windows securit y t o specifically set which users and groups can access a file. I n order t o m ake t his work, you need t o split your back end int o m ore t han one file, as described in Sect ion 18.2.4. Then, once t he files are in t he shared folder, you can configure exact ly who is allowed t o access each one. Hopefully, you have a net work adm inist rat or t o help you out . The basic process works like t his: 1. Usin g W in dow s Ex plor e r , r igh t - click t h e da t a ba se file you w a n t t o pr ot e ct , a n d t h e n Ch oose pr ope r t ie s. The Propert ies window appears, wit h several t abs of inform at ion about t he file. 2. Ch oose t h e Se cu r it y t a b ( Figu r e 1 8 - 1 5 ) . Windows keeps t rack of people in t wo waysit ident ifies t hem uniquely by user nam e, and it cat egorizes ent ire groups of people by group nam e. For exam ple, you can log in as MarkHam lon and be a m em ber of several groups, including Users, Adm inist rat ors, SalesDepart m ent , and so on. That gives an adm inist rat or t he abilit y t o change t he securit y set t ings for a single individual or for a whole crowd of people wit h one rule.

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-5.html (4 of 8) [1/7/2007 7:15:07 AM]

Section 18.5. Securing Your Database

Figu r e 1815. The Security tab lists all the people (and groups) who are allowed to use this file, and it indicates what they're allowed to do. In this example, every user and group name is preceded by the term FARIA\ because the name of the computer where the user accounts are

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-5.html (5 of 8) [1/7/2007 7:15:07 AM]

Section 18.5. Securing Your Database

defined is FARIA.

3. To ch a n ge w h a t a pe r son or gr ou p ca n do w it h t h e file , se le ct t h e m in t h e list , a n d t h e n ch a n ge t h e Allow or D e n y opt ion s ( Figu r e 1 8 - 1 6 ) . Say you don't want t he people in t he Users group t o be able t o use t his file; select t he Users group in t he list , and t hen place a checkm ark in t he Deny colum n next t o each perm ission.

Note: The Deny options always take precedence. For example, if a person is a member of two groups, and one group is allowed to use a file but the other isn't, the Deny setting overrides everything else.

Figu r e 1 8 - 1 6 . If the checkbox is grayed out, that's because the setting is inheritedin other words, it's based on the folder that contains this file. For example, file:///C|/html/0596527608/access2007tm-CHP-18-SECT-5.html (6 of 8) [1/7/2007 7:15:07 AM]

Section 18.5. Securing Your Database

you can't change the Allow settings of the Users group, because they're inherited. However, you can add Deny settings (as shown here with the user named RemoteUser). The Deny settings always overpower the Allow settings.

4. I f you w a n t t o a dd a n e w gr ou p or pe r son t o t h e list , click t h e Add bu t t on , fill in t h e u se r or gr ou p n a m e , a n d t h e n click OK. You m ay decide you don't want t o lock out an ent ire group but you want t o single out a specific

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-5.html (7 of 8) [1/7/2007 7:15:07 AM]

Section 18.5. Securing Your Database

person. Windows file securit y gives you dat abases. I n order t o use it at can be difficult t o m anage. You securit y eit her locks people out inform at ion in your dat abase.

a very basic level of securit y. I t isn't really designed t o work wit h Access all, you need t o split your dat abase int o sm aller and sm aller pieces, which also can't cont rol what act ions a person is allowed t o perform t he file ent irely or gives t hem full cont rol t o add, delet e, updat e, and redesign t he

I f you need real user- level securit y, you're bet t er off wit h a server product like SQL Server. However, if you j ust need t he abilit y t o keep som e sensit ive inform at ion out of reach, t he file- based securit y feat ures can help you out .

file:///C|/html/0596527608/access2007tm-CHP-18-SECT-5.html (8 of 8) [1/7/2007 7:15:07 AM]

Chapter 19. Importing and Exporting Data

19. Importing and Exporting Data An Access dat abase is like a carefully built fort . I t t akes st rict ly organized and error- t est ed inform at ion, and locks it up t ight . Very few program s guard t heir dat a as prot ect ively as dat abase soft ware does. Word processors and spreadsheet program s accept j ust about any cont ent and let you build your docum ent st ruct ure on t he fly. Dat abases aren't nearly as freewheeling. Most of t he t im e, dat abases live in an independent world. But every once in a while, you need t o bridge t he gap in one of t wo ways: ● ●

You want t o t ake t he inform at ion from anot her program and im port it basically, st uff it int o your dat abase. You want t o t ake som e of t he inform at ion in an Access dat abase and export it , so you can work wit h it in anot her program .

Access has several different opt ions for t ransferring inform at ion. You can use t he lowly clipboard, sophist icat ed im port and export feat ures, or t he ever- popular XML st andard. I n t his chapt er, you'll learn about all your opt ions, including one new and pret t y nift y t rick: how t o let people em ail you t heir updat es t o a dat abase. This isn't your fat her's Access.

file:///C|/html/0596527608/access2007tm-CHP-19.html [1/7/2007 7:15:09 AM]

Section 19.1. Case for Importing and Exporting

19.1. Case for Importing and Exporting I f you haven't t hought m uch about im port ing and export ing, it 's probably because you don't need t o use t hese feat uresyet . Many dat abases are com plet ely happy living a quiet , solit ary life. However, im port ing and export ing m ight com e in handy for a few reasons. Sooner or lat er, one of t hese reasons will apply t o you.

19.1.1. Understanding Exports Export ing's t he easier part of t he equat ion. Export ing's sim pler t han im port ing, because it involves m oving inform at ion from a st rict er st orage locat ion ( t he dat abase) t o one wit h fewer rules ( anot her t ype of docum ent ) .

Note: Exporting's a way to transfer a copy of your information to another location. The original copy always remains in Access. There's no point in changing the exported copy. Instead, if you need changes, make them in the database, and then perform the export operation again.

Here are som e of t he m ost com m on reasons people decide t o export inform at ion: ● ●

You w a n t t o e m a il som e in for m a t ion t o a fr ie n d. You don't want t o send t he Access dat abase because your friend doesn't have a copy Access, or you want him t o see only som enot allof t he dat a You 'r e cr e a t in g a pr e se n t a t ion in Pow e r Poin t . The easiest way t o dazzle and convince your peers is t o show t hem som e im pressive inform at ion from your dat abase.

Tip: Access stores huge volumes of information, which is often more than other programs can handle. You'd never be able to copy a table into a PowerPoint presentationat most, a slide can fit a handful of records. However, you might choose to show the results of a totals query (Section 7.3) that uses grouping to boil down the results to a few subtotals. ●

You w a n t t o a n a lyze t h e in for m a t ion in Ex ce l. Access is great for st oring and m anaging your dat a, but it doesn't give you t he t ools t o help you figure out what it all m eans. I f you want t o crunch t he num bers wit h heavy dut y form ulas and slick chart ing feat ures, it m akes sense t o m ove it t o Excel.

Som e program s are int elligent enough t o pull t he inform at ion out of an Access dat abase all on t heir own. One exam ple's Word, which provides a m ail m erge feat ure t hat let s you t ake a list of nam es and addresses from a dat abase, and t hen use t hem t o creat e m ailing labels, personalized form s, or any ot her sort of bat ch paper- work. When using t his feat ure, you don't need t o perform any export inginst ead, you can j ust point Word t o your Access dat abase file. ( For m ore inform at ion about Word's m ail m erge feat ure, see Word 2007: The Missing Manual.)

19.1.2. Understanding Imports file:///C|/html/0596527608/access2007tm-CHP-19-SECT-1.html (1 of 3) [1/7/2007 7:15:12 AM]

Section 19.1. Case for Importing and Exporting

You need im port ing whenever t here's inform at ion out side your dat abase t hat belongs inside it . Suppose you creat e a st at e- of- t he- art e- com m erce dat abase for your buffalo farm . However, som e of your sales associat es st ill fill out form s using an old Excel spreadsheet . Now, you need a way t o get t he inform at ion out of t he Excel spreadsheet and int o your dat abase.

Tip: Your sales staff has let you down. They really shouldn't enter data into a document for another program. Instead, they should use a form that's designed for logging sales, as described in Chapter 12.

I m port operat ions have t wo key challenges. The first 's m aking sure t he dat a fit s t he dat abase's st rict requirem ent s. As you learned in Chapt er 1, dat abases are rule- crazy, and t hey rudely t oss out any inform at ion t hat doesn't fit ( for exam ple, t ext in a dat e field) . The second challenge is dealing wit h inform at ion t hat doesn't quit e line upin ot her words, it s represent at ion in t he dat abase doesn't m at ch it s represent at ion in t he ext ernal docum ent . This headache's m ore com m on t hat you m ay t hink. I n your dat abase, you m ight use st at us codes ( like 4302) , while t he spreadsheet you want t o im port uses st at us nam es ( like High Priorit y) . Or, you m ay need t o break t he inform at ion you're im port ing int o m ore t han one linked t able, even t hough it 's st ored t oget her in a single docum ent . The cust om er order spreadsheet for your buffalo farm could include cust om er inform at ion ( which corresponds t o t he Cust om ers t able) and order inform at ion ( for t he Orders t able) . Sadly, you don't have any easy way t o solve t hese problem s. I f t he ext ernal dat a doesn't m at ch t he represent at ion in t he dat abase exact ly, you'll need t o change it by hand before or aft er t he im port operat ion. Expert s occasionally t ry t o solve problem s like t hese by writ ing Visual Basic code t hat reads t he dat a and creat es t he appropriat e records. ( To do t his, you'd need t o use t he DAO obj ect s described in Sect ion 17.4.5.) While t he code approach is infinit ely flexible, it can quickly becom e a night m are t o writ e and m aint ain, so avoid it if at all possible.

UP TO SPEED SQL Server and SharePoint: Two Special Cases You won't consider t wo program s in t his chapt er. SQL Server's t he high- powered server- side dat abase product described in Chapt er 20. I f your Access dat abase is growing exponent ially, you m ay decide t o m ove your dat a t o SQL Server. However, you don't use t he ordinary export feat ure t o do it . I nst ead, Access has a specialized " upsizing" t ool t o help you out , and you can learn about it in Chapt er 20. SharePoint 's anot her indust rial- st rengt h server product t hat st ores large volum es of inform at ion. But unlike SQL Server, SharePoint 's designed t o help t eam s of people share inform at ion and collaborat e over net works or t he Web. I f you want t o m ove inform at ion int o ( or out of) a SharePoint list , you'll need t o t ake a look at Chapt er 21.

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-1.html (2 of 3) [1/7/2007 7:15:12 AM]

Section 19.1. Case for Importing and Exporting

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-1.html (3 of 3) [1/7/2007 7:15:12 AM]

Section 19.2. Using the Clipboard

19.2. Using the Clipboard Anyone who's spent m uch t im e using a Windows com put er is fam iliar wit h t he clipboarda behind- t he- scenes cont ainer t hat t em porarily st ores inform at ion so you can t ransfer it from one program t o anot her. Using t he clipboard, you can copy a snippet of t ext in a Word docum ent , and t hen past e it int o a field in an Access t able, or vice versa. That m uch is easy. But you probably don't realize t hat you can copy an ent ire t able of inform at ion.

Tip: Almost all Windows programs respect the same shortcut keys for the clipboard. Use Ctrl+C to copy information, Ctrl+X to cut it (copy and delete it), and Ctrl+V to paste it.

Before you t ry t his t rick out , you need t o underst and t wo key fact s about t he clipboard: ● ●

Th e clipboa r d ca n st or e m a n y diffe r e n t t ype s of in for m a t ion . Most of t he t im e, you're using it t o copy plain t ext . However, depending on t he program you're using, you could also copy shapes, pict ures, t ables, and m ore. Som e t ype s of in for m a t ion ca n con ve r t t h e m se lve s t o ot h e r t ype s. I f you copy a select ion of cells in Excel, t hen you can past e it as a form at t ed t able in a word processing program like Word or WordPerfect . Of, if you copy a diagram in Visio, t hen you can past e it as a pict ure in Paint . I n bot h exam ples, you copy a specialized t ype of obj ect ( Excel cells or a Visio diagram ) t o t he Windows clip- board. However, t his obj ect can downgrade it self when it needs t o. You can past e a full- fledged copy of t he obj ect in t he original program wit hout losing anyt hing, or you can past e and convert it t o som et hing sim pler in a less powerful program .

This flexibilit y's t he secret t o t ransferring dat a t o and from Access. The following sect ions explain how it works.

Note: The clipboard approach is simpler than the import and export features in Access. As a result, it's a faster choice (with fewer steps). Of course, it also gives you fewer choices and doesn't work with all programs.

19.2.1. Copying a Table from Access to Somewhere Else Access let s you copy a select ion of rows or an ent ire t able t o anot her program , wit hout going t hrough t he hassle of t he Export wizard. Access copies t hese rows t o t he clipboard as an int elligent obj ect t hat can convert it self int o a variet y of soft ware- friendly form at s. You can past e t hem as Excel cells, HTML t ext ( t he form at t ing language of t he Web) , or RichText ( a form at t ing st andard creat ed by Microsoft and support ed by all m aj or Word processors) . Since HTML and Rich- Text are so widely support ed, you'll alm ost never have a problem copying your rows int o anot her program when you use t his t echnique. Here's how t o t ry it out : 1. I f you w a n t t o copy a n e n t ir e t a ble , t h e n , in t h e n a viga t ion pa n e , se le ct t h e t a ble . I f you w a n t t o copy on ly a fe w r ow s, t h e n se le ct t h e m in t h e D a t a sh e e t vie w , a s sh ow n in Figu r e 1 9 - 1 . You're not lim it ed t o copying t ables. You can also copy a query's result s. Just select t he query in t he navigat ion pane. You can't copy report s or form s, however. When you copy rows or an ent ire t able, Access t akes your colum n hiding set t ings ( Sect ion 3.1.4) int o account . I f you've hidden a colum n so it doesn't appear in t he dat asheet ( by select ing it , and t hen choosing Hom e Records More Hide Colum ns) , Access doesn't copy it t o t he clipboard. This t echnique helps you leave out inform at ion you don't want t o copy.

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-2.html (1 of 5) [1/7/2007 7:15:16 AM]

Section 19.2. Using the Clipboard

Figu r e 19-1. When selecting rows in the datasheet, click the gray margin just to the left of the first row you want to select. Then, drag down to select as many rows as you want. If you don't want to take your hand off the mouse, then you can copy these rows by holding down the Ctrl key, and rightclicking one of them. Then, from the pop-up menu, choose Copy.

Note: You can copy only a contiguous selection of rows, which is a fancy way of saying you can copy only rows that are right next to each other. If you have 10 rows in a table, then you can copy rows three to six, but you can't copy just the first and last rows. (Of course, you can use several smaller copy operations to get the stragglers.)

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-2.html (2 of 5) [1/7/2007 7:15:16 AM]

Section 19.2. Using the Clipboard

H it Ct r l+ C t o copy you r se le ct ion . This act ion places t he records on t he Windows clipboard. You can now past e it inside Access or in anot her program . 3. Sw it ch t o t h e pr ogr a m w h e r e you w a n t t o pa st e you r in for m a t ion . I f you're j ust t rying t his feat ure out for t he first t im e, t hen t ake a whirl wit h Excel or Word ( shown in Figure 19- 2) . 4. H it Ct r l+ V t o pa st e you r se le ct ion ( se e Figu r e 1 9 - 2 ) . Access past es t he rows from your select ion, com plet e wit h colum n headers. I f you've applied form at t ing t o t he dat asheet ( Sect ion 3.1) , t hen m ost of t hat form at t ing com es along. Depending on t he program where you past e your records, you m ight see a sm art t ag icon appear at your newly past ed cont ent 's right - hand corner. I n Office applicat ions, you can use t his sm art t ag t o change opt ions about how t he dat a's past ed ( for exam ple, wit h or wit hout form at t ing) .

Figu r e 19-2. Using cut and paste, you can transform a database table into a table in a Word document (shown here). Once you've pasted the content, you may need to fiddle with column widths to make sure it all looks right.

Note: Copying text, numbers, and dates is easy. However, some data types don't make the transition as well. If you copy an attachment field, file:///C|/html/0596527608/access2007tm-CHP-19-SECT-2.html (3 of 5) [1/7/2007 7:15:16 AM]

Section 19.2. Using the Clipboard

then the pasted content shows the number of attachment fields, but the files themselves are left out.

TIMESAVING TIP Copying from One Database to Another You can also use t he copying t rick described in Sect ion 19.2.1 t o copy dat a from one Access dat abase t o anot her Access dat abase t hat 's open in a separat e window. However, it works only if you're copying a com plet e t able ( or ot her obj ect ) , not a select ion of rows. To t ry it out , right - click t he obj ect you want in t he navigat ion pane, and t hen choose Copy. Then, swit ch t o t he second Access dat abase, right - click in t he em pt y space in t he navigat ion pane, and t hen choose Past e. Access asks you what you want t o nam e t he past ed t able, and gives you t hree past ing opt ions: ● ● ●

St r u ct u r e creat es t he t able st ruct ure, but leaves it em pt y. St r u ct u r e a n d D a t a creat es an exact duplicat e of t he t able, wit h all t he dat a. Appe n d D a t a t o Ex ist in g Ta ble doesn't creat e a new t ableinst ead, it adds t he dat a t o t he t able t hat you specify. For t his t o work, t he t able m ust have t he sam e st ruct ure as t he one you've copied.

This t rick also let s you creat e a duplicat e copy of a t able ( or ot her obj ect ) in t he sam e dat abase.

19.2.2. Copying Cells from Excel into Access You can copy inform at ion from Access int o anot her program easily enough, but you probably don't expect t o be able t o do t he reverse. Aft er all, a dat abase is a st rict , rigorously st ruct ured collect ion of inform at ion. I f you t ry t o copy a t able from a Word processing program , t hen you'll lack vit al inform at ion, like t he dat a t ypes of each colum n. For t hat reason, Access doesn't allow it . However, Access m akes a special except ion for everyone's favorit e spreadsheet program , Excel. You can copy a select ion of cells in Excel, and t hen past e t hem int o Access t o creat e a new t able. This procedure works because Excel does dist inguish bet ween different t ypes of dat a ( alt hough it isn't nearly as picky as Access) . For exam ple, Excel t reat s num bers, dat es, t ext , and TRUE/ FALSE values different ly. Here's how t o use t his feat ure: 1. I n Ex ce l, se le ct t h e ce lls you w a n t t o copy. I f your spreadsheet includes colum n t it les, t hen include t hose headers in t he select ion. Access can use t he t it les as field nam es.

Note: It doesn't matter what version of Excel you havethis trick works with them all. 2. H it Ct r l+ C t o copy you r se le ct ion . 3. Sw it ch t o Acce ss. 4. Click a n yw h e r e in t h e n a viga t ion pa n e , a n d t h e n pr e ss Ct r l+ V. Access not ices t hat you're t rying t o past e a group of Excel cells, and it t ries t o t ransform t hem int o a t able. First , it asks if t he first row in your select ion includes colum n t it les. 5.

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-2.html (4 of 5) [1/7/2007 7:15:16 AM]

Section 19.2. Using the Clipboard

I f you se le ct e d t h e colu m n t it le s in st e p 1 , t h e n ch oose Ye s. Ot h e r w ise , ch oose N o. I f you choose Yes, t hen Access doesn't need t o creat e random field nam esinst ead, it can use your headers. Access creat es a new t able t o deal wit h t he new dat a. This t able's nam ed aft er t he Excel sheet . I f your sheet 's nam ed Sheet 1 ( as so m any are in Excel) , you now have a Sheet 1 t able. Once Access finishes t he past e, it shows a confirm at ion m essage t o let you know everyt hing's finished successfully. 6. Click OK. Now you can refine your t able t o m ake sure t he dat a t ypes and field nam es are exact ly what you want .

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-2.html (5 of 5) [1/7/2007 7:15:16 AM]

Section 19.3. Import and Export Operations

19.3. Import and Export Operations Alt hough t he clipboard cut - and- past e approach is neat , it doesn't always work out . I f you need t o export dat a t o a file and you don't have t he corresponding program inst alled on your com put er ( or you j ust don't want t o bot her running it ) , t hen you need a different way t o t ransfer your inform at ion. Sim ilarly, if you're downloading dat a from t he Web or fet ching inform at ion from a program t hat doesn't support Windows cut - and- past e, you need t he full- fledged Access im port feat ure. When Microsoft designed Access 2007, t hey spent a fair bit of t im e m aking t he im port and export feat ures clearer and m ore st raight forward. Nowadays, you can do all t he im port ing and export ing you want from a single ribbon t ab, which is nam ed Ext ernal Dat a ( Figure 19- 3) .

Figu r e 19-3. The External Data tab's Import section lets you pipe data into Access using a variety of formats. The Export section does the reverseit takes your table, and exports it in a bunch of different flavors.

Note: The Import and Export sections have easy-to-access buttons for the most popular file formats. If you don't see what you want, then click the More button to see an expanded list of choices.

Whet her you're im port ing or export ing dat a, t he process is essent ially t he sam e. You answer a few quest ions about what file you want t o use and how you want t o m ake t he conversion, and t hen Access does your bidding. Once you finish perform ing an im port or export operat ion, Access gives you t he opt ion of saving all your st eps. I f you do, you can reuse t hem lat er on ( see Sect ion 19.3.7) . This m et hod's a great way t o save t im e if you need t o perform t he sam e export or im port process again ( like if you need t o im port som e dat a every day, or export a sum m ary at t he end of every m ont h) .

19.3.1. Importable File Types file:///C|/html/0596527608/access2007tm-CHP-19-SECT-3.html (1 of 12) [1/7/2007 7:15:28 AM]

Section 19.3. Import and Export Operations

Most of t he t im e, you'll im port dat a t hat 's in one of t hese five com m on form at s: ●

● ●





Acce ss. When you use t his opt ion, you aren't perform ing a conversion. I nst ead, you're t aking a dat abase obj ect from anot her Access dat abase file, and copying it int o t he current dat abase. You used t his opt ion in Chapt er 18 ( Sect ion 18.2.4) when building a front - end dat abase. Ex ce l. Pulls t he dat a from an Excel spreadsheet . Sh a r e Poin t List . Pulls t he dat a from a list t hat 's host ed on a SharePoint server. You don't need t o im port SharePoint inform at ion in order t o work wit h it . Youcan also edit SharePoint list s direct ly in Access. Chapt er 21 has m uch m ore about get t ing Access and SharePoint t o work t oget her. Te x t File . Pulls t he dat a out of a plain t ext file. Typically, plain t ext files use som e sort of charact er ( like a com m a) t o separat e field values. This universally underst ood form at 's support ed by m any program s, including j ust about every piece of spreadsheet soft ware ever writ t en. When using t his opt ion, Access t akes a look at t he t ext file as it t ries t o figure out how it 's organized. However, you get t he chance t o confirm or correct t he hunch before you im port any dat a, as described in Sect ion 19.3.4. XM L File . Pulls t he dat a out of a st ruct ured XML file. XML is a cross- plat form form at used t o represent any t ype of inform at ion. However, you can't successfully im port all XML filesfor t he im port feat ure t o have any chance of success, t he XML file m ust use a t able- like st ruct ure. You'll learn m ore about t his opt ion in Sect ion 19.4.6.

Using t he More but t on, you'll find several ot her, m ore exot ic im port choices: ● ● ● ●

OD BC D a t a ba se . Grabs inform at ion from j ust about any dat abase product , provided it has an ODBC driver. This opt ion works part icularly well if you need t o get dat a out of a high- end server- side dat abase like Oracle, SQL Server, or MySQL. H TM L D ocu m e n t . Ext ract s inform at ion from a list or a t able in an HTML Web page. Since HTML's a st andard t hat 's not oriously loose ( and at t im es down- right sloppy) , you should t ry t o avoid t his opt ion. You're likely t o have im port ing problem s. Ou t look Folde r . Pulls inform at ion out of a folder in Out look or Out look Express. dBa se File , Pa r a dox File , a n d Lot u s 1 - 2 - 3 File . Pulls inform at ion out of a file creat ed wit h one of t hese Paleolit hic program s.

19.3.2. Importing Data No m at t er what t ype of dat a you want t o im port , you'll go t hrough t he sam e basic st eps. Here's an overview: 1. I n t h e r ibbon 's Ex t e r n a l D a t a t o im por t .

I m por t se ct ion , click t h e bu t t on t h a t cor r e spon ds t o t h e t ype of file you w a n t

When you choose a form at , Access launches t he I m port wizard ( Figure 19- 4) . 2. En t e r t h e n a m e of t h e file you w a n t t o im por t . I f you don't rem em ber t he file pat h ( or you j ust don't want t o t ype it in by hand) , t hen click Browse, and t hen navigat e t o t he right place in t he File Open window. Once you find t he file, double- click it .

Figu r e 19-4. No matter what format you choose, the Import wizard's more or

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-3.html (2 of 12) [1/7/2007 7:15:28 AM]

Section 19.3. Import and Export Operations

less the same, although certain options may be restricted. In this first step, you choose the source file name, and the way Access inserts the information into your database.

3. Ch oose w h e r e t o pla ce t h e im por t e d con t e n t in you r da t a ba se . You have t hree possible choices for placing your dat a. Depending on t he file form at you're using, all t hese m ay not be available. ❍





Cr e a t e a n e w t a ble . This opt ion creat es a fresh new t able for t he dat a you're im port ing, which saves you t he headache of worrying about conflict ing records. However, if a t able of t he sam e nam e already exist s in t he Access dat abase, t hen t his opt ion wipes it out . Appe n d t o a n e x ist in g t a ble . This opt ion t akes t he rows you're im port ing and adds t hem t o an exist ing t able. I n order for t his opt ion t o work, t he st ruct ure of t he dat a you're im port ing m ust m at ch t he st ruct ure of t he t able you're using. For exam ple, t he field nam es m uch m at ch exact ly. However, t he dat a you're im port ing can leave out fields t hat aren't required ( Sect ion 4.1.1) or have default values ( Sect ion 4.1.2) . Cr e a t e a lin k e d t a ble . I f you use t his approach, t hen Access doesn't act ually t ransfer t he inform at ion int o your dat abase. I nst ead, every t im e you view t he linked t able, Access checks t he original file t o get t he m ost recent inform at ion. The neat t hing here's t hat your linked t able always shows t he m ost recent inform at ion. Wit h any ot her opt ion, t he im port ed t able's left unt ouched if you change t he original file. However, linked t ables are also risky, because you don't have any guarant ee t hat t he file won't t ravel t o anot her locat ion on your hard drive ( where Access can't find it ) . You used linked t ables t o creat e a split dat abase in Chapt er 18.

Note: Linked tables are a good way to bridge the gap between different Access databases or other databases (like SQL Server). However, they don't work well with other more limited formats, like text files. 4. Click OK. A wizard launches t hat collect s t he rem aining inform at ion t hat Access needs. I f you're im port ing an Excel file, t hen Access asks you which worksheet t o use. I f you're im port ing a t ext file, t hen Access asks you how t he fields are separat ed. 5.

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-3.html (3 of 12) [1/7/2007 7:15:28 AM]

Section 19.3. Import and Export Operations

An sw e r a ll qu e st ion s in t h e w iza r d t o t e ll Acce ss w h a t it n e e ds t o k n ow a bou t t h e st r u ct u r e of t h e da t a you 'r e im por t in g. Once you're finished wit h t his st age, Access asks you it s final quest ionwhet her or not you want t o save your im port st eps. 6. I f you w a n t t o pe r for m t h is im por t a ga in la t e r on , t h e n se le ct " Sa ve im por t st e ps" . Th e n , click Close . Sect ion 19.3.7 shows how t o reuse a saved im port .

Note: If Access finds any errors while importing your data, then it creates another table with the same name as the table you're importing to, with_ImportErrors tacked on the end. Access adds one record to that table for each problem. If you try to import a bunch of information into a table named SalesData, and Access can't convert the values to the data type you want (for example, there's text in a column that should only hold numbers), you get a table named SalesData_ImportErrors.

The following sect ions walk you t hrough t he specifics for t wo com m on dat a form at s t hat need a few ext ra st eps: Excel workbooks and t ext files.

19.3.3. Importing from an Excel File I n order t o im port from an Excel file, your dat a should be organized in a basic t able. I deally, you have colum n headings t hat m at ch t he fields in your dat abase. You should t rim out any dat a t hat you don't want t o im port ( like ot her cells under t he t able t hat aren't a part of t he t able) . You should also rem ove values calculat ed using Excel form ulas. ( As you learned in Sect ion 2.5.5, you shouldn't st ore calculat ed values in a t able, because t hey int roduce t he risk of inconsist ent dat a.)

Note: Earlier in this chapter, you learned how to take Excel data, and cut and paste your way to an Access table. However, when you perform a full-fledged import, you get the opportunity to change field names, fine-tune data types, and use indexing.

Once you have a cleaned- up t able of dat a in an Excel file, you're ready t o st art t he im port process: 1. I m por t Ex ce l, ch oose you r Ex ce l file , a n d t h e n spe cify h ow you w a n t t o a dd Ch oose Ex t e r n a l D a t a t h e im por t e d in for m a t ion t o you r da t a ba se . Th e n , click OK. You learned how t o m ake t hese decisions in st eps 1 t o 3 in Sect ion 19.3.2.

UP TO SPEED Th e D a n ge r of D u plica t e s I f your im port 's adding ( ot herwise known as appending) records t o an exist ing t able, t hen you're in danger of every im port er's worst night m are: duplicat ion. Quit e sim ply, Access has no way of t elling whet her or not it 's already im port ed t he sam e inform at ion. I f you've set Access t o aut om at ically fill in an aut onum bered I D value for each record, t hen it cheerily adds t he sam e dat a several t im es, wit h a different I D value each t im e. On t he ot her hand, if you aren't using aut onum bered I D values and t he dat a you're im port ing cont ains t he prim ary key, t hen Access can't im port t he new dat a at all. Obviously, neit her out com e's ideal. I f you're in t he im port business for t he long t erm , t hen t he only solut ion's t o be very careful. Here are som e t ips: ❍







I f you want t o reuse a file aft er you've im port ed t he dat a it cont ains, t hen m ake sure you delet e all t he inform at ion you've already im port ed right away. I f you suspect you m ight have im port ed t he sam e inform at ion t wice, t hen use a query t o check. You can creat e your own, or you can use t he Find Duplicat es query t hat t he Query wizard creat es ( Sect ion 6.2.2) . Perform sm all updat es frequent ly, rat her t han less frequent large updat es. That way, you'll cat ch m ist akes fast er, and have an easier t im e t racking t hem down. I f you really need a m ore robust solut ion, t hen you need t o build it yourself. You can use Visual Basic code t o cont rol exact ly how Access t ransfers dat a ( which is a lot m ore work) .

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-3.html (4 of 12) [1/7/2007 7:15:28 AM]

Section 19.3. Import and Export Operations

2. Ch oose t h e w or k sh e e t t h a t h ou se s you r da t a ( Figu r e 1 9 - 5 ) . Excel files, or workbooks, begin wit h t hree worksheet s. Most people plop t heir dat a on t he first one, which is init ially nam ed Sheet 1. I f you're an Excel expert , t hen you m ight have designat ed a sect ion of a m ore com plex worksheet as a nam ed range. I f so, you can pick t hat nam ed range from t he list . 3. Click N e x t . 4. I f you r Ex ce l da t a h a s a r ow w it h colu m n h e a din gs, t h e n ch oose Fir st Row Con t a in s Colu m n H e a din gs. These headings becom e t he st art ing point for your field nam es. I f you don't choose First Row Cont ains Colum n Headings, t hen Excel t reat s t he first row as an ordinary record. 5. Click N e x t . I f you're creat ing a new t able for your im port ed records, t hen Access asks you t o configure t he fields you're creat ing. I f you're appending t he records t o an exist ing t able, t hen skip ahead t o st ep 7. 6. For e a ch fie ld, you ca n ch oose a fie ld n a m e , t h e da t a t ype , a n d w h e t h e r or n ot t h e fie ld sh ou ld be in de x e d ( Se ct ion 4 .1 .3 ) . Th e n , click N e x t . Access m akes som e int elligent guesses based on t he dat a t hat 's t here, but it 's up t o you t o fine- t une t he det ails. For exam ple, if you have a colum n wit h whole num bers, you m ay want t o change t he dat a t ype from Double ( which support s fract ional num bers) t o I nt eger, as shown in Figure 19- 6.

Figu r e 19-5. This Excel workbook file has the standard three worksheets: file:///C|/html/0596527608/access2007tm-CHP-19-SECT-3.html (5 of 12) [1/7/2007 7:15:28 AM]

Section 19.3. Import and Export Operations

Sheet1, Sheet2, and Sheet3. When you make a selection, you see a preview of the data.

Figu r e 1 9 - 6 . To configure a field, select it in the preview, and then adjust the settings. If you decide you don't want to import a field at all, then you can choose "Do not import field" (circled) to ignore it altogether.

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-3.html (6 of 12) [1/7/2007 7:15:28 AM]

Section 19.3. Import and Export Operations

7. Ch oose w h e t h e r you w a n t Acce ss t o cr e a t e t h e pr im a r y k e y. Choose " Let Access add prim ary key" if you'd like Access t o creat e an aut onum bered I D field ( which is generally a good idea) . I f t he dat a you're im port ing already includes a field you want t o use as a key, t hen select " Choose m y own prim ary key" , and t hen pick t he right field. 8. I n t h e I m por t t o Ta ble t e x t box , t ype t h e n a m e of t h e t a ble you w a n t t o cr e a t e or a dd you r r e cor ds t o. 9. Click Fin ish t o fin a lize you r ch oice s. Once t he im port 's com plet e, you can choose whet her or not t o save your im port st eps for reuse. You'll find som e pot ent ial st um bling blocks when im port ing dat a from Excel. Blank values and fields, t he com m onest problem s, occur when t he I m port wizard assum es t here's dat a in a part of your worksheet t hat doesn't cont ain any inform at ion. ( This could happen if t here's a cell wit h j ust a space som ewhere on your worksheet , or even if you have a cell t hat used t o cont ain dat a but has since been delet ed.) Aft er you perform your im port , you m ay need t o clean up your t able t o fix problem s like t hese by delet ing em pt y fields and records.

19.3.4. Importing from a Text File Text files are t he lowest com m on denom inat or for dat a exchange. I f you're using a program t hat creat es files Access can't im port , t hen plain t ext m ay be your only avenue. Once again, you st art by choosing your file, and t hen choosing how you want t o add t he inform at ion t o your dat abase. Then, t he I m port wizard t akes you t hrough a few m ore st eps: 1. Spe cify t h e t ype of t e x t file . Access can im port from t wo t ypes of t ext files: ❍



D e lim it e d t e x t file s use som e sort of separat or t o indicat e where each field ends. For exam ple, Joe,Piscapone,43 is a line of t ext you m ay find in a delim it ed t ext fileit 's t hree field values separat ed by com m as. Fix e d- w idt h t e x t file s separat es a record int o separat e fields by posit ion. Each field has a cert ain num ber of charact ers allocat ed t o it , and if you don't use t hem all up, t hen Access fills t he rem aining space ( up unt il t he next field) wit h space charact ers.

Note: Delimited text files are commoner and more flexible than fixed-width text files (because they can accommodate data values of vastly different lengths). 2. Click N e x t . I f you're im port ing delim it ed t ext , Access asks you what charact er's t he delim it erin ot her words, what charact er separat es t he fields ( Figure 19- 7) . Com m as and t abs are com m on delim it ers. I f you're im port ing fixed- widt h t ext , Access let s you set t he field boundaries by dragging colum n lines t o t he right posit ion in t he preview window.

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-3.html (7 of 12) [1/7/2007 7:15:28 AM]

Section 19.3. Import and Export Operations

Figu r e 19-7. In this example, fields are separated using tabs.

3. Com ple t e t h e w iza r d. The rest of t he wizard unfolds in exact ly t he sam e way as it does for Excel dat a. I f you're creat ing a new t able t o hold your im port ed dat a, t hen t he next st ep asks you t o configure t he fields you want t o creat e by set t ing t heir nam es, dat a t ypes, and indexing opt ions ( Figure 19- 6) . Once you've finished t his part , you can choose whet her or not you want Access t o creat e an aut onum bered I D field, and t hen use it as t he prim ary key. Finally, in t he last st ep, you need t o ent er t he nam e of t he t able you want t o creat e or add t o. You can t hen click Finish ( and, opt ionally, choose t o save your im port st eps for lat er reuse) .

19.3.5. Exportable File Types Just as you can im port inform at ion from ot her files and pop it in your dat abase, you can also t ake t he exist ing inform at ion and ship it out t o anot her form at . You'll m ost oft en undert ake t his st ep t o let som e ot her person or program get t heir hands on your inform at ion wit hout needing t o go t hrough Access. When export ing your dat a, you can use all t he sam e form at s t hat you can use in an im port operat ion, plus a few m ore. Here's a rundown of t he m ost popular choices: ● ● ●



Acce ss. Transfers t he Access t able ( or a different t ype of obj ect ) t o anot her Access dat abase file. This feat ure isn't as powerful as im port ing Access obj ect s, because you're lim it ed t o one obj ect at a t im e. For t hat reason, people don't use it as oft en. Ex ce l. Put s t he dat a int o t he cells of an Excel worksheet . Perfect if you want t o use Excel's t ools t o analyze a sales t rend or plot a profit chart . W or d. Put s t he dat a int o a Word docum ent , separat ing each colum n wit h t abs and each line wit h a hard ret urn. This form at leaves a lot t o be desired, because it 's difficult t o rearrange t he dat a aft er t he fact in Word. ( A nicer export feat ure would put t he report dat a int o a Word t able, which would m ake it far easier t o work wit h.) PD F or XPS. Creat es a print - ready PDF file wit h t he exact form at t ing and layout you'd see if you sent t he t able t o your print er. Unlike Excel or Word docum ent s, you can't edit a PDF fileyou're lim it ed t o reviewing t he report and print ing it out .

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-3.html (8 of 12) [1/7/2007 7:15:28 AM]

Section 19.3. Import and Export Operations

Note: The PDF or XPS option appears only if you've installed a free add-in for Office. Section 10.2.3 describes how to get it. ● ●



H TM L D ocu m e n t . Creat es a web- ready HTML Web page t hat you can post t o a Web sit e or a com pany int ranet . The HTML form at t hat Access generat es looks rem arkably like your real, print ed report . Te x t File . Dum ps t he dat a int o a plain t ext file, wit h t abs and spaces used t o arrange t he dat a. You lose colors, font s, borders, and ot her form at t ing det ails. This form at isn't very usefult hink of it as a last resort t o t ransfer dat a t o anot her program if none of t he ot her export opt ions work. XM L File . Saves t he dat a in a t ext .xm l file, wit hout any form at t ing. This opt ion m akes sense if you're using som e sort of aut om at ed program t hat can read t he export ed XML file and process t he dat a. ( See Sect ion 19.4.3 for m ore inform at ion about XML and det ailed export st eps.)

19.3.6. Exporting Data To perform an export operat ion, follow t hese st eps: 1. I n t h e n a viga t ion pa n e , se le ct t h e t a ble you w a n t t o e x por t . Unfort unat ely, you can't export m ore t han one t able at once. However, you can export j ust a port ion of a t able. One way t o do t his part ial export is t o open t he t able, and t hen select t he rows you want t o export . ( Once you st art t he export process, you see an opt ion t hat let s you export j ust t he select ed rows.) You can also creat e a query t hat get s j ust t he rows you want . You can export t he query result s by select ing t he query in t he navigat ion pane inst ead of t he underlying t able. 2. Click t h e bu t t on t h a t cor r e spon ds t o t h e t ype of file you w a n t t o e x por t . When you choose a form at , Access launches t he Export wizard ( Figure 19- 8) .

Figu r e 19-8. The Export wizard varies depending on the export format you're using. But the first step's always to pick your file, and then set the export options shown here.

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-3.html (9 of 12) [1/7/2007 7:15:28 AM]

Section 19.3. Import and Export Operations

En t e r t h e n a m e of t h e file you w a n t t o cr e a t e . Access creat es t his file during t he export operat ion. I n som e cases, you m ay have a choice of file form at . For exam ple, if you're export ing t o Excel you can use t he newer XML- based spreadsheet form at ( t he .xlsx st andard) , or t he older .xls st andard t hat support s older versions, like Excel 97. 4. I f you w a n t t o k e e p t h e for m a t t in g t h a t 's in you r da t a ba se , t h e n ch oose " Ex por t da t a w it h for m a t t in g a n d la you t " . I f you've t ailored t he dat asheet wit h fancy font s and colors ( as described in Sect ion 3.1) , Access preserves t hese det ails in t he export ed file. Obviously, t his opt ion doesn't work for all form at s. For exam ple, sim ple t ext files can't handle any form at t ing. 5. I f you w a n t t o dou ble - ch e ck you r e x por t e d docu m e n t , t h e n ch oose " Ope n t h e de st in a t ion file a ft e r t h e e x por t ope r a t ion is com ple t e " . I t 's always a good idea t o m ake sure you got t he dat a and t he form at t ing you expect . I f you use t his opt ion, t hen Access launches t he export ed file, opening it in t he program t hat owns it ( Excel for spreadsheet s, Not epad for t ext files, and so on) . Of course, t his m et hod works only if you have t hat applicat ion on your com put er. 6. I f you 've se le ct e d on ly a fe w r e cor ds in a t a ble , t h e n ch oose " Ex por t on ly t h e se le ct e d r e cor ds" . This way, Access export s t he current select ion, not t he ent ire t able or query. 7. Click OK t o pe r for m t h e e x por t . Access m ay ask you for addit ional det ails, if it needs any m ore inform at ion about how t o creat e t he export ed file. Once you're finished t his st age, Access asks you it s final quest ionwhet her or not you want t o save your export st eps. 8. I f you w a n t t o pe r for m t h is im por t a ga in la t e r on , se le ct " Sa ve e x por t st e ps" . Th e n , click Close . The following sect ion explains how t o use a saved export .

GEM IN THE ROUGH Exporting Reports Tables and queries aren't t he only dat abase obj ect s you can export . Access also let s you export your report s. I f you choose t o keep t he form at t ing and layout , t hen Access t ries t o m ake sure t he export ed file looks j ust like t he print ed report . This choice is great if you want t o pass along a report t o som eone who doesn't have Access. I f you sim ply want t o share t he report dat a, t hen you can use Word. I f you want t o preserve t he form at t ing exact ly so t hat it can be print ed lat er on, t hen t he PDF form at m akes m ore sense. Sect ion 10.2.2 discusses how t o export a report in det ail. Access also let s you export a form , but you probably won't get t he result s you want . Access uses t he form at t ing and layout from t he Dat asheet view. Most form s use a carefully laid set of cont rols in Form view, and rarely use t he Dat asheet view. However, when Access export s a form , it ignores t he Form view alt oget her.

19.3.7. Reusing Import and Export Settings I n som e sit uat ions, you'll find you need t o perform regular im port or export operat ions. You m ay need t o dum p t he dat a from an Excel spreadsheet int o your dat abase once a week. Or m aybe you need t o produce a m ont hly PDF report wit h a sales sum m ary. I n t hese cases, it 's quit e t im e- consum ing t o go t hrough t he ent ire wizard. This is especially t rue if you're perform ing an im port , because you m ight need t o choose which colum ns you want t o im port , set t he appropriat e dat a t ypes, and t hen adj ust ot her set t ings t he exact sam e way you did t he first t im e you perform ed t he operat ion.

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-3.html (10 of 12) [1/7/2007 7:15:28 AM]

Section 19.3. Import and Export Operations

Fort unat ely, Access has a solut ion for t im es like t hese. You can save all t he set t ings you chose in t he I m port or Export wizard and st ore t hem in your current dat abase. Then, when you need t o repeat t he process, you can use t hese set t ings t o do it wit h j ust a couple of clicks ( wit h no brainpower needed) . To save your st eps, j ust t urn on t he " Save im port st eps" or " Save export st eps" checkbox at t he end of t he process t he first t im e you im port or export your dat a. You'll need t o choose a descript ive nam e for your set t ings, as shown in Figure 19- 9, and t hen click Save I m port .

Tip: If you're saving an import operation, think carefully about whether you choose to create a new table or append to an existing table (Section 19.3.3). If you create a new table, then every time you run the import, Access overwrites that table with a new table that has all new data. But if you append to an existing table, Access adds the new data to whatever data you've already got. (In this case, you need to be on the lookout for duplicate data; see the "The Danger of Duplicates" box in Section 19.3.3.)

Figu r e 19-9. Here, an import process is being saved for later use. You can fill in an optional description for this operation to help you remember what it's all about. And if you're using the popular Microsoft Outlook email program, then you can choose Create Outlook Task to create an automatic reminder that tells you when it's time to perform your

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-3.html (11 of 12) [1/7/2007 7:15:28 AM]

Section 19.3. Import and Export Operations

import or export.

At som e fut ure point , you can rerun your im port or export operat ion. I f you want t o repeat an im port , t hen choose Ext ernal I m port Saved I m port s. To repeat an export , choose Ext ernal Dat a I m port Saved Export s. Eit her Dat a way, you get t o t he Manage Dat a Tasks dialog box ( Figure 19- 10) , at eit her t he Saved I m port s or Saved Export s t ab. These t abs list s t he im port and export operat ions you've saved for t his dat abase. Here's what you can do in t he Manage Dat a Tasks dialog box: ● ● ●

Ru n t h e ope r a t ion a ga in . Select it in t he list , and t hen click Run. Access warns you if it needs t o overwrit e an exist ing t able ( in an im port ) or file ( in an export ) . Ot her t han t hat , t he whole process happens in a flash. D e le t e you r sa ve d ope r a t ion . Just select it , and t hen click Delet e. Cr e a t e a n Ou t look Ta sk for t h e ope r a t ion . You can use t his feat ure t o rem ind yourself t o perform t his operat ion at som e fut ure scheduled t im e ( or at regular int ervals) . To do so, click Creat e Out look Task t o creat e t he t ask, and t hen find and configure t hat t ask in Out look. When t he rem inder occurs, it includes a handy Run I m port but t on t hat you can click t o launch t he im port operat ion in Access right away.

Figu r e 191 0 . In this example, a single import operation has been saved. By clicking on the file name, you can change it to another file, but you'll have to type in the new path by hand.



Ch a n ge som e a spe ct s of you r ope r a t ion . You can m odify t he nam e, t he descript ion, and t he file nam e by clicking t he appropriat e det ail in t he Manage Dat a Tasks dialog box ( Figure 19- 10) . This way, you can st art out im port ing c: \ My Docum ent s\ FancyFiles\ WildExpenses.xlsx, but t hen use t he sam e set t ings t o im port d: \ HankSm it h\ EvenMoreExpenses.xlsx. You can't change any ot her det ails, like t he source or dest inat ion t able in Access, or t he field dat a t ypes.

When you're finished using t he Manage Dat a Tasks dialog box, click Close t o get back t o Access.

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-3.html (12 of 12) [1/7/2007 7:15:28 AM]

Section 19.4. Access and XML

19.4. Access and XML One of t he hot t est buzzwords in t he com put er world is XML ( t he ext ensible m arkup language) , an all- purpose way of exchanging inform at ion bet ween different program s. Access 2007 support s XML wit h it s im port and export feat ures, where XML shows up as j ust one m ore support ed form at . However, if you really want t o underst and how t he Access XML feat ures workand whet her or not t hey really add anyt hing newyou need t o dig a lit t le deeper.

19.4.1. What Is XML, Really? XML alone sounds pret t y m odest . People oft en describe it as a form at for st oring inform at ion. For exam ple, inst ead of saving dat a in Word docum ent s, Excel spreadsheet s, or ordinary t ext files, you can save dat a in an XML file. This sim plicit y's deceiving, and t wo fact ors m ake XML really special: ● ●

XM L is fle x ible . You can t ailor XML t o st ore pret t y m uch any t ype of inform at ion: pict ures, product cat alogs, invoice dat a, receipt s, cat alog list ings, t he m aint enance specs for every Dodge Minivan ever built , and on and on. XM L is w ide spr e a d. Com put er applicat ions writ t en in different program m ing languages ( like Java, Visual Basic, or C+ + ) , or running on different operat ing syst em s and com put er hardware ( like Windows, Mac, or Linux) , can all use XML in exact ly t he sam e way. That qualit y m akes XML a perfect solut ion for exchanging inform at ion bet ween people, com panies, and even com put ers t hat have been program m ed t o send dat a t o one anot her aut om at ically ( it 's feat ures like t his last one t hat cause supply- chain m anagem ent t ypes t o st art drooling when t hey t alk about XML) .

Cont rary t o what m any people believe, XML is not a dat a form at ( like HTML, t he form at used t o creat e Web pages) . I f XML were an ordinary dat a form at , it wouldn't be nearly as useful because, no m at t er how good a form at is, it can't suit everyone. For exam ple, even t hough alm ost every com pany needs t o creat e invoices, m ost com panies wouldn't be happy wit h a generic form at for st oring invoice inform at ion. One com pany m ay need t o t rack cust om er nam es, while anot her m ight t rack cust om er I D num bers. The bot t om line is t hat m ost com panies need t o st ore slight ly different dat a in slight ly different ways. That m eans a one- size- fit s- all solut ion is pret t y m uch always doom ed t o failure. So if XML isn't a dat a form at , what is it ? Technically, XML is a m et a- language, which is a fancy way of saying t hat XML is a language for creat ing ot her languages. XML does t his creat ing by set t ing out a few sim ple rules t hat let you build your own dat a form at t hat 's j ust right for your dat a. For exam ple, Acm e Com pany can build an XML form at for invoices, and call it Acm eI nvoice. Meanwhile, Budget Com pany can build it s own XML invoice form at and call it Budget I nvoice. Even t hough bot h t hese form at s are designed t o st ore invoice inform at ion, t hey can cont ain com plet ely different kinds of dat a. XML's flexibilit y is it s st rengt h. At t he sam e t im e, XML's flexibilit y can creat e problem s. Suppose a bank nam ed Worldwide Green set s up a syst em t o aut om at ically process XML invoices in a specific form at . The syst em works sm oot hly unt il Acm e Corporat ion sends along it s own hom egrown invoice. Even t hough Acm e's invoice uses XML, it doesn't conform t o t he XML t hat t he bank expect s, and so it gum s up t he bank's aut om at ed invoice- processing applicat ion. Suddenly, XML doesn't look so useful. The bot t om line is: XML holds t he prom ise of universal dat a sharingbut if you don't creat e som e rules and follow t hem , t hen you're left wit h a bunch of incom pat ible form at s.

Note: XML is really quite simple. However, there are a slew of other standards with names like XML Schema and XSLT that work in conjunction with XML and provide solutions for validating XML, searching XML, transforming XML, and so on. These other standards are quite complex and aren't discussed in this book. For more information, refer to a book like Learning XML by Erik Ray (O'Reilly), or the Web site www.w3schools.com/ xml.

19.4.2. Three Rules of XML To get a bet t er underst anding of how t o configure Access t o handle XML, look at a sim ple exam ple. Technically, you don't need t o know what XML looks like in order t o use t he XML feat ures in Access, but t he m ore you underst and, t he less confusing life will be. I n t his sect ion, you'll learn t he t hree m ost im port ant rules t hat shape all XML docum ent s. I f you already know a lit t le about XML,

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-4.html (1 of 10) [1/7/2007 7:15:37 AM]

Section 19.4. Access and XML

feel free t o skip ahead. By t he way, good news before you even st art : XML is writ t en in a t ext - based, hum an- readable form at . So you can use a program like Not epad t o crack open an exist ing XML file, and get a basic idea of it s form at and st ruct ure. You can even writ e an XML file from scrat ch using Not epad. You can't do t he sam e wit h t he average Access dat abase, because it 's st ored in a binary form at t hat you can read only when you're looking at t he dat a in Access. ( I f you t ry t o open a dat abase in Not epad, you'll see a j um ble of indecipherable sym bols.)

19.4.2.1. The prolog All respect able XML docum ent s st art wit h som et hing called a docum ent prolog. This bit sim ply announces t hat what you're looking at is an XML docum ent . I t can also indicat e t he encoding of t he docum ent , which som et im es specifies t hat t he docum ent uses a special charact er set ( like a non- English alphabet ) . Here's a t ypical docum ent prolog, indicat ing t hat t his docum ent uses Version 1.0 of t he XML st andard ( t he m ost prevalent version) :

I f you're creat ing an XML docum ent by hand, t hen you should m ake sure you place t he docum ent prolog as t he very first line of t he file.

19.4.2.2. Elements The basic building block of any XML docum ent is t he elem ent . Elem ent s are inform at ion cont ainers. For exam ple, if you want ed t o st ore a person's nam e, you could creat e an elem ent called Nam e. ( For m ore on t he infinit e variet y of elem ent s t hat anyone can creat e, see t he box in Sect ion 19.4.2.3.) A t ypical elem ent 's com posed of a st art t ag and an end t ag. The act ual inform at ion goes bet ween t hese t wo t ags. You can easily recognize st art t ags and end t ags because t hey use angle bracket s < > . Here's one possible st art t ag:

This t ag m arks t he st art of t he Nam e elem ent . The end t ag looks alm ost ident ical, except it begins wit h t he charact ers < / inst ead of j ust < . Here's what you need t o end t he Nam e elem ent :

To act ually st ore som e inform at ion in an XML docum ent , you j ust insert t he cont ent bet ween t he st art and end t ag of an elem ent . Here's how you m ight st ore som eone's nam e in an XML docum ent : Patrick

You could creat e a list of nam es by put t ing one < Nam e> elem ent aft er t he ot her, or you could add ot her elem ent s t hat st ore different t ypes of inform at ion, like address, t it le, em ployer, and so on. You put all t hese t ags t oget her in a file t o m ake an XML docum ent .

UP TO SPEED A Closer Look at Tags

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-4.html (2 of 10) [1/7/2007 7:15:37 AM]

Section 19.4. Access and XML

Tags follow fairly st rict nam ing rules. Tags can be of any lengt h, are case- sensit ive, include any alphanum eric charact er and hyphens ( - ) , underscores ( _) , and periods ( .) . You can't use ot her special charact ers, including spaces, and t he t ag nam e m ust st art wit h an underscore or let t er. XML docum ent s also support charact ers from non- English alphabet s. The m ost im port ant t hing you should underst and about t ags is t hat it 's up t o you t o creat e t hem . I f you decide t hat you need t o st ore a list of nam es, you m ay creat e an XML form at t hat uses a < Nam e> t ag. Meanwhile, som eone else m ay decide t o t rack nam e inform at ion by creat ing anot her XML form at t hat uses elem ent s like < first Nam e> and < last - Nam e> . These t wo elem ent s m ay st ore t he sam e t ype of inform at ion as your < Nam e> elem ent , but t hey're different , and a docum ent writ t en wit h t he < first Nam e> and < last - Nam e> t ags isn't com pat ible wit h your docum ent s. Since t here are so m any possible XML form at s, a lot of int elligent people have invest ed a lot of t im e and energy in t rying t o creat e ways t o define and m anage different XML form at s. Also, com panies and organizat ions have com e t oget her t o define specific XML st andards for different indust ries. I f you search on t he I nt ernet , you'll find predefined XML form at s for law, science, real est at e, and m uch m ore.

19.4.2.3. Nesting So far, you've seen exam ples of XML elem ent s t hat cont ain t ext . You can also creat e an elem ent t hat cont ains one or m ore addit ional elem ent s. This is a basic principle for organizing inform at ion in XML. Suppose you want t o keep t rack of several people's nam es and ages. The following form at isn't especially clear because it 's hard t o t ell which person connect s t o which age: Lisa Chen 19 Bill Harrison 48

A bet t er solut ion is t o group t he < Nam e> and < Age> elem ent s t oget her for each person, and put t hem inside anot her elem ent . Here's an exam ple:

Lisa Chen 19

Bill Harrison 48

Here, t he t wo < Person> elem ent s each represent a dist inct individual. I nform at ion about each person's st ored in < Nam e> and < Age> elem ent s t hat are nest ed inside t he appropriat e < Person> elem ent . There's no lim it t o how m any layers deep you can nest inform at ion, m aking t his m et hod of organizing inform at ion ext rem ely flexible. I n fact , it 's part of t he reason t hat XML can work wit h so m any different t ypes of dat a. XML im poses one m ore rule. Every docum ent m ust st art wit h a single elem ent t hat you place right aft er t he docum ent prolog. You place all t he ot her cont ent inside t his elem ent , which is called t he root or docum ent elem ent . So far, t he exam ples you've seen are only excerpt s of XML. The following list ing shows a com plet e, valid XML docum ent a list wit h inform at ion about t wo peoplet hat st art s off wit h t he docum ent elem ent < PeopleList > :



file:///C|/html/0596527608/access2007tm-CHP-19-SECT-4.html (3 of 10) [1/7/2007 7:15:37 AM]

Section 19.4. Access and XML

Lisa Chen 19

Bill Harrison 48

You could enhance t his docum ent by adding m ore < Person> elem ent s or different elem ent s t o t rack addit ional inform at ion about each person. You've probably not iced t hat t hese XML exam ples indent each level of elem ent s. That indent at ion m akes t he overall st ruct ure easier t o read, but it 's not required. I n fact , applicat ions t hat read XML ( including Access) ignore all t he whit e space bet ween elem ent s, so it doesn't m at t er if you add spaces, t abs, and blank lines. I n fact , as far as com put ers are concerned, t he docum ent above is exact ly t he sam e as t he following, m uch less hum an- friendly version:

Lisa Chen19Bill Harrison48

19.4.3. XML Files and Schemas As you've already learned, a file's one place you can st ore XML docum ent s. But you can j ust as easily place XML docum ent s in dat abases or ot her st orage locat ions. I n fact , som et im es XML dat a isn't st ored anywhereinst ead, people j ust use it t o send inform at ion bet ween applicat ions over t he I nt ernet . However, when you use XML wit h Access, you're always using XML files ( unless your com pany has creat ed a cust om solut ion using t he heavy- dut y program m ing feat ures in Access) . Most XML files have t he ext ension .xm l. For exam ple, it m akes perfect sense t o t ake t he person list docum ent shown earlier and place it in a t ext file nam ed PersonList .xm l. Anot her t ype of XML docum ent 's ext rem ely im port ant : XML schem as. Schem as are designed t o solve a com m on problem nam ely, defining t he rules for a specific XML- based form at . For exam ple, a schem a indicat es t he elem ent nam es you can use, how you can arrange t he elem ent s, and t he t ype of inform at ion each elem ent can cont ain. An XML- friendly applicat ion can use t he schem a t o verify t hat an XML docum ent uses t he right st ruct ure and cont ains t he appropriat e cont ent . I n an ideal world, every t im e a com pany creat ed an XML form at , t hey'd writ e an XML schem a t hat defines it . ( You probably won't be surprised t o learn t his doesn't always happen.) I n order t o use a schem a, you sim ply need t o have a copy of it in a file. ( Schem as t hem selves are com plex and ugly and beyond t he scope of what a t ypical office needsor want st o learn.) Usually, schem a files have t he ext ension .xsd.

Note: For a more comprehensive beginner's introduction to XML and XML schemas, check out the excellent online tutorial provided by W3 Schools at www.w3schools.com/xml.

19.4.4. The Access XML Story XML is a great way t o exchange dat a bet ween different com put er program s. But what does t hat have t o do wit h Access, which already has it s own perfect ly good way of st oring dat a? Here's t he deal: More and m ore com panies t oday use XML t o pass dat a back and fort h. When com panies exchange business orders, for inst ance, or news organizat ions post st ories, or real est at e firm s list propert ies for sale, chances are t hey're using an XML- based form at . I f you want t o send your Access dat a t o t hese syst em s, t hen you need a way t o t ake it out of t he specialized .accdb dat abase form at , and put it in clear- as- a- bell XML. Unfort unat ely, t he XML support in Access is st ill quit e lim it ed. The problem 's t hat Access doesn't let you pick t he XML form at you want . I nst ead, it creat es a cust om form at t hat closely m at ches your t able. Consider t he t able in Figure 19- 11. ( When export ing

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-4.html (4 of 10) [1/7/2007 7:15:37 AM]

Section 19.4. Access and XML

XML, you always export a com plet e t able.)

Figu r e 1911. Some sample data, ready for a new life in XML format.

When you export t his t able, Access creat es an XML docum ent t hat looks like t his:

371 Thin-Jam Hex Nut 7 HJ-7161 1000 750

372 Thin-Jam Hex Nut 8 HJ-7162 1000 750



No m at t er what t able you export , Access always follows t he sam e rules: ● ● ●

The docum ent 's root elem ent is nam ed < dat aroot > . Access creat es a separat e elem ent for each row in t he t able, using t he t able nam e. I n t his exam ple, t hat syst em m eans you end up wit h one < Product > elem ent for each record. I nside each record, Access creat es a separat e elem ent for each field. I n t his exam ple, you end up wit h fields like < Nam e> , < Product Num ber> , and so on.

There's not hing part icularly wrong wit h st ruct uring XML in t his way. However, since you can't change t he st ruct ure, you'll run int o t rouble if you want t o use anot her program t hat expect s XML in a different form at . For exam ple, your program m ay expect t he root elem ent t o be nam ed < Product Records> inst ead of < dat aroot > , or it m ay assum e a slight ly different nest ing. Minor quibbles like t hese can com plet ely derail an XML- processing applicat ion. Sadly, t here's no way around t his problem . I n order t o use Access XML, you m ust specifically design a program t hat recognizes t his st ruct ure, or you m ust use anot her t ool t o convert t he XML t o t he st andard you really want . Access's XML export feat ure's enough t o get you st art ed, but it doesn't t ake your dat a all t he way.

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-4.html (5 of 10) [1/7/2007 7:15:37 AM]

Section 19.4. Access and XML

Note: If all you need to do is filter out records or fields that don't interest you, or give fields different names, then you can solve the problem with a query. Just create a query that presents the information the way you want it, and then export its results (rather than the whole table).

The sam e lim it at ions appear when you im port XML cont ent . Access expect s t o find XML cont ent in t he rigid t able- like form at it expect s. I f you t ry t o feed it a different t ype of XML, t hen you get an error.

19.4.5. Exporting to an XML File Now t hat you've learned about XML and considered it s lim it at ions in Access, you're ready t o t ry it out for yourself. The following st eps lead you t hrough t he process: 1. Ch oose Ex t e r n a l D a t a

Ex por t

M or e

XM L File .

The fam iliar export process begins. 2. Su pply t h e n a m e of t h e file you w a n t t o cr e a t e , a n d t h e n click OK. Access suggest s you use t he t able nam e. For exam ple, if you're export ing t he Orders t able, it recom m ends an XML file nam ed Orders.xm l. 3. Ch oose w h a t file t ype s you w a n t t o cr e a t e ( Figu r e 1 9 - 1 2 ) :

❍ ❍



D a t a ( XM L) creat es t he XML file t hat has t he act ual cont ent from all records in your t able. Sch e m a ( XSD ) creat es a .xsd schem a file. The schem a doesn't cont ain any dat a, but it st ores a concise definit ion t hat describes your t able and t he fields it cont ains. The schem a has t wo purposesyou can pass it along t o expert program m ers so t hey know what t ype of XML t o expect from Access, or you can use it t o creat e a new, em pt y t able in anot her Access dat abase ( see Sect ion 19.4.6) . Pr e se n t a t ion ( XSL) creat es a .xsl t ransform file. This file defines how a browser can convert t he raw dat a in t he XML file int o an HTML Web page suit able for display in a browser. When you choose t his opt ion, Access also creat es an .ht m file t hat uses t he .xsl file. For exam ple, if you're export ing t he Product s t able, you wind up wit h a Product s.ht m Web pageopen t his in your browser, and it uses t he Product s.xsl file t o display t he dat a in Product s. xm l.

Figu r e 1 9 - 1 2 . Usually, you'll want to create the XML file that stores the actual data from your table. In addition, you can create two more support files.

4.

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-4.html (6 of 10) [1/7/2007 7:15:37 AM]

Section 19.4. Access and XML

I f you w a n t t o e x por t r e la t e d t a ble s in t h e sa m e XM L docu m e n t , t h e n click M or e Opt ion s. An Export XML window wit h addit ional opt ions appears. Most of t hese opt ions are best left for XML gurus. However, t he Dat a t ab's m ore int erest ingit let s you export relat ed t ables ( Figure 19- 13) .

Figu r e 19-13. The Data tab shows a tree that starts with the table you're exporting, and branches out to other related tables. If you want to include the data from these related tables, simply add a checkmark next to each one.

For exam ple, if you're export ing t he Orders t able, you have t wo opt ions: ❍



Ex por t ot h e r ch ild t a ble s. You could also export t he OrderDet ails records for each order. Access nest s t he OrderDet ails elem ent s inside t he corresponding Orders elem ent in t he XML. Ex por t t h e r e la t e d r e cor ds fr om a pa r e n t t a ble . You could, for inst ance, also export records from t he OrderSt at us and Credit Cards t ables. These records appear under t he heading [ Lookup Dat a] because t hey provide m ore dat a t hat 's linked t o an order ( in t his case, t he current st at us of t he order, and t he credit card used t o pay for an order) .

Note: When you export parent tables, the records aren't nested in the XML, because that could lead to duplication (for example, if more than one order has the same status or uses the same credit card). Instead, they're added after the main table you're exporting. 5.

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-4.html (7 of 10) [1/7/2007 7:15:37 AM]

Section 19.4. Access and XML

Click OK. Access creat es t he files you chose in st ep 3. 6. I f you w a n t t o r e pe a t t h e e x por t pr oce ss a n ot h e r t im e , t h e n ch oose " Sa ve e x por t st e ps." Click Close t o ret urn t o Access.

19.4.6. Importing from an XML File Access m akes it j ust as easy t o im port XML dat a, provided it 's in t he st ruct ure Access expect s. To t ry it out , t ake t he t able you j ust export ed, and t hen reim port it int o a new dat abase. Here's how t o do it : 1. Ch oose Ex t e r n a l D a t a

I m por t

XM L File .

The fam iliar im port process begins. 2. I f you 'r e cr e a t in g a n e w t a ble a n d you h a ve a sch e m a for you r da t a , t h e n su pply t h e sch e m a file 's n a m e . I f you a lr e a dy h a ve t h e t a ble s t h a t you w a n t t o u se , or you don 't h a ve a sch e m a h a n dy, t h e n j u m p st r a igh t t o st e p 6 . You can im port st raight from t he XML file, but it 's always bet t er t o use t he schem a if you need t o creat e t he t able for t he first t im e, because t he schem a st ores inform at ion about each field's dat a t ypes. This inform at ion ensures t hat t he t able you creat e is a closer m at ch t o t he original t able you export ed. 3. Click OK. Access scans t he schem a, and displays t he st ruct ure of t he t ables it 'll creat e ( Figure 19- 14) .

Figu r e 1 9 - 1 4 . In this example, Access correctly identifies that your schema file defines the structure for file:///C|/html/0596527608/access2007tm-CHP-19-SECT-4.html (8 of 10) [1/7/2007 7:15:37 AM]

Section 19.4. Access and XML

the Orders, OrderDetails, OrderStatus, and CreditCards tables. You can expand each table to see what fields it contains.

4. Click OK. Using t he schem a inform at ion, Access creat es a new, blank t able wit h t he correct st ruct ure. Now you're ready t o fill it wit h dat a.

Note: If a table already exists with the same name, Access adds a number to the end to distinguish it (such as Products1, Products2, and so on). 5. Click Close t o r e t u r n t o Acce ss. 6. Ch oose Ex t e r n a l D a t a

I m por t

XM L File .

Now t hat you've creat ed your t ables, you're ready t o im port t he act ual dat a. 7. Su pply t h e n a m e of t h e XM L file t h a t h a s t h e da t a you w a n t t o im por t , a n d t h e n click OK. Access shows t he st ruct ure of t he t able, based of t he XML dat a in your file. This st ruct ure should exact ly m at ch t he st ruct ure of t he t able you want t o creat e or add t o. 8. Ch oose on e of t h e t h r e e im por t opt ion s: ❍

Appe n d D a t a t o Ex ist in g Ta ble ( s) t ells Access t o find t he t able wit h t he sam e nam e, and t hen add all t he dat a t o t his t able. Use t his opt ion if t he t able you're using already exist s.

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-4.html (9 of 10) [1/7/2007 7:15:37 AM]

Section 19.4. Access and XML ❍ ❍

St r u ct u r e a n d D a t a creat es t he t able, and t hen fills it wit h all t he dat a. St r u ct u r e On ly creat es t he t able if it doesn't already exist , but doesn't im port any dat a.

Note: If you need to create a new table as part of your import process, it's always best to use the schema file to create the table (as described in steps 1 to 5), because the schema file has more precise information about data types. 9. Click OK. Access fills t he t ables wit h dat a from your XML file. I f you want t o repeat t he export process anot her t im e, t hen choose " Save export st eps" .

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-4.html (10 of 10) [1/7/2007 7:15:37 AM]

Section 19.5. Collecting Info by Email

19.5. Collecting Info by Email There are m any m ore dedicat ed em ail users t han dat abase m avens in t he world. So it would be pret t y nift y t o have a way t o get dat a from ot her people by j ust having t hem send you an em ail. The designers who work on Access t hink so t oo. They've added one ot her way t o pull dat a int o Access from ot her sources: You can collect it by em ail. Here's how it works: ● ● ●

● ●

You pick a t able t hat needs inform at ion. You pick a bunch of people who can provide t hat inform at ion. ( You need a list of em ail addresses, which you can eit her t ype in by hand or pull out of a t able in your dat abase.) Access sends an em ail m essage t o all of t hem wit h a form t hey can fill out . The form let s t hem fill in t he dat a for one record's wort h of inform at ion ( alt hough a recipient can fill out t he sam e form m ult iple t im es if necessary) . To see a quick preview of what t his em ail m essage m ight look like, j um p ahead t o Figure 19- 19. The result s of t hat form get em ailed back t o you. For each em ail you receive, Access insert s a record in your t able.

Oft en, t his collect - by- em ail feat ure is used t o get inform at ion about people. For exam ple, you m ay have a t able t hat has a list of cont act s. You can send each person an em ail m essage and get t hem t o supply t heir personal inform at ion ( address, phone num ber, and so on) . Of course, you can also use t he feat ure t o collect ot her t ypes of inform at ion, like a list of it em s people want t o bring t o t he com pany pot luck. The collect - by- em ail feat ure has a few ground rules: ●



● ●

You n e e d t o u se M icr osoft Ou t look 2 0 0 7 ( t h e e m a il soft w a r e t h a t 's in clu de d w it h Office 2 0 0 7 ) t o se n d you r m e ssa ge a n d r e ce ive t h e r e spon se s. So if you haven't configured Out look yet wit h your em ail det ails, t hen you should do t hat before you go any furt her. Your recipient s can use what ever kind of em ail program t hey want . You ca n on ly in se r t in for m a t ion , n ot u pda t e it . ( There's one except ion. You can updat e a t able if each record has t he recipient 's em ail address in a field, because Access can figure out which record t o updat e by m at ching t he em ail address of t he responder t o t he em ail address in t he t able.) I f pe ople fill in t h e w r on g da t a ( for e x a m ple , pu t t in g t e x t in a n u m e r ic fie ld) , Acce ss ca n 't cr e a t e t h e r e cor d. I t 's t hen up t o you t o figure out what went wrong, and correct t he problem . You 'll pr oba bly n e e d t o spe n d som e t im e r e vie w in g t h e da t a ot h e r pe ople h a ve su bm it t e d. People are not oriously careless when filling out form s on a com put er. They m ay t ype t heir nam es com plet ely in lowercase let t ers, leave out im port ant inform at ion, m ake spelling m ist akes or off- color j okes, and so on.

I n t he following sect ions you'll see how t o creat e t he em ail m essage you need, and t hen get t he dat a int o your t able.

19.5.1. Creating an Email Message The first st ep ( assum ing you've already inst alled Out look and configured your em ail account in it ) is t o ident ify t he t able where you want t o insert dat a. I n t he following exam ple, you'll see how t o add prospect ive candidat es t o Dat ing Service dat abase's Bachelors t able. I f you want t o t ry t his out wit h your friends, you can find t he Dat ing Service dat abase on t he " Missing CD" page at www.m issingm anuals.com . Here's how t o do it : 1. Ch oose Ex t e r n a l D a t a

Colle ct D a t a

Cr e a t e E- m a il.

A wizard appears. The first st ep list s all t he st eps you need t o go t hrough t o get your dat a. 2. Click N e x t t o m ove on . The second st ep let s you pick t he t ype of form you want t o use. 3. Ch oose " H TM L for m " , a n d t h e n click N e x t . This choice t ells Access t o use HTML t ags in it s em ail m essage. Using t hese t ags, Access can creat e a form wit h at t ract ive form at t ing and t ext boxes where t he recipient can t ype in inform at ion.

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-5.html (1 of 10) [1/7/2007 7:15:45 AM]

Section 19.5. Collecting Info by Email

The only ot her opt ion ( Microsoft Office I nfoPat h form ) is t urned off unless you have t he I nfoPat h applicat ion inst alled on your com put er. I nfoPat h is only included in cert ain edit ions of Office, and it 's m ost com m only used by big com panies. Alt hough it 's a great program for filling out form s, it has one serious drawbackin order t o use an I nfoPat h form , all your recipient s need t o have t he I nfoPat h soft ware inst alled on t heir com put ers. For t hat reason, t he HTML opt ion's usually bet t er. 4. Th e n e x t st e p a sk s w h e t h e r you w a n t t o colle ct n e w in for m a t ion or u pda t e e x ist in g in for m a t ion . Ch oose a n opt ion , a n d t h e n click N e x t . Usually, you'll choose " Collect new inform at ion only" . This opt ion's t he one t o use in t he Dat ing Service dat abase, because you want t o get t he inform at ion t hat you need t o insert a record in t he Bachelors t able for each recipient . I f you choose " Updat e exist ing inform at ion" , your t able m ust include t he recipient 's em ail addresses. For exam ple, you can use t his approach if you have a set of records in t he Bachelors t able t hat you want t o updat e. Each bachelor will receive an em ail t hat t hey can use t o change t heir current det ails.

Tip: You can also use the update option if you have the email addresses in another table that's related to the table you want to fill. For example, you could update a Projects table with the current status of every project if it includes a ProjectManagerID field that points to a record in a ProjectManagers table, which in turn contains the email address. 5. Pick t h e fie lds you w a n t t o colle ct ( Figu r e 1 9 - 1 5 ) . To add a field, select it in t he " Fields in t able" list , and t hen click t he > but t on. Or, click t he > > but t on t o t ransfer all t he fields in one go.

Figu r e 1 9 1 5 . You can collect as few or as many fields as you want. But Access forces you to include all the table's required fields, which appear with an asterisk (*) in front of them. (In this example, that's FirstName, LastName, and PhoneNumber.)

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-5.html (2 of 10) [1/7/2007 7:15:45 AM]

Section 19.5. Collecting Info by Email

Note: You don't see your ID AutoNumber field in the "Fields in table" list. Access knows it needs to generate that number itself, so it doesn't bother asking anyone to supply a value. You also don't see multivalue fields or attachment fields, because Access can't create forms for these types of data. 6. Opt ion a lly, pr ovide cle a r e r n a m e s for you r fie lds. For exam ple, t he label " Your favorit e food is" m ight be clearer t han t he field nam e FoodPreference. To change a label, select it in t he list , and t hen change t he t ext box t hat appears underneat h. You can also t urn on t he Read- only checkbox so t hat people can't change a field value. This opt ion m akes sense only if you're get t ing people t o updat e records. I n t his sit uat ion, t here m ight be som e inform at ion you want t hem t o see in t he form but not change. 7. Opt ion a lly, r e a r r a n ge t h e or de r of you r fie lds. To m ove a field, select it in t he list of included fields, and t hen use t he up or down arrow but t ons. When Access creat es t he em ail form , it put s t he fields in t he sam e order. 8. Click N e x t . The final st ep appears ( Figure 19- 16) .

Figu r e 19-16. Figure 1916: In the next step, you pick the location where Access stores the replies, and you choose whether they'll be processed automatically.

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-5.html (3 of 10) [1/7/2007 7:15:45 AM]

Section 19.5. Collecting Info by Email

9. Ch oose t h e folde r w h e r e Acce ss st or e s t h e r e ply m e ssa ge s on ce it 's pr oce sse d t h e m . Ordinarily, Access st ores replies in an Out look folder nam ed Access Dat a Collect ion Replies. However, you can use any folder you want . To change t he folder, click t he Access Dat a Collect ion Replies link. Out look launches, and shows you a Select Folder dialog box where you can pick any exist ing folder ( or click New t o creat e a new one.) Once you've picked t he folder you want , click OK.

Tip: If you plan to perform more than one import operation for different tables, it makes sense to use different folders. 10. I f you w a n t t o u se a u t om a t ic pr oce ssin g, t h e n t u r n on t h e " Au t om a t ica lly pr oce ss r e plie s" ch e ck box . I f you w a n t t o u se m a n u a l pr oce ssin g, t h e n sk ip t o st e p 1 2 . I f you use aut om at ic processing, t hen Out look com m unicat es wit h Access whenever it receives a reply. Access t hen adds or updat es t he corresponding record right away. This syst em works as long as your dat abase file rem ains in t he sam e locat ion, has t he sam e nam e, and isn't password- prot ect ed. Manual processing's m ore work, but it 's act ually a safer choice. That way, you can review every reply before you add t he record. You also know exact ly how m any replies you've received, and you can check for errors before t he dat a get s int o your t able. For t hese reasons, m anual processing's t he best bet . 11. I f you 'r e u sin g a u t om a t ic pr oce ssin g, t h e n click t h e " Se t pr ope r t ie s t o con t r ol t h e a u t om a t ic pr oce ssin g of r e plie s" lin k t o sh ow t h e Colle ct in g D a t a Usin g E- m a il Opt ion s dia log box ( Figu r e 1 9 - 1 7 ) . Ch oose t h e se t t in gs you w a n t , a n d t h e n click OK.

Figu r e 1 9 - 1 7 . If you choose to process replies automatically, then you can control a number of settings in this dialog box.

You can cont rol t he following set t ings: ❍





D isca r d r e plie s for t h ose t o w h om you did n ot se n d t h e m e ssa ge let s you ignore m essages if t hey're sent from people t hat you didn't em ail. Acce pt m u lt iple r e plie s fr om e a ch r e cipie n t le t s r e cipie n t s respond as m any t im es as t hey want . Each t im e Access receives a m essage, it adds a record t o t he t able. This m akes sense if, say, you're collect ing a list of it em s your friends want t o sell at a group garage sale. I t doesn't m ake sense if you're com piling t he personal inform at ion of a bunch of bachelors, because each person get s j ust one record. Allow m u lt iple r ow s pe r r e ply works only if you're using I nfoPat h. Wit h I nfoPat h, you can fill in t he inform at ion for m ore t han one record in t he sam e form ( if t his set t ing's swit ched on) .

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-5.html (4 of 10) [1/7/2007 7:15:45 AM]

Section 19.5. Collecting Info by Email







On ly a llow u pda t e s t o e x ist in g da t a works only if you're perform ing an updat e ( see st ep 4) . I f you are, t hen you can use t his set t ing t o prevent people from adding new records. Again, t his set t ing's an I nfoPat h- only opt ion. N u m be r of r e plie s t o be pr oce sse d let s you st op processing aft er you reach a cert ain num ber of replies. From t hat point on, Access ignores all replies ( unless you choose t o process t hem m anually, as described in Sect ion 19.5.2) . D a t e a n d t im e t o st op let s you halt processing on a cert ain dat e and t im e. Replies t hat com e in lat e are ignored, alt hough you can process t hem m anually.

12. Click N e x t . The next screen asks how you want t o supply em ail addresses. 13. Ch oose a n e m a il opt ion , a n d t h e n click N e x t . Choose " Ent er t he em ail addresses in Microsoft Office Out look" if you want t o t ype in t he em ail addresses for your recipient s ( or pick t hem from your Out look address book) . Then skip t o st ep 15. Choose " Use t he em ail addresses st ored in a field in t he dat abase" if you want t o pull t he em ail addresses out of a t able. I f you're perform ing a t able updat e, t hen you don't see t his st ep. You always need t o get em ail addresses out of a t able. 14. I f you 'r e su pplyin g e m a il a ddr e sse s fr om a t a ble , t h e n you n e e d t o t e ll Acce ss w h a t t a ble a n d fie ld t o u se . Th e n click N e x t t o con t in u e . You can pull em ail addresses out of a current t able ( if you're perform ing record updat es) or anot her linked t able ( which works if you're perform ing record insert s or updat es) . I f you're updat ing t he inform at ion in t he Bachelors t able, you could use t he Em ail field in t hat t able. Or, if you're creat ing a list of proj ect s, each of which is linked t o a proj ect m anager record, you can pull em ail addresses out of t he Proj ect Managers t able, and let people creat e relat ed records in t he Proj ect s t able. 15. Fin e - t u n e t h e e m a il m e ssa ge t h a t you 'r e se n din g, a n d t h e n click N e x t . You can m odify t he t ext in t he subj ect line and int roduct ion ( Figure 19- 18) . 16. You 've r e a ch e d t h e fin a l st e p. Click Cr e a t e t o fir e u p Ou t look , a n d ge t r e a dy t o se n d you r m e ssa ge . When you click " Creat e" , Access creat es t he form and loads it up in a new m essage t hat 's j ust it ching t o be sent ( Figure 19- 19) . I f you chose t o pull em ail addresses out of a t able, t hen you see t hose addresses appear in t he To, Cc, or Bcc lines. Ot herwise, t he To line's em pt y and it 's up t o you t o fill in t he right addresses. ( Add as m any as you want , separat ed by sem icolons.) I f you're an Out look whiz, feel free t o t hrow a m ailing list int o t he m ix. You can also perform any last m inut e edit s t o your m essage. 17. On ce you h a ve t h e cor r e ct r e cipie n t e m a il a ddr e sse s, click Se n d t o se n d t h e m e ssa ge on it s w a y. That 's it . Your work's done ( unt il som eone get s t he m essage and fires back a response) .

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-5.html (5 of 10) [1/7/2007 7:15:45 AM]

Section 19.5. Collecting Info by Email

Figu r e 19-18. This example shows the standard subject line and text that Access fills in. You can add something that's more meaningful to your recipients.

To fill out a reply, t he recipient sim ply needs t o click Reply, t ype t he values in all t he t ext boxes, and t hen click Send t o send t he com plet ed form back t o you.

19.5.2. Processing Replies Manually I f you opt ed for m anual processing, t hen you need t o check your Out look inbox periodically t o look for replies. When you find a reply, right - click it , and t hen choose Export Dat a t o Microsoft Access. This opt ion appears only if you right - click a m essage t hat Out look recognizes as a com plet ed Access form ( see Figure 19- 20) . I f Access successfully im port s t he m essage, t hen t he em ail m oves t o t he Access Dat a Collect ion Replies folder ( or what ever folder you set up in st ep 9) . Out look shows a confirm at ion m essage t elling you t hat all's well. I f you find a m essage t hat Access can't process, t hen you get t o decide how you want t o handle it . Possible problem s include values t hat break field validat ion rules ( Sect ion 4.3) , values t hat duplicat e a value t hat 's already in t he t able when duplicat es aren't allowed ( Sect ion 4.1.3) , and values t hat break dat a t ype or field lengt h rest rict ions. Here are som e possible st rat egies for dealing wit h m essages t hat Access can't process: ●

D e le t e t h e m e ssa ge a n d for ge t a bou t it . You could use t his approach if you spot a m essage t hat 's obviously wrong, or one t hat duplicat es a record t hat 's already in t he t able.

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-5.html (6 of 10) [1/7/2007 7:15:45 AM]

Section 19.5. Collecting Info by Email

Figu r e 19-19. Here's part of the form for the Bachelors table. You'll notice that Access automatically identifies the required fields, and fills in some details about the acceptable data types for each form.

● ●

Ask for a cor r e ct ion . Send t he form t o t he recipient , and ask t hem t o t ry again. En t e r t h e cor r e ct in for m a t ion by h a n d. I f you can figure out where t he dat a went wrong, t hen you m ay be able t o correct t he problem yourself. I n t hat case, use t he dat asheet in Access t o add t he record t hat it should've creat ed.

19.5.3. Processing Replies Automatically I f you chose t o use aut om at ic processing, t hen you don't need t o t ake any m ore st eps. As replies arrive in your I nbox, Access adds t he dat a t o t he t able, wit hout you even knowing t hat it 's happening. I t 's a good idea t o check your t able frequent ly t o m ake sure t he dat a t hat 's being added doesn't cont ain obvious errors. Also, you should review your Out look inbox for m essages t hat weren't successfully processedlike t hose t hat cont ain bad dat a. You'll know a m essage couldn't be processed if you see it in your inbox, and t here's a red square or a blank value next t o it in t he Cat egories colum n. I n t his sit uat ion, you can t ry all t he solut ions described in t he previous sect ion t o fix t he problem .

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-5.html (7 of 10) [1/7/2007 7:15:45 AM]

Section 19.5. Collecting Info by Email

Figu r e 1920. Choose this shortcut menu option, and the current message goes to Access, which places it in a new record in the Bachelors table.

Note: You can also try one other technique to remedy problematic emails. If the record wasn't processed because of a temporary problem (for example, the database was open in exclusive mode at the time, or the drive where the database is stored wasn't available), you can ask Access to try to process it again. To do so, right-click it, and then choose Export Data to Microsoft Access.

19.5.4. Managing Your Email Collection Settings Aft er you've sent your m essage, all t he inform at ionwhom it 's been sent t o, what it 's asking for, and so onis st ored in your dat abase. Access needs t his info so it knows how t o process replies. You can do a few t hings t o m ake sure everyt hing runs sm oot hly. For exam ple, you can send t he em ail t o m ore people, swit ch aut om at ic processing on or off, and rem ove t he em ail inform at ion alt oget her. To perform any of t hese t asks, Collect Dat a Manage Replies. This act ion shows t he Manage Dat a Collect ion Messages shown choose Ext ernal Dat a in Figure 19- 21. ( The nam e of t his com m andManage Repliesis a bit m isleading. You're not act ually doing anyt hing wit h t he replies here. I nst ead, you're t uning up your original em ail set t ings.)

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-5.html (8 of 10) [1/7/2007 7:15:45 AM]

Section 19.5. Collecting Info by Email

Figu r e 19-21. Click Message Options to pop up the dialog box where you can switch automatic processing on or off, and adjust how it works (Figure 19-17). Click "Resend this Email Message" to send your form out to another batch of people. Finally, click "Delete this Email Message" when you're done receiving data, and you don't want to use this feature anymore.

Tip: Even if you're finished collecting data, there's no reason to delete your email settings. Instead, why not keep them around in case you decide to collect data again, sometime in the future?

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-5.html (9 of 10) [1/7/2007 7:15:45 AM]

Section 19.5. Collecting Info by Email

file:///C|/html/0596527608/access2007tm-CHP-19-SECT-5.html (10 of 10) [1/7/2007 7:15:45 AM]

Chapter 20. Connecting Access to SQL Server

20. Connecting Access to SQL Server I n Chapt er 18, you considered how you t o share your prize dat abase wit h ot her people. For som e, t his is Access paradise. Team s of people can collaborat e, businesses can t ake care of day- t o- day workflow, and everyone works happily ever aft er. But for ot hers, dat abase sharing is a big- t im e headache, because Access j ust can't keep up wit h everyone who want s t o m ake changes at t he sam e t im e. I n t his chapt er, you'll learn anot her approach, which let s you break t hrough t he lim it s of Access and share your dat abases wit h m uch larger groups of people who can use it m uch m ore int ensively. To do so, you'll plug Access int o SQL Server, Microsoft 's hard- core, server- side dat abase. ( Flip back t o Sect ion 3.1.2 for a refresher on t he difference bet ween client - side dat abases and server- side dat abases.) This com binat ion gives you t he best of bot h worlds. You get t o use a suprem ely reliable dat abase engine ( t hat 's SQL Server) , wit hout giving up t he friendly user int erface t hat m akes it easy t o get t hings done ( t hat 's Access) . Best of all, you can st art using a version of SQL Server wit hout shelling out a single cent .

file:///C|/html/0596527608/access2007tm-CHP-20.html [1/7/2007 7:15:47 AM]

Section 20.1. Should You Switch to SQL Server?

20.1. Should You Switch to SQL Server? As you learned in Sect ion 18.1.1, t here's no absolut e rule t hat decides who can use Access's built - in sharing feat ure successfully and who can't . You find ext rem esa Fort une 500 com pany wit h t housands of workers probably can't use Access sharing, while a five- person int erior design t eam won't face any problem sbut for m any people, m any fact ors need t o be considered. Successful sharing depends on how m any people need t o m ake changes at once, how ext ensive t heir changes t end t o be, how long t hey keep t heir records in edit m ode, and how m uch dat a you're st oring ( for exam ple, ginorm ous m em o and at t achm ent fields are m uch harder t o m anage in a m ult iuser dat abase t han plain t ext and num ber fields) . Som e fact ors are beyond t he cont rol of Accesslike a slow or unreliable com pany net workt hat can derail dat abase sharing. Sect ion 18.1.1 has som e good guidelines t hat describe when sharing m ay fall short . However, if you're set t ing up an Access dat abase for a sm all business, you m ay need t o t est out dat abase sharing yourself. I f you go ahead wit h dat abase sharing, som e t ypical sym pt om s will alert you if it 's not working out . Here are som e key danger signs: ●





You r e dit s oft e n ove r la p w it h som e on e e lse 's. I n t his sit uat ion, Access keeps asking you what t o do about t he conflict ( Sect ion 18.3.2) . This problem is one of t he m ost com m on, and while it won't crash your dat abase, conflict ing edit s can lead t o legit im at e changes get t ing blown out by som eone else's work. You ca n 't e dit t h e r e cor ds you w a n t . This problem occurs when Access uses locks ( Sect ion 18.3.3) t o prevent sim ult aneous changes. Locks let Access dodge t he overlapping edit problem but at a price: Every ot her process t hat uses t he record grinds t o a halt . Again, t his occurrence isn't dangerousj ust a t riple- Aspirin aggravat ion. D a t a ge t s cor r u pt e d. This occurrence is bot h t he least com m on and t he m ost serious. But even t hough it 's rare ( and it get s rarer wit h each new release of Access) , it can st ill happen. You'll know you have a problem when garbled dat a appears in a field, or Access gives you a bizarre error m essage ( like " t oo m any indexes" ) when you t ry t o open a dat abase obj ect . Sect ion 18.4 explains t he problem and gives som e safet y t ips.

Note: Data corruption can happen through no fault of Access. For example, if Zoe loses her network connection while she's in the middle of saving a change, Access can leave the shared database in an inconsistent state. The only way that you can prevent problems like these is to have a powerful database program running on the server that does all the work. (That's the idea behind SQL Server. When you use SQL Server, no one changes the database directly. Instead, people make polite requests to the always-running SQL Server engine, which then does the work in a safe and controlled manner.)

So what can you do if you find t hat dat abase sharing j ust doesn't work for you? One of t he best opt ions is t o use a high- powered server- side dat abase product , like SQL Server. Using SQL Server obviously adds m ore com plexit y ( m eaning you'll spend m ore t im e set t ing it up and m aking sure it 's running properly) , but it gives you ironclad support for sharing dat a safely and efficient ly.

file:///C|/html/0596527608/access2007tm-CHP-20-SECT-1.html (1 of 5) [1/7/2007 7:15:52 AM]

Section 20.1. Should You Switch to SQL Server?

20.1.1. How SQL Server Works Before you prance int o t he land of SQL Server, you need t o know a lit t le bit m ore about how it works. Figure 20- 1 shows how SQL Server and Access int eract . I n t his exam ple, t here are several people using t he SQL Server dat abase at once, each wit h t heir own copy of Access t o help t hem out .

Note: This is actually how any server-side database works, including competing database products like Oracle and DB2. However, other server-side databases don't have the nifty Access integration that you'll learn about in this chapter, so clients need to use another front-end (usually, a custom-built application).

Figu r e 20-1. SQL Server hosts the database with its tables (and, optionally, some queries). Access runs the front end, which contains all other types of objects (reports, forms, macros, and code modules).

file:///C|/html/0596527608/access2007tm-CHP-20-SECT-1.html (2 of 5) [1/7/2007 7:15:52 AM]

Section 20.1. Should You Switch to SQL Server?

This figure j ust m ay look fam iliaraft er all, t his is m ore or less t he sam e way t hat dat abase sharing works. Each person get s a copy of t he front end wit h t he form s and report s, and t he back end ( which act ually st ores t he dat a) is placed on anot her com put er ( t he server) and m ade available t o all. However, t here's also a significant difference here. I n SQL Server Land, t he individual front ends do less work. I nst ead of m odifying t he dat abase on t heir own, t hey cont act SQL Server ( which is really j ust a Windows program t hat runs in t he background on t he server com put er) . Essent ially, you've given Access a dem ot ion. I t 's now responsible for eye candy, m acros, and print out s, but it doesn't do t he heavy lift ing ( like insert ing, updat ing, and delet ing records) anym ore.

20.1.2. A Cheaper SQL Server At t his point , you're probably wondering how m uch t hat part in t he cent er of Figure 20- 1t he SQL Server dat abase engineact ually cost s. Microsoft set s t he price using a com plex licensing schem e t hat rat chet s up t he cost depending on how m any people use t he dat abase at once. Usually, it runs int o t housands of dollars, and it 's not uncom m on for a big business t o shell out $20,000 or m ore annually.

UP TO SPEED The Top Reasons to Switch to SQL Server You have a lot of reasons t o like SQL Server. But when diehard Access fans swit ch over, t hey usually have one of t he following reasons in m ind: ● ●







Lot s a n d lot s of pe ople . As you've learned, Access doesn't do so well if you need t o share one dat abase file wit h a few hundred people. Lot s a n d lot s of da t a . Access doesn't let you m ake a dat abase bigger t han 2 GB ( gigabyt es) . The full version of SQL Server let s you creat e dat abases t hat swallow ent ire hard drives whole. Pe r for m a n ce . As your dat abase grows, you'll probably find t hat it doesn't ret rieve your dat a quit e as speedily as it used t o. Alt hough indexes can help t o a cert ain ext ent ( see Sect ion 6.2.2) , SQL Server is able t o do m uch m ore. I t keeps recent ly used inform at ion in a vast pool of m em ory, and doles t hat inform at ion out t o whom ever needs it . This t echnique alone saves oodles of t im e. Re a l se cu r it y. As you learned in Sect ion 18.5, Access doesn't offer a fine- grained securit y m odel t hat let s you lock specific people out of specific dat abase obj ect s. ( I t used t o, but Microsoft pulled t hat feat ure out of Access 2007 because it wasn't secure enough.) But SQL Server has bullet proof securit y t hat can be as fine- grained as you want . Tr a n sa ct ion s. I n com plex dat abase syst em s, m any t asks consist of several separat e dat abase operat ions t hat happen one aft er t he ot her. For exam ple, a m oney t ransfer of $500 involves t wo correlat ed act ionsone account get s a $500 credit , and t he ot her get s a $500 debit . SQL Server let s you put t his sequence of st eps in a t ransact ion, which ensures t hat if any one of t hese act ions fails, t he whole shebang is cancelled. I n ot her words, even if light ning st rikes and your server reboot s in t he m iddle of it s work, SQL Server can rest ore t he syst em t o t he m om ent j ust before t he account t ransfer ( and you'll never wind up wit h $500 winking out of exist ence) .

Alt hough t hese feat ures are great , m ost of t hem are beyond t he scope of t his book. To learn m ore, you need t o t rack down a dedicat ed book about SQL Server. One good choice is Beginning SQL Server 2005 Program m ing by Robert Vieira ( Wrox) . ( Don't be put off by t he file:///C|/html/0596527608/access2007tm-CHP-20-SECT-1.html (3 of 5) [1/7/2007 7:15:52 AM]

Section 20.1. Should You Switch to SQL Server?

word " program m ing," as t his book covers t he essent ials of dat abase design, opt im izat ion, and m aint enance.)

But before you skip t his chapt er in disgust , t here's som et hing you should know: A com plet ely free version of SQL Server is out t here wait ing for you. Am azingly enough, it 's alm ost as powerful as t he one t hat cost s t housands of dollars and requires you t o pledge your first - born child t o Microsoft . This version is called SQL Server 2005 Express Edit ion, and you'll learn how t o download and inst all it in t he next sect ion. I f you com pare it wit h t he full version of SQL Server, you'll find it has t hree lim it at ions: ●

● ●

I t su ppor t s j u st on e CPU ( com pu t e r pr oce ssor ) . More CPUs m ake for m ore powerful com put ers, and t his lim it prevent s SQL Server Express from being quit e as powerful as it s big nonExpress brot her. I t ca n u se on ly 1 GB of RAM m e m or y. I f your server has m ore, use it for som et hing else. Ea ch da t a ba se you cr e a t e t ops ou t a t 4 GB. No problem hereAccess it self t ops out at 2 GB dat abase files. I f you avoid st oring pict ures and ot her large cont ent in t he dat abase, you'll be good for a while.

What 's m ore not ewort hy is all t he st uff t hat isn't left out . SQL Server Express is a full- fledged version of SQL Server, wit h exact ly t he sam e high- powered engine under t he hood. I f you need t o upsize your Access dat abase, it 's a great deal.

Note: SQL Server Express also leaves out fancy tools to help you create tables and manage your databases. Although you can download a free management tool from Microsoft (see Figure 20-2), Access has already got you covered. It's a capable front end that can help you do everything you need to do.

FREQUENTLY ASKED QUESTIONS Can You Trust Microsoft? Why would Microsoft give anyt hing away for free? Savvy com put er users are suspicious of anyt hing t hat seem s t oo good t o be t rue. They're worried t hat Microsoft 's SQL Server deal m ay be a craft y bait - and- swit ch t act icin ot her words, j ust enough t o ent ice you t o use SQL Server but not enough t o m eet your needs. Fort unat ely, you have no reason t o worry. I f you decide t o use SQL Server Express, you can st ick wit h it happily for years wit hout ever finding a reason t o upgrade t o t he ret ail version. So why does Microsoft offer a product t hey can't m ake any m oney on? I t 's sim plet hey're aft er t he big fish. They know t hat a sm all com pany m ay st art out wit h SQL Server Express and t hen grow int o a large ent erprise t hat 's happy t o pay t he ext ra m oney t o get a version t hat 's even m ore powerful. This is part icularly t rue if t hat com pany is using SQL Server t o power a so- called Web applicat ion ( an online shopping sit e, for exam ple) . I f t hat Web sit e becom es

file:///C|/html/0596527608/access2007tm-CHP-20-SECT-1.html (4 of 5) [1/7/2007 7:15:52 AM]

Section 20.1. Should You Switch to SQL Server?

t he next eBay, t he com pany running it will need som e serious dat abase horsepower ( like a server com put er t hat has m ult iple CPUs and a t on of m em ory) . To support t his hardware, t hey'll need t he full version of SQL Server. Finally, offering a free version of SQL Server helps Microsoft by ent icing m ore people t o design fancy dat abase syst em s using SQL Server. A t echie m ay com e t o know and love SQL Server Express, and t hen recom m end t he full version t o a big- pocket ed com pany.

file:///C|/html/0596527608/access2007tm-CHP-20-SECT-1.html (5 of 5) [1/7/2007 7:15:52 AM]

Section 20.2. Getting Started: SQL Server 2005 Express

20.2. Getting Started: SQL Server 2005 Express Before you can st art using SQL Server Express, you need t o inst all it . This process is fairly st raight forward, but it 's long and it involves downloading som e very big filesone t hat 's 22 MB ( m egabyt es) and anot her t hat 's 54 MB. I f you're st ill using a dial- up connect ion, it could t ake you a few m ind- num bing hours.

Note: Everything you learn in this chapter about Access and SQL Server Express also applies to the full version of SQL Server. However, if you have that version, you obviously don't need to follow the down-load steps described hereinstead, you can pop in your setup DVD and get going right away.

20.2.1. Installing SQL Server Express You inst all SQL Server on t he com put er where you plan t o place t he shared dat abase. Typically, t his is a com put er on t he net work t hat no one uses for anyt hing else. ( I f som eone's using t he com put er, t here's t he risk t hat t hey'll shut it down, rest art it , t ie it up wit h ot her work, or do som et hing else t hat will affect everyone's abilit y t o get t he inform at ion t hey need.) You don't need t o inst all SQL Server on t he com put ers t hat run t he Access front end, alt hough obviously t hey all need t o have a copy of Access. However, if you're st ill in t he process of designing and fine- t uning your dat abase, you m ay decide t o t ry it out on your own com put er first . I n t hat case, you inst all SQL Server right on your own PC. Then, when you're ready t o st art sharing, you inst all SQL Server on t he server com put er and m ove your dat abase t here ( as described in Chapt er 21) . I n fact , if you're new t o SQL Server it 's probably best if you t ry it out on your com put er first . That 's because you need t o t weak a few finicky set t ings in order t o let ot her people access SQL Server from ot her com put ers. You'll probably prefer t o see how everyt hing works before you st art m essing around wit h t hose det ails. The syst em requirem ent s for SQL Server are pret t y m odest . ( Shockingly enough, t hey're less st ringent t han t he requirem ent s for running Access.) You can find t he exact specificat ions at www.m icrosoft .com / sql/ edit ions/ express/ sysreqs.m spx. You'll find t hat any relat ively m odern com put er can run SQL Server, but you m ay need t o m ake sure your operat ing syst em has t he lat est updat es and service packs. For exam ple, Windows XP com put ers need Service Pack 2.

Tip: To make sure a computer has the latest updates, click the Start button, and then choose Windows Update.

Once you've decided where t o inst all SQL Server and you've verified t hat t he com put er can handle it , here's what you need t o do: 1. Ope n you r fa vor it e W e b br ow se r a n d go t o t h e .N ET dow n loa d sit e . Before you can inst all SQL Server, you need t o inst all a com ponent t hat SQL Server uses: t he .NET Fram ework 2.0. You can find it by heading t o ht t p: / / m sdn.m icrosoft .com / net fram ework and searching around. Or, bet t er, use t he secret short cut URL ht t p: / / t inyurl.com / drj 86.

Note: If you have Windows Vista, you already have the .NET Framework 2.0. And even if you don't have Windows Vista, another application may have already installed it on your computer. If you suspect it's there, head to the Control Panel, go to the Administrative Tools section, and look for an icon named Microsoft .NET Framework 2.0 Configuration. If you find it, congratulationsyou can skip straight to step 4. 2.

file:///C|/html/0596527608/access2007tm-CHP-20-SECT-2.html (1 of 6) [1/7/2007 7:15:58 AM]

Section 20.2. Getting Started: SQL Server 2005 Express

On ce you fin d t h e .N ET Fr a m e w or k 2 .0 , dow n loa d a n d in st a ll it . The set up file is pret t y big: about 22 MB. 3. On ce you fin ish dow n loa din g t h e se t u p file , r u n it , a n d click t h r ou gh a ll t h e st e ps in t h e se t u p w iza r d. Don't worryyou don't have any decisions t o m ake. 4. W h e n t h e se t u p is fin ish e d, h e a d t o w w w .m icr osoft .com / sql/ e dit ion s/ e x pr e ss. This page has plent y of inform at ion about SQL Server Express. Hunt around for a link t hat let s you download SQL Server Express, and t hen click it . ( I t was last spot t ed wit h t he t ext " Get SQL Server Express." ) 5. Click a w a y t o fin d t h e SQL Se r ve r Ex pr e ss dow n loa d ( Figu r e 2 0 - 2 ) . Along t he way, Microsoft will ask if you want t o regist er wit h Microsoft . I f you regist er, you'll get news from Microsoft ( which is handy if you want t o know about t he lat est SQL Server updat e) . However, it 's purely opt ional.

Figu r e 2 0 - 2 . You have options. Not only can you download SQL Server 2005 Express (the circled link), you can also get a slick management tool called SQL Server Management Studio (underneath), some samples, and the informationpacked help file reference

file:///C|/html/0596527608/access2007tm-CHP-20-SECT-2.html (2 of 6) [1/7/2007 7:15:58 AM]

Section 20.2. Getting Started: SQL Server 2005 Express

that's known as the SQL Server 2005 Books Online (at the bottom).

6. W h e n you fin d t h e dow n loa d lin k for SQL Se r ve r ( Figu r e 2 0 - 2 ) , click t o dow n loa d a n d in st a ll it . The SQL Server download is a whopping 54 MB. 7. Aft e r you fin ish dow n loa din g t h e se t u p file , r u n it . Before t he set up st art s, you need t o go t hrough a few sim ple st eps. Here's what t o expect : ❍

Be for e in st a llin g a n yt h in g, t h e se t u p pe r for m s a syst e m con figu r a t ion ch e ck . The set up program exam ines your com put er, and t hen report s t o you whet her it 's SQL- Server- wort hy ( Figure 20- 3) .

Figu r e 2 0 - 3 . This computer can run SQL Server, but a warning message appearsits aging Pentium III processor is a bit underpowered if you expect optimum performance.

file:///C|/html/0596527608/access2007tm-CHP-20-SECT-2.html (3 of 6) [1/7/2007 7:15:58 AM]

Section 20.2. Getting Started: SQL Server 2005 Express







You 'r e a sk e d t o fill in you r n a m e . This part is pret t y t ypical, but keep t he " Hide advanced configurat ion opt ions" checkbox t urned on t o avoid t he low- level set t ings you don't want t o change. You 'r e a sk e d t o pick t h e fe a t u r e s you w a n t t o in st a ll. Keep t he st andard opt ionst hey inst all everyt hing you need. You 'r e a sk e d if you w a n t t o a u t om a t ica lly se n d e r r or m e ssa ge s t o M icr osoft . No, don't expect t hem t o help you out . This feat ure is designed solely t o help Microsoft im prove fut ure versions of SQL Server by det erm ining what problem s are current ly afflict ing it s users.

And t he end of all t his, you get t o one t ricky part . SQL Server will ask you what t ype of securit y you want t o use. 8. Ch oose you r a u t h e n t ica t ion m ode ( Figu r e 2 0 - 4 ) . You have t wo opt ions: ❍



W in dow s Au t h e n t ica t ion M ode m eans t hat SQL Server decides whet her som eone's allowed t o use a dat abase based on t hat person's Windows user account . This approach is t he best and m ost secure. Unfort unat ely, it also m eans you need t o do a bit of ext ra work lat er on t o m ake sure ot her people are allowed t o use your dat abase ( Sect ion 20.2.2) . M ix e d M ode m eans t hat SQL Server let s people use t he dat abase if t hey have t he right Windows account ( as described above) or if t hey can supply a user nam e and password com binat ion t hat you've defined. I f you choose Mixed m ode, you need t o supply a password for a special SQL Server account known as sa ( syst em adm inist rat or) . Anyone who logs in wit h t his user nam e and password is given com plet e cont rol of every dat abase on t he server. Mixed m ode saves you t he hassle of doing any ext ra configurat ion, but it 's not as secure. ( For one t hing, you need t o pass t his inform at iont he user nam e and password you want people t o usearound t he office.)

Note: If you aren't familiar with concepts like Windows users and groups, and you don't have a network administrator to help you out, you'd better choose the Mixed mode option. It's not a very secure approach, but it's the only easy way that you'll be able to let other people log in to the database (Section 20.2.2).

Figu r e 20-4. Windows Authentication Mode gives

file:///C|/html/0596527608/access2007tm-CHP-20-SECT-2.html (4 of 6) [1/7/2007 7:15:58 AM]

Section 20.2. Getting Started: SQL Server 2005 Express

you the best security. However, it also means you need to do a bit of configuration to tell SQL Server who it can trust.

9. Aft e r t h is poin t , t h e in st a lla t ion is lon g bu t st r a igh t for w a r d. N ow 's a good t im e t o gr a b a cu p of coffe e . Once t he set up is finished, you should run Windows Updat e again ( click t he St art but t on, and t hen choose Windows Updat e) . That 's because SQL Server Express has t wo service packs ( at t he t im e of t his writ ing) , and t he Windows Updat e feat ure inst alls t hem aut om at ically.

Note: The SQL Server Express service packs are critical for Windows Vista users. Without them, the super-strict Windows Vista security model will stop you from doing just about anything with your SQL Server databases.

Once you've finished t his last round of updat ing, you're finally ready t o get t o work. I f you decided t o inst all SQL Server on your com put er, you can st art using it right away. Jum p ahead t o Sect ion 20.3.3 t o ret urn t o t he welcom ing arm s of Access. I f you decided t o inst all SQL Server on anot her com put er, you st ill have m ore set up st eps t o finish. The next sect ion has t he det ails.

20.2.2. Putting SQL Server on the Network When you first inst all SQL Server, it 's usable only from t he current com put er t hat is, ot her com put ers can't log in t o t he server and use any of it s dat abases. At first glance, t his appears t o defeat t he whole purpose of using SQL Server. ( On second glance, it does t oo.) However, Microsoft file:///C|/html/0596527608/access2007tm-CHP-20-SECT-2.html (5 of 6) [1/7/2007 7:15:58 AM]

Section 20.2. Getting Started: SQL Server 2005 Express

knows t hat if t hey release a product t hat 's wide open t o t he rest of t he world, wit h it s hackers, crackers, and all- around com put er bad guys, som eone som ewhere will shout at t hem . For t hat reason, SQL Server t akes t he safest approachit lim it s it self t o t he current com put er unt il you give it t he go- ahead t o accept out side calls. To open up SQL Server t o t he out side world, you need t o change t wo configurat ion set t ings. I f you're using Windows XP or Vist a, you also need t o configure t he Windows firewall so it let s SQL Server get t hrough. You can find t he lat est set up inst ruct ions in a Knowledge Base art icle at ht t p: / / support .m icrosoft .com / kb/ 914277. Once you've m ade t hese changes, ot her people will finally be able t o cont act SQL Server and t ry t o log in. However, t he part y's not on yet . SQL Server m ay st ill refuse t hem . That 's because it won't let anyone in t hat it doesn't t rust . So who does SQL Server Express t rust ? Here's t he lowdown: ●



When you first inst all SQL Server, it 's set up t o t rust anyone who's an adm inist rat or of t he com put er where SQL Server is inst alled. ( Technically, being an adm inist rat or m eans your Windows user account is a m em ber of t he Adm inist rat ors group.) I f you configured SQL Server t o use Mixed m ode aut hent icat ion ( Sect ion 20.2.1) , it also let s in anyone who supplies t he user nam e sa and t he password you specified during t he inst all.

I f you want SQL Server t o t rust m ore people, you have som e ext ra work t o do. Usually, you m ake sure t hat everyone who needs t o use SQL Server belongs t o a single Windows group ( a group is a collect ion of users and has a descript ive nam e, like Guest s, Adm inist rat ors, Dat abaseLovers, and so on) . This j ob is a Windows set up t ask, so consult your net work adm inist rat or t o get it done. Once you've done t hat , you need t o t ell SQL Server t o t rust your group. You can use several approaches t o t ake t his st ep, but t he easiest is t o download t he free SQL Server Managem ent St udio t ool ( shown in Figure 20- 2) . For m ore inform at ion, check out t he SQL Server Managem ent St udio Help ( which is fairly t echnical) , or look for a dedicat ed book about SQL Server adm inist rat ion.

Note: By this point, you're probably wondering why SQL Server makes life so difficult. The reason is because SQL Server is designed to be extremely flexible. Its security model seems ridiculously complex when you're just trying to let people use your database, but it's indispensable if you need to control exactly what different people are allowed to do.

file:///C|/html/0596527608/access2007tm-CHP-20-SECT-2.html (6 of 6) [1/7/2007 7:15:58 AM]

Section 20.3. Creating a SQL Server Database

20.3. Creating a SQL Server Database You've suffered t hrough t he long and grueling inst allat ion process. Now it 's t im e t o reap t he rewards of your labor and creat e your first SQL Server dat abase. Access gives you t wo ways t o creat e a SQL Server dat abase: ● ●

You can t ake an ordinary Access dat abase and upsize it . Access creat es t he t ables you need and t ransfers all your inform at ion t o SQL Server. You can use Access t o creat e a new SQL Server dat abase from scrat ch.

Generally, upsizing a dat abase is easiest because it let s you design your t ables using t he t ools you're m ost fam iliar wit h, and t hen t ransfer your dat a. ( As you'll see, creat ing a SQL Server t able in Access is a sim ilar, but subt ly different process from creat ing an ordinary Access t able. I t 's a bit like you'd feel if you got up in t he m orning and found som eone had swapped your sock drawer wit h your CD collect ion. Everyt hing's t herej ust not where you expect .) The direct - creat ion approach also has it s advant ages. Most im port ant ly, it gives you m ore cont rol because you don't have a conversion st ep. Access dat abases don't line up exact ly wit h SQL Server dat abases ( for exam ple, t he field dat a t ypes t hat you use are sim ilar, but slight ly different ) . I f you creat e your dat abase in SQL Server from t he st art , you'll dodge any pot ent ial conversion issues. I t t he following sect ions, you'll learn about bot h approaches.

20.3.1. Upsizing a Database Access has a handy Upsizing wizard t hat can convert any Access dat abase int o a SQL Server dat abase. The Upsizing wizard is sim ilar t o t he dat abase split t er ( Sect ion 18.2.2) when you're finished, you'll have a front end and a back end. Your front end is an Access file t hat cont ains your form s, report s, m acros, and code. Your back end is t he dat a ( and usually t he queries) , which are in SQL Server's capable hands. Here's how t o t ake t he Upsizing wizard for a whirl: 1. Ope n t h e da t a ba se you w a n t t o u psize . Choose Dat abase Tools

Move Dat a

SQL Server.

2. Th e fir st w in dow of t h e Upsizin g w iza r d a ppe a r s ( Figu r e 2 0 - 5 ) .

file:///C|/html/0596527608/access2007tm-CHP-20-SECT-3.html (1 of 10) [1/7/2007 7:16:06 AM]

Section 20.3. Creating a SQL Server Database

Figu r e 20-5. Usually, you'll use the Upsizing wizard to take the information from an Access database file and put it into a shiny new SQL Server database.

3. Ch oose " Cr e a t e n e w da t a ba se ," a n d t h e n click N e x t . I f you've already creat ed a SQL Server dat abase in your SQL Server com put er ( for exam ple, using anot her dat abase m anagem ent t ool) , you could choose " Use exist ing dat abase" t o t ransfer your Access t ables int o t hat dat abase. However, it alm ost always m akes sense t o creat e a new dat abase. Aft er all, a dat abase engine like SQL Server can st ore a virt ually unlim it ed num ber of dat abases. 4. I n t h e n e x t st e p ( Figu r e 2 0 - 6 ) , you n e e d t o t e ll Acce ss w h e r e t o fin d you r da t a ba se se r ve r . Fir st , su pply t h e se r ve r n a m e in t h e box a t t h e t op of t h e w in dow . The server nam e consist s of t he nam e of t he com put er t hat 's running SQL Server, followed by a backslash, followed by t he word SQLEXPRESS. So, if t he com put er t hat 's running SQL Server is nam ed FudgeServer, you'd find your dat abase at FudgeServer\ SQLEXPRESS. I f you're connect ing t o t he full version of SQL Server ( not t he Express edit ion) , you usually don't need t he second part , so j ust FudgeServer would do. Consult wit h your dat abase adm inist rat or for help.

Note: To find out the name of your computer, find the My Computer icon (on your desktop or in Windows Explorer), right-click it, and then choose Properties. Then choose the Computer Name tab. You'll see the name of your computer and a handy Change button you can use to modify it. file:///C|/html/0596527608/access2007tm-CHP-20-SECT-3.html (2 of 10) [1/7/2007 7:16:06 AM]

Section 20.3. Creating a SQL Server Database

Figu r e 20-6. Here Access is about to connect to a computer named MYSERVER, which is running SQL Server Express.

5. Ke e p t h e Use Tr u st e d Con n e ct ion ch e ck box t u r n e d on . This act ion t ells Access t o connect using your Windows account . However, if you need t o supply a different user nam e and password connect ion, clear t he checkbox, and t hen ent er t his inform at ion in t he t ext boxes below. 6. En t e r t h e n a m e for you r da t a ba se , a n d t h e n click N e x t . Use t he sam e rules you follow for nam ing dat abase obj ect sbe short and leave out spaces and ot her punct uat ion.

Note: When you create a database, SQL Server doesn't tell you the name of the actual database file (and actually, it's usually more than one file). That's because the file names are just not that important. Instead, all you need to know is the name you've anointed your database with (BoutiqueFudge, for example). Behind the scenes, SQL Server stores your data in the appropriate files, so you don't need to worry about it.

file:///C|/html/0596527608/access2007tm-CHP-20-SECT-3.html (3 of 10) [1/7/2007 7:16:06 AM]

Section 20.3. Creating a SQL Server Database

7. Ch oose t h e t a ble s you w a n t t o t r a n sfe r t o you r da t a ba se ( Figu r e 2 0 - 7 ) , a n d t h e n click N e x t . Access doesn't let you pick t he queries you want t o t ransfer. I nst ead, it t ransfers all t he queries t hat are relat ed t o t he t ables you pick. Ot her obj ect s, like form s and report s, are never t ransferred. 8. Th e n e x t st e ps le t s you con t r ol h ow SQL Se r ve r cr e a t e s you r t a ble s ( Figu r e 2 0 - 8 ) . Ch a n ge a n y opt ion s you w a n t , a n d t h e n click N e x t . I n Chapt er 2 you learned about indexes, and in Chapt er 4 you learned about default values and validat ion rules. Usually, if you've t aken t he t im e t o define t hese ingredient s in Access, you also want t hem in t he export ed SQL Server t ables, so leave t he checkboxes t urned on. Here are t he ot her opt ions you can use:

Figu r e 20-7. Click > to move a single table to the "Export to SQL Server" list, or >> to move them all.

file:///C|/html/0596527608/access2007tm-CHP-20-SECT-3.html (4 of 10) [1/7/2007 7:16:06 AM]

Section 20.3. Creating a SQL Server Database

Figu r e 2 0 - 8 . If you're intimidated by all the options in this step, just click Next to breeze on by. The standard settings are usually what you want.







Ta ble r e la t ion sh ips. Keep t his checkbox t urned on, because it ensures t hat t he relat ionships you've defined bet ween your t ables are enforced by SQL Server. You have t wo opt ions here. " Use DRI " is short for " use dat a relat ional int egrit yin ot her words, t he st andard pract ice of m aking sure you can't creat e child records t hat link t o a nonexist ent parent ( Sect ion 5.2.3) . " Use t riggers" t ells SQL Server t o use t he less com m on cascading delet es and cascading updat es feat ures ( Sect ion 5.2.3.1) . Add t im e st a m p fie lds t o t a ble s. This set t ing let s you creat e a t im est am p fieldan ext ra field whose only purpose is t o record each t im e a change is m ade. The t im est am p field is som et im es used t o prevent clashing edit s, because it let s you check if som eone else has m ade changes t o a record since t he last t im e you looked at it . Usually, you won't add any t im est am p fields. I nst ead, you'll add t hem t o specific t ables lat er on if you decide you want t his feat ure. On ly cr e a t e t h e t a ble st r u ct u r e . Wit h t his opt ion you can creat e all t he t ables in SQL Server, but leave out t he dat a. This opt ion is useful if you've been using t he Access dat abase file for t est ing and it 's full of fake dat a.

9. Th e la st st e p a sk s you w h a t t o do w it h t h e or igin a l Acce ss file . Usu a lly, you 'll ch oose " Cr e a t e a n e w Acce ss clie n t / se r ve r a pplica t ion ." Here's what t he t hree opt ions m ean: ❍

Cr e a t e a n e w Acce ss clie n t / se r ve r a pplica t ion . This opt ion creat es a special t ype of Access file called an Access proj ect . You'll recognize t he difference because every Access proj ect file has t he file ext ension .adp. This file is a front end t hat has all your report s, form s, and code, and has a special set of links t hat let s you int eract wit h your t ables t hat are on t he server. ( The original Access dat abase file rem ains, but you'll probably j ust delet e t hat now t hat all your dat a is in SQL

file:///C|/html/0596527608/access2007tm-CHP-20-SECT-3.html (5 of 10) [1/7/2007 7:16:06 AM]

Section 20.3. Creating a SQL Server Database





Server.) Lin k SQL Se r ve r t a ble s t o e x ist in g a pplica t ion . This opt ion is sim ilar t o creat ing an Access proj ect , except it m odifies t he current dat abase t o becom e t he front end. All t he t ables t hat have j ust been t ransferred are renam ed by adding t he word " local" at t he end ( so t he Product s t able becom es Product s_ local) . I n addit ion, you'll have a new set of linked t ables t hat use t he original t able nam es. Each linked t able let s you access t he corresponding t able in SQL Server. Once you've verified t hat t hese links work, you'll probably decide t o delet e t he " local" t ables so you don't get confused. ( For m ore about linked t ables, see t he box " Access Proj ect s vs. Linked Tables" in Sect ion 20.3.2) . N o a pplica t ion ch a n ge s. Wit h t his opt ion, t he dat a is t ransferred, but your Access dat abase isn't m odified. That m eans you'll be left wit h t wo set s of dat aone in your Access dat abase file, and one in SQL Server ( which you can't see or m odify in Access) . This result usually isn't what you want .

10. Click N e x t . I f you're creat ing an Access proj ect ( as described in t he previous st ep) , Access asks if you want t o open t he new proj ect front end right away or keep t he old dat abase open. Usually, you'll want t o open t he new file so you can get t o work. 11. Click Fin ish t o st a r t t h e u psizin g pr oce ss. Access connect s t o SQL Server and st art s t ransferring all t he dat a. As it works, you see a progress indicat or ( Figure 20- 9) . When Access is finished, it shows a report t hat sum m arizes how t he whole process went . You can print it , Close Preview Close Print Preview t o ret urn t o your dat abase. or choose Print Preview

Figu r e 20-9. Depending on the amount of data you have, this upsizing process may take a bit of time.

The conversion process usually runs wit hout a problem . However, not everyt hing can survive t he swit ch. Here are som e ingredient s t hat will be lost : ●

H ype r lin k fie lds. They becom e ordinary t ext fields.

file:///C|/html/0596527608/access2007tm-CHP-20-SECT-3.html (6 of 10) [1/7/2007 7:16:06 AM]

Section 20.3. Creating a SQL Server Database ● ●

At t a ch m e n t fie lds. They becom e ordinary t ext fields, but t he only t hing t he t ext field st ores are t he nam es of t he files t hat you originally put in t he at t achm ent . M u lt iva lu e fie lds. You're left wit h a sem icolon- separat ed list of values. This result gives you t he right inform at ion, but not in a way t hat SQL Server can use. Any relat ions and queries t hat use t his inform at ion are out of luck.

I f you're creat ing an Access proj ect ( rat her t han j ust linked t ables) , your queries are also convert ed. As a result , you'll lose t he following ingredient s, because SQL server doesn't support t hem : ● ● ● ●

Act ion queries ( Chapt er 8) t hat use param et ers ( Sect ion 7.4) . Crosst ab queries. Queries t hat reference values on a form . ( The form is in your front end, so once you t ransfer t he query, it has no way t o access t hat inform at ion.) Nonst andard queries t hat were creat ed in SQL view rat her t han in Design viewfor exam ple, union queries ( Sect ion 6.2.3.2) .

Tip: Want to go back the other way, and transfer some data from SQL Server into Access? If so, the trick is the import and export features in Access, which you learned about in Chapter 19.

Once you've finished t he upsizing process, you can cont inue t o work wit h your t ables as you did before. For exam ple, you can open your t ables in t he dat asheet , edit records, and use your form s and report s. The difference is t hat now your copy of Access is com m unicat ing wit h SQL Server t o get t he inform at ion it needs and m ake changes. When edit ing dat a and using form s and report s, you won't not ice any difference bet ween t he new upsized dat abase and your original dat abase ( except for t he fact t hat it m ay perform m ore slowly) . However, you will not ice a difference when you creat e a new t able or query, or when you m odify t he design of an exist ing t able or query. That 's because t ables and queries are act ually st ored in t he SQL Server dat abase, and SQL Server dat abases are designed different ly t han t heir Access count erpart s.

UP TO SPEED Access Projects vs. Linked Tables Access proj ect s and linked t ables sound like t wo sim ilar opt ions. They bot h let you creat e Access front ends t hat work wit h dat a in a SQL Server dat abase. However, here are som e im port ant differences: ●





Upda t a bilit y. Alt hough you can use bot h approaches t o m odify dat a, you can't m odify t he design of a linked t able. So if you want t o add fields, set up relat ionships, and so on, you need t o use an Access proj ect . Qu e r y pr oce ssin g. When you creat e an Access proj ect , your queries are convert ed t o SQL Server obj ect s and st ored on t he server. When you creat e a linked t able, your queries rem ain in t he front end. I t 's hard t o say which opt ion is bet t er. Usually, Access proj ect s have bet t er query perform ance, because t he server does m ore work. ( This is part icularly t rue if you're running a query t hat filt ers out a few records from a large t able.) However, linked t ables let you keep using t he fam iliar Access query designer, and t hey rem ove t he possibilit y of query conversion errors. File t ype . You place linked t ables in an ordinary Access dat abase. ( You can even put t hem alongside ordinary t ables.) However, an Access proj ect m ust always be st ored as a special . adp file.

file:///C|/html/0596527608/access2007tm-CHP-20-SECT-3.html (7 of 10) [1/7/2007 7:16:06 AM]

Section 20.3. Creating a SQL Server Database

You learned about linked t ables in Chapt er 19. The rest of t his chapt er assum es you're creat ing an Access proj ect .

You'll st art looking at t he differences in Sect ion 20.3.3. But first , it 's wort h considering how you can m anage t he SQL Server dat abase you've j ust creat ed.

20.3.2. Managing Your Database I n Access Land, it 's easy t o delet e, m ove, or back up a dat abase. All you need t o do is find t he corresponding . accdb file and use a file m anagem ent t ool like Windows Explorer. SQL Server doesn't work t his way. As you learned earlier, it handles files behind t he scenes, wit hout revealing t heir file nam es. And even if you know where t o find t he dat abase files, you can't accom plish m uch wit h t hem . For exam ple, if you want t o m ove a SQL Server dat abase from one server com put er t o anot her, a sim ple cut - andpast e operat ion in Windows Explorer won't work. The original server will keep looking for t he dat abase you m oved, and t he dest inat ion server will keep ignoring it . I f you want t o perform m anagem ent t asks like t hesedelet ing, m oving, and copying a dat abaseyou need t o work wit h SQL Server so it can m ove t he files and updat e it s dat abase cat alog. One opt ion is t o download t he free SQL Server Managem ent St udio t ool ( see Figure 20- 2) , which helps you out wit h a wide range of adm inist rat ive t asks. ( For exam ple, it 's t he t ool you'll need t o use if you get really am bit ious and st art configuring SQL Server's securit y set t ings so it allows som e people and rej ect s ot hers.) However, you can also perform t he m ost com m on Server m enu ( which appears m anagem ent t asks right inside Access. The secret is using t he Office but t on only when you have an Access proj ect open) . Your opt ions t here include: ●

Con n e ct ion . Pops open a Dat a Link Propert ies dialog box where you can change t he connect ion set t ings for your Access proj ect file. Usually, you head here if you have a problem connect ing t o your SQL Server dat abase. For exam ple, if som eone's m oved or renam ed t he SQL Server dat abase, or t hey've changed t he user nam e and password you need t o log in, t his window is where you can updat e your set t ings. Just supply t he new server, dat abase nam e, or password inform at ion, and t hen click OK t o reconnect .

Tip: If you open an Access project file but you don't see any tables, and the word "disconnected" appears in the title bar, Access wasn't able to connect to your database. If the name of the database or server has changed recently, choose Office button ●





● ●

Server

Connection to fix the problem.

Se r ve r Pr ope r t ie s. Shows a dialog box wit h a few basic det ails about your dat abase, including t he product you're running ( SQL Server) , it s version ( SQL Server 2005 is version num ber 9) , t he server locat ion, and t he current dat abase. You can't change any of t he inform at ion here. Lin k Ta ble s. Let s you add one or m ore linked t ables t o your current Access proj ect . Usually, t he idea here is t o add links t o t he t ables in anot her dat abase ( or even anot her dat abase server) , so you can see everyt hing using one Access file. Ba ck Up SQL D a t a ba se . Creat es a backup of your SQL Server dat abase in a .dat file, which you can choose t o place anywhere you want ( on t he server com put er or your com put er) . SQL Server gurus generally prefer t o use a t ool t hat let s t hem m ake aut om at ed backups, like SQL Server Agent ( which is only included wit h t he full version of SQL Server) . Re st or e SQL D a t a ba se . Takes a .dat file t hat you creat ed wit h t he Office but t on Server Back Up SQL Dat abase com m and and recreat es t he corresponding SQL Server dat abase. Tr a n sfe r D a t a ba se . Let s you m ove a dat abase from one com put er t o anot her. ( Bot h com put ers need t o

file:///C|/html/0596527608/access2007tm-CHP-20-SECT-3.html (8 of 10) [1/7/2007 7:16:06 AM]

Section 20.3. Creating a SQL Server Database



● ●

have t he SQL Server soft ware.) Access st ores t he new server locat ion in your proj ect file so you can keep using t he dat abase in it s new locat ion. This feat ure is handy if you've been t est ing a SQL Server dat abase on your com put er and now you want t o m ove it t o a net work server where everyone can access it . Copy D a t a ba se File . I f you're running SQL Server on your com put er, t his opt ion let s you creat e a copy of t he dat abase file t hat you can t ake t o anot her com put er. ( I f you're connect ed t o a copy of SQL Server Server Transfer on anot her server, t his com m and won't work.) Generally, t he Office but t on Dat abase com m and is easier t o use because it get s everyt hing done in one st ep. D r op SQL D a t a ba se . Rem oves t he dat abase from SQL Server and delet es it . Se t Logon Pa ssw or d. I f you're using Mixed m ode aut hent icat ion ( Sect ion 20.2.1) , t his opt ion let s you change t he SQL Server password.

20.3.3. Creating a SQL Server Database from Scratch Access also let s you creat e a new SQL Server dat abase wit h not hing in it , and t hen add t he t ables you want . Here's how t o do it : 1. Ch oose Office bu t t on Bla n k D a t a ba se ) .

N e w ( or j u st la u n ch Acce ss w it h ou t ope n in g a da t a ba se file a n d click

The Get t ing St art ed page appears. 2. On t h e r igh t side of t h e w in dow , click t h e folde r icon n e x t t o t h e da t a ba se file n a m e . The New Dat abase dialog box appears. 3. I n t h e " Sa ve a s t ype " list , ch oose " M icr osoft Office Acce ss Pr oj e ct s ( * .a dp) ." 4. Pick t h e folde r w h e r e you w a n t t o pla ce t h e fr on t e n d ( t h e .a dp file ) , t ype a n a m e in t o t h e " File n a m e " box ( lik e ZooAn im a ls.a dp) , a n d t h e n click OK. Access ret urns you t o t he Get t ing St art ed page, wit h your inform at ion in t he New Proj ect pane on t he right side of t he window. 5. Click Cr e a t e t o se a l t h e de a l. Access asks if you want t o use an exist ing SQL Server dat abase. 6. Click N o t o cr e a t e a n e w on e of you r ow n . file:///C|/html/0596527608/access2007tm-CHP-20-SECT-3.html (9 of 10) [1/7/2007 7:16:06 AM]

Section 20.3. Creating a SQL Server Database

A window appears t hat asks you where your server is and what dat abase you want t o creat e. You've seen t his st ep before in t he Upsizing wizard ( Figure 20- 6) . 7. En t e r t h e loca t ion of you r da t a ba se se r ve r a n d t h e n a m e of t h e da t a ba se you w a n t t o cr e a t e , a n d t h e n click Fin ish . Access creat es t he blank SQL Server dat abase ( and your .adp proj ect file) . Aft er a short delay, t he Access window appears wit h an em pt y navigat ion panel. 8. W h e n you 'r e r e a dy t o cr e a t e you r fir st t a ble , j u m p a h e a d t o t h e n e x t se ct ion .

file:///C|/html/0596527608/access2007tm-CHP-20-SECT-3.html (10 of 10) [1/7/2007 7:16:06 AM]

Section 20.4. Adding Objects to a SQL Server Database

20.4. Adding Objects to a SQL Server Database The nicest t hing about t he SQL Server support in Access is t hat it let s you work inside t he fam iliar Access window, even t hough you're dealing wit h a very different dat abase engine. However, you pay a price for t his convenience. As you'll see in t he following sect ions, creat ing dat abase obj ect s for SQL Server isn't quit e as int uit ive as creat ing t hem for Access.

20.4.1. Creating a Table You can creat e a t able in any Access proj ect ( .adp file) , whet her it 's a new dat abase you creat ed from scrat ch or an exist ing one t hat you're working wit h. Eit her way, t he process is t he sam e. Tables Table Design. You can't creat e a SQL Server t able in Dat asheet view. I nst ead, you First , choose Creat e always need t o st art in Design view. You can also edit an exist ing t able in Design view in t he norm al way. Just right - click it , and t hen choose Design View. When t he Design view appears, you'll not ice t hat it looks a bit different t han t he Design view for ordinary Access t ables. Fort unat ely, it st ill works essent ially t he sam e way. You add a list of fields from t op t o bot t om , and configure t he nam e, dat a t ype, and size of each one. ( SQL Server calls t hem colum ns inst ead of fields, but t here's really no difference.) Each field has five colum ns of inform at ion ( Figure 20- 10) for you t o fill out : ● ●







Colu m n N a m e . This colum n ident ifies t he field ( j ust as it does in a norm al Access t able) . To avoid headaches, don't use spaces or special charact ers. D a t a Type . This colum n indicat es what t ype of inform at ion t he field can st ore ( j ust as it does in a norm al Access t able) . However, t he set of field t ypes t hat SQL Server provides is different from t he set t hat Access usesm ore on t hat issue in Sect ion 20.4.1.1. Le n gt h . This colum n corresponds roughly t o t he Field Size propert y in Access ( Sect ion 2.3.1.1) . For a t ext - based dat a t ype, t he lengt h is t he num ber of allowed charact ers. But for m ost dat a t ypes, t he field size is for inform at ion only; it shows t he num ber of byt es of space t hat t he field uses, but it can't be m odified. Allow N u lls. This colum n corresponds t o t he Required field propert y in Access ( Sect ion 4.1.1) . I f a checkm ark is in t his colum n, you're t elling SQL Server t hat blank values are accept able, which m eans t he dat abase user can leave t his field em pt y. D e scr ipt ion . This colum n get s a plain- English descript ion of your field. Fill it in, or not it 's up t o you.

When designing a SQL Server t able, you also need t o specify t he prim ary key ( Sect ion 2.4) . Usually, you'll use a field t hat st ores an aut om at ically generat ed I D num ber. To designat e a field as a prim ary key, click t o select t he field, and t hen choose Tools Prim ary Key. You'll see a key icon appear at t he far left of t he row. Table Tools | Design When you're done working wit h your t able, close it . Access prom pt s you t o save t he t able and pick a nam e. Then you can st art ent ering dat a in t he fam iliar Access dat asheet , which hasn't changed a bit .

file:///C|/html/0596527608/access2007tm-CHP-20-SECT-4.html (1 of 10) [1/7/2007 7:16:16 AM]

Section 20.4. Adding Objects to a SQL Server Database

Figu r e 20-10. This example shows the Design view for the familiar Customers table from the BoutiqueFudge database, SQL Server style.

Note: You'll probably notice that Access projects are slower than ordinary Access database files. That's because Access needs to communicate with SQL Server behind the scenes, asking it to create tables, perform data operations, and so on.

20.4.1.1. SQL Server data types I t would be nice if SQL Server and Access used exact ly t he sam e set of dat a t ypes. However, t hese applicat ions com e from different backgrounds and som et im es t heir differences show. Fort unat ely, t here's a close m apping bet ween m ost dat a t ypes. That m eans m ost Access dat a t ypes have a corresponding SQL Server dat a t ype t hat m at ches pret t y closely. ( And when you upsize a dat abase, Access is usually able t o pick a good m at ch.) Table 20- 1 shows t he SQL Server dat a t ypes t hat you get for various Access dat a t ypes.

Note: SQL Server has still more data types that aren't shown in this table and don't map directly to Access data types. However, the data

file:///C|/html/0596527608/access2007tm-CHP-20-SECT-4.html (2 of 10) [1/7/2007 7:16:16 AM]

Section 20.4. Adding Objects to a SQL Server Database

types shown here are by far the most common.

Ta ble 2 0 - 1 . SQL Se r ve r a n d Acce ss D a t a Type s Com pa r e d Acce ss D a t a Type

SQL Se r ve r Equ iva le n t

Text

nvarchar ( which can hold up t o 4,000 charact ers, unlike t he Access Text dat a t ype, which t ops out at 255 charact ers)

Mem o

nt ext

Num ber ( wit h a Field Size of I nt eger)

sm allint

Num ber ( wit h a Field Size of Long I nt eger)

int

Num ber ( wit h a Field Size of Single)

real

Num ber ( wit h a Field Size of Double)

float

Num ber ( wit h a Field Size of Decim al)

decim al

Num ber ( wit h a Field Size of Byt e)

t inyint

Num ber ( wit h a Field Size of Replicat ionI D)

uniqueident ifier

Dat e/ Tim e

dat et im e

Currency

m oney

Aut oNum ber

int ( wit h I dent it y set t o Yes)

Yes/ No

bit

Hyperlink

nvarchar

At t achm ent

nvarchar ( but only t he file nam e is kept )

20.4.1.2. AutoNumber fields You m ay have not iced t hat SQL Server doesn't have an Aut oNum ber dat a t ype. But don't let t hat fool you int o t hinking t hat t here's no way t o get t his insanely useful feat ure ( Sect ion 2.3.9) in SQL Server. You j ust need t o set it up a bit different ly: 1. W h e n cr e a t in g a n I D fie ld, give it t h e in t da t a t ype . 2. I n t h e Colu m n s t a b u n de r n e a t h t h e fie ld list , se t I de n t it y t o Ye s. An ident it y value is t he SQL Server nam e for an Aut oNum ber field. I t 's a value t hat SQL Server assigns for you aut om at ically, and is guarant eed t o always be unique. 3. You ca n a lso se t t h e I de n t it y Se e d a n d I de n t it y I n cr e m e n t pr ope r t ie s: ❍



I de n t it y Se e d is t he st art ing value. This propert y is a sorely m issed feat ure in Access, which always st art s it s Aut oNum ber values at 1. ( You m ay rem em ber t he com plex workaround in Sect ion 8.3.2.) I de n t it y I n cr e m e n t is t he am ount SQL Server increases in bet ween values. For exam ple, if t he I dent it y I ncrem ent is 5, you m ay see num bers like 1, 6, 11, 16, and so on. Of course, SQL Server is free t o skip over a num ber for a variet y of reasons, j ust like Access does.

20.4.1.3. Lookups The SQL Server Design view lacks t he convenient lookup wizard t hat Access uses. I nst ead, you need t o select t he field where you want t o place t he lookup, click t he Lookup t ab at t he bot t om of t he design window ( Figure 20- 11) , and t hen fill in all file:///C|/html/0596527608/access2007tm-CHP-20-SECT-4.html (3 of 10) [1/7/2007 7:16:16 AM]

Section 20.4. Adding Objects to a SQL Server Database

t he lookup inform at ion. Here are t he key set t ings you need t o creat e a lookup: ● ● ●

D ispla y Con t r ol should be set t o Com bo Boxt hat 's t he drop- down list t hat let s you pick t he value you want . Row Sou r ce Type should be set t o Tables/ Views/ Funct ions if you want t o creat e a lookup t hat uses t he dat a from a relat ed t able. ( I f you j ust want t o supply a list of values, you would use t he Value List opt ion inst ead.) Row Sou r ce provides t he dat a for t he lookup. I f you're drawing your dat a from anot her t able, you'll use a SQL SELECT com m and ( Sect ion 6.2.3) t hat pulls out t wo fieldst he field wit h descript ive inform at ion, and t he field wit h t he I D value. For exam ple, you could use t he com m and SELECT I D,Product Nam e FROM Product s ORDER BY Product Nam e t o creat e a lookup list t hat get s t he I D and t he nam e of each product in t he Product s t able, sort ed by product nam e.

Figu r e 20-11. Here's a completed lookup for the CreditCardID field in the Orders table.

Tip: If you don't want to write the SELECT statement on your own, click in this box, and then click the ellipsis button to open a query window where you can pick your table and fields. This query window is a bit different from the Access query designer you've used so farsee Section 20.4.2 for a quick tour. ●







Bou n d Colu m n ident ifies which colum n ( from t he Row Source) should be insert ed in t he field when you pick a value from t he lookup. For exam ple, if t he first field in your SELECT st at em ent is t he I D value ( as in t he previous exam ple) , you would set t his value t o 1. Colu m n Cou n t set s t he num ber of colum ns t hat show up in t he lookup list . Usually, t his opt ion is set t o 2 ( which shows bot h colum ns) , but t he widt h of t he first colum n wit h t he I D num ber is given an infinit esim ally sm all size so you don't act ually see it . Colu m n H e a ds det erm ines whet her t it les are at t he t op of t he colum ns in t he lookup. Usually, t his value is set t o No. However, if you creat e a lookup t hat shows several pieces of relat ed inform at ion, you can use colum n heads t o m ake it easier t o t ell what 's what when you're reading values in t he lookup list . Colu m n W idt h s set s how big each colum n is in t he lookup list . You separat e each value ( in inches) wit h a sem icolon. For exam ple, a set t ing of 0" ; 1" shrinks t he first colum n out of sight and m akes t he second colum n one inch wide.

Unfort unat ely, creat ing a lookup doesn't creat e a relat ionship bet ween t he t wo t ables. I f you want a relat ionship, you need t o creat e it yourself, as described in t he next sect ion.

Note: When you upsize a database, Access is nice enough to keep all your lookups.

file:///C|/html/0596527608/access2007tm-CHP-20-SECT-4.html (4 of 10) [1/7/2007 7:16:16 AM]

Section 20.4. Adding Objects to a SQL Server Database

20.4.1.4. Relationships As you learned in Chapt er 5, every respect able dat abase has lot s of t able relat ionships. I n Access, you have t wo speedy ways t o build a relat ionship: using t he dat abase diagram t ool, and creat ing a lookup on a field. But in an Access proj ect , neit her one of t hose feat ures are available. I nst ead, you need t o define t he relat ionship by hand in t he design window for your t able. Here's how t o do it : 1. Ope n t h e ch ild t a ble in D e sign vie w . This t able has t he field t hat links t o t he parent t able. ( For exam ple, Product s is in t he child t able of Product Cat egories. The t ip- off is t he Product Cat egoryI D field t hat appears in t he Product s t able.) 2. Ch oose Ta ble Tools | D e sign

Sh ow / H ide

Pr ope r t y Sh e e t .

This act ion pops open t he Propert ies dialog box ( Figure 20- 12) , which looks not hing like t he Propert y Sheet you've used before wit h Access dat abases.

Figu r e 2 0 - 1 2 . Here's a completed relationship that links the OrderDetails table (as the child) to the Products table (as the parent). In each record in the OrderDetails table, the ProductID field points to the product that was ordered.

3. Click t h e Re la t ion sh ips t a b.

file:///C|/html/0596527608/access2007tm-CHP-20-SECT-4.html (5 of 10) [1/7/2007 7:16:16 AM]

Section 20.4. Adding Objects to a SQL Server Database

Click N e w t o de fin e a n e w r e la t ion sh ip. 5. I n t h e list box u n de r t h e h e a din g " Pr im a r y k e y t a ble ," pick t h e pa r e n t t a ble . 6. I n t h e fir st r ow u n de r n e a t h , pick t h e u n iqu e fie ld in t h e pa r e n t t a ble . ( You have several rows here because it 's possible t o creat e relat ionships based on several fields, alt hough it 's rarely done.) 7. I n t h e list box u n de r t h e h e a din g " For e ign k e y t a ble ," pick t h e ch ild t a ble . I n t he first row underneat h, pick t he field in t he child t able t hat point s t o t he linked parent record. 8. I f you w a n t t o ve r ify t h a t e x ist in g da t a live s u p t o t h is r e la t ion sh ip, t u r n on t h e ch e ck box for " Ch e ck e x ist in g da t a on cr e a t ion ." I f you don't want t o check your exist ing records t o m ake sure t hey live up t o t he rules of t his relat ionship, ( Sect ion 5.2.3) leave t his checkbox t urned off. I f you don't have any dat a in t he t able yet , it doesn't m at t er what you choose. 9. Tu r n on t h e ch e ck box n e x t t o " En for ce r e la t ion sh ips for I N SERTs a n d UPD ATEs" if you w a n t t o e n for ce r e la t ion a l in t e gr it y w h e n a ddin g a n d ch a n gin g r e cor ds. Doing so prevent s you from breaking t he relat ionship rules ( Sect ion 5.2.3) when adding or updat ing records. For exam ple, you won't be allowed t o insert a child record t hat point s t o a non- exist ent parent record. I f you choose not t o use relat ional int egrit y, you can use one of t he opt ions below t o swit ch on cascading updat es or delet es ( Sect ion 5.2.3.1) . 10. Close t h e w in dow w h e n you 'r e don e .

20.4.2. Understanding Queries Tables of dat a aren't t he only dat abase obj ect t hat 's st ored in a SQL Server dat abase. Your SQL Server dat abase can also hold queries, t hose endlessly useful rout ines for finding ( and changing) t he records you want . The obj ect s t hat Access fans call queries have a whole different exist ence in SQL Server. Where you see queries, SQL Server sees t hree different t ypes of obj ect s: ● ●



Vie w . A view is roughly equivalent t o a select queryit grabs records ( possibly from relat ed t ables) and displays t hem in a dat asheet . Use r - de fin e d fu n ct ion . A user- defined funct ion is sim ilar t o a select query t hat t akes param et ers. ( As you learned in Sect ion 7.4, param et ers let you ask t he user for a piece of inform at ion j ust before running t he query. You can t hen use t hat inform at ion t o filt er records or perform a calculat ion.) St or e d pr oce du r e . A st ored procedure is t he heavyweight of SQL Server dat abase obj ect s. I t can perform a whole bat ch of t asks, like select ing records, com m it t ing updat es, and running t ransact ions. You won't use m ost of t hat power when you creat e a st ored procedure in Access. I nst ead, you use st ored procedures t o creat e t he SQL Server equivalent of an act ion query ( Chapt er 8) t hat com m it s a single updat e, insert , or delet e operat ion.

I n t he following sect ion, you'll t ry your hand at creat ing a basic view.

20.4.3. Creating a View Creat ing a view is a lot like creat ing a classic Access query t hat select s a bunch of records. The following st eps show you how t o creat e a view and equip it wit h all t he essent ials, including sort ing, filt ering, and expressions: 1. file:///C|/html/0596527608/access2007tm-CHP-20-SECT-4.html (6 of 10) [1/7/2007 7:16:16 AM]

Section 20.4. Adding Objects to a SQL Server Database

Ch oose Cr e a t e

Ot h e r

Qu e r y W iza r d.

The New Query dialog box appears, which offers t o help you creat e a variet y of SQL Server query t ypes. I n t his case, you sim ply want t o creat e an ordinary query t hat ext ract s som e useful dat a. 2. Ch oose D e sign Vie w , a n d t h e n click OK. The Add Table dialog box appears. 3. Ch oose t h e t a ble ( or t a ble s you w a n t t o u se ) , a n d t h e n click Add t o in clu de it in you r qu e r y. W h e n you 'r e fin ish e d, click Close . The query designer appears. Concept ually, it works m ore or less like t he Access query designer, wit h t he sam e feat ures. However, it looks a bit different ( Figure 20- 13) .

Figu r e 20-13. When you add more than one table to a query, and these tables have a relationship defined in the database, the query designer includes the join lines (Section 6.3.1). In this example, the query is showing a list of ordered items, with extra product information from the Products table.

file:///C|/html/0596527608/access2007tm-CHP-20-SECT-4.html (7 of 10) [1/7/2007 7:16:16 AM]

Section 20.4. Adding Objects to a SQL Server Database

Ch oose t h e fie lds you w a n t t o in clu de in you r qu e r y r e su lt s. To include a field in your result s, place a checkm ark next t o t he field. Each field is added t o t he list at t he bot t om of t he window in a separat e row ( Figure 20- 14) . This is sim ilar t o t he Access query designer but flipped around. ( Access creat es one colum n for each field in a query.) At t his point , you have a fully funct ional query. But you m ay also want t o add sort ing, filt ering, and calculat ed expressions, as described in t he following st eps. 5. I f you w a n t t o sor t on a fie ld, ch oose Asce n din g or D e sce n din g in t h e Sor t Type box . I f you want t o sort by m ore t han one field, set t he Sort Type of every field you want t o use. However, you also need t o fill in a num ber in t he Sort Order colum n t o t ell t he query designer which sort t o perform first . For exam ple, if you want t o sort a bat ch of nam es by last nam e and t hen first nam e, you would use t he num ber 1 for t he Sort Order of t he Last Nam e field and t he num ber 2 for t he First Nam e field.

Tip: If you want to use a field for sorting or filtering but you don't want it to appear in the results, just clear the checkmark in the Output box.

Figu r e 20-14. This example shows four fields, all with a checkmark in the Output column, which means they'll be shown in the results table.

6. I f you w a n t t o u se filt e r in g, se t a filt e r e x pr e ssion in t h e Cr it e r ia box n e x t t o t h e a ppr opr ia t e fie ld. Perform ing t his t ask is easy enough for num eric values, because t he filt er expressions are exact ly t he sam e as in Access. You can use t he sam e operat ors ( like t he + , - , / , * signs t o perform calculat ions, and t he = , < , and > signs t o com pare num bers) . However, if you want t o work wit h t ext or dat es, m ake sure you review t he synt ax differences bet ween SQL Server and Access in t he " Synt ax Differences box in Sect ion 20.4.3. You can apply filt ering t o as m any fields as you want . I f you want t o define several different crit eria, and show records t hat

file:///C|/html/0596527608/access2007tm-CHP-20-SECT-4.html (8 of 10) [1/7/2007 7:16:16 AM]

Section 20.4. Adding Objects to a SQL Server Database

m at ch any of t hese crit eria, you can define addit ional filt er expressions in t he Or colum n, as shown in Figure 20- 15.

Figu r e 2015. This field matches any prices that are under $10 or over $50.

7. I f you w a n t t o u se a ca lcu la t e d fie ld, a dd it t o t h e bot t om of t h e list by fillin g in t h e Colu m n a n d Alia s box e s ( Figu r e 2 0 - 1 6 ) . The synt ax for creat ing a calculat ed field is a bit different in t he SQL Server query designer. Rat her t han using t he Colum nNam e: Expression synt ax, you put t he colum n nam e in t he Alias box, and you put t he expression in t he Colum n box. Alt hough you can t ype in your expression using sim ple field nam es, t he query designer convert s t hem t o t hree- part nam es aut om at ically. Figure 20- 16 shows what you'll see if you t ype in t he sim ple calculat ed expression Price* Quant it y, which calculat es t he cost of one line in an order. I f you want t o creat e a calculat ed expression t hat uses t ext or dat es, m ake sure you review t he synt ax differences bet ween SQL Server and Access in t he " Synt ax Differences" box below.

Figu r e 20-16. You'll notice that the field names use strange three-part names (so Price becomes dbo. OrderDetails. Price). This name indicates that the Price field is in a table named OrderDetails, which was created by the database owner (dbo). SQL Server

file:///C|/html/0596527608/access2007tm-CHP-20-SECT-4.html (9 of 10) [1/7/2007 7:16:16 AM]

Section 20.4. Adding Objects to a SQL Server Database

uses these names in expressions to prevent possible ambiguity. But don't worrythe query designer changes ordinary names into three-part names automatically.

W ORD TO TH E W I SE Syn t a x D iffe r e n ce s When you creat e a query using an Access proj ect , your query is act ually a SQL Server dat abase obj ect . I t 's SQL Server t hat st ores it , and it 's SQL Server t hat runs it . This point is im port ant because t he variat ion of SQL ( t he st ruct ured query language; see Sect ion 6.2.3) t hat Access uses is slight ly different from t he flavor you find in SQL Server. This m inor differences can t rip up t he m ost well m eaning query writ ers. Fort unat ely, you can avoid m any headaches j ust by being aware of a few key differences: ❍

❍ ❍

Text values use single quot es, not double quot es. So t o search for a product record by nam e, use 'Maple Magic' not " Maple Magic" . Dat es also use single quot es, not num ber signs. So search for orders placed before '1/ 30/ 2008' not # 1/ 30/ 2008# . When j oining t wo pieces of t ext t oget her, use t he + sym bol, not t he & sym bol. So t o get a full nam e in a calculat ed expression, use First Nam e + ' ' + Last Nam e, not First Nam e &+ " " &Last Nam e.

You can't use Access funct ions. SQL Server has it s own library of funct ions, and while m any of t hem are t he sam e or sim ilar t o t he Access funct ions you know and love, differences abound. The safest approach is t o search for t he funct ion you want t o use in t he SQL Server Books Online reference ( Figure 20- 2 shows how t o download it ) . That way you can check t he funct ion and see if it works t he sam e as it s Access count erpart .

8. W h e n you 'r e fin ish e d de sign in g you r qu e r y, r igh t - click t h e t a b t it le , a n d t h e n ch oose D a t a sh e e t Vie w ( or ch oose Fu n ct ion & Vie w Tools | D e sign Tools Ru n ) . Access will ask you t o save your query. Once you do, you see your result s in t he fam iliar dat asheet , j ust as you do when you run a query in an Access dat abase. You can t hen print or edit t he result s.

file:///C|/html/0596527608/access2007tm-CHP-20-SECT-4.html (10 of 10) [1/7/2007 7:16:16 AM]

Chapter 21. Connecting Access to SharePoint

21. Connecting Access to SharePoint Even in t he m ost dysfunct ional com panies, people need t o get along. Businesses t hat have efficient ways t o share inform at ionwhet her it 's m eet ing agendas, high- priorit y t asks, or int eroffice gossipare m ore successful t han t hose t hat keep quiet . I t m ay have occurred t o you back in Chapt er 18 t hat you can use Access t o share t his sort of inform at ion. All you need t o do is creat e a suit able dat abase, put it in a shared locat ion, and m ake sure everyone has Access inst alled on t heir com put ers. However, you don't need t o go t hrough any of t his work if you use SharePoint , a Microsoft product t hat 's explicit ly designed for office t eam work. Best of all, if your com pany owns Windows Server 2003, it already owns t he basic version of SharePoint , which is all you need. ( A beefed- up version of SharePoint wit h ext ra Office feat ures is also sold under t he nam e Microsoft Office SharePoint Server 2007, or MOSS for short .)

Note: If you don't own a copy of Windows Server 2003, and you'd rather plunk down the near-$1,000 sticker price for an all-inclusive beach vacation, stop reading right now. You're better off designing your own databases for collaboration (see Chapter 18) or using the free version of SQL Server (see Chapter 20).

SharePoint works perfect ly well wit hout Accessin fact , all you need is t he I nt ernet Explorer browser. Using your browser you can log in t o your t eam 's SharePoint sit e, review t he lat est inform at ion, upload docum ent s, and edit list s of dat a. For m ost SharePoint users, t his is m ore t han enough. But if you happen t o have a copy of Access handy, you get t wo m ore opt ions. You can: ●



Tr a n sfe r da t a in t o a n d ou t of Sh a r e Poin t . This t rick is useful if som e people in your com pany use Access and ot hers use SharePoint . Of course, it 's up t o you t o m ake sure you keep everyone's dat a up t o dat e. Use Acce ss a s a fr on t e n d for Sh a r e Poin t . This is t he sam e t echnique you used in Chapt er 20 t o int eract wit h SQL Server. I t let s you work wit h t ables of inform at ion in t he fam iliar Access environm ent but st ore t hese t ables on t he SharePoint server. The advant age is t hat your dat a is available t o m uch larger num bers of people at once, and for t hose who don't have Access, it 's available t hrough t he Web pages on your SharePoint sit e.

I n t his chapt er, you'll learn a bit m ore about SharePoint , and you'll t ry out bot h of t hese t echniques.

Note: Unlike Access, the SharePoint server can handle a practically unlimited number of people. That's because it uses SQL Server under the hood, which is the same high-powered database software you explored in Chapter 20.

file:///C|/html/0596527608/access2007tm-CHP-21.html [1/7/2007 7:16:18 AM]

Section 21.1. Understanding SharePoint

21.1. Understanding SharePoint No, it 's not hipst er slang for t he lat est knit t ing t echnique. SharePoint is a server- based program t hat helps groups of people collaborat e, let t ing t hem share inform at ion and docum ent s t hrough a cent ralized Web sit e. SharePoint is a bit of an oddit y: Even t hough it 's one of t he fast est growing product s in Microsoft 's hist ory, m ost ordinary people have never heard of it , and even it s longt im e fans have a difficult t im e describing what it act ually does. Fort unat ely, t he basic idea behind SharePoint is pret t y st raight forward. First , your t eam get s t oget her and set s up a SharePoint Web sit e. This sit e is host ed on a server com put er on your com pany's net work. As part of t he set up process, you decide who is allowed t o access t he sit e and what t hey'll be allowed t o do.

Tip: Ordinarily, your SharePoint server isn't reachable over the Internet, but if you want people to be able to work from home, you can change that toojust talk to an Internet hosting company.

Once your SharePoint sit e is set up, every t eam m em ber can access it . The login process is sim plej ust fire up I nt ernet Explorer, and t hen surf t o t he t eam sit e. Ordinarily, you don't need t o supply user nam e and password inform at ion, because I nt ernet Explorer aut om at ically logs you in using your current user account ( what ever you used t o log in t o t he net work when you boot ed up your com put er and st art ed t he day) . However, if you need t o use a different user account t o access t he SharePoint server, I nt ernet Explorer will pop up a login box when you visit t he sit e. ( Net work adm inist rat ors are a great help when sort ing out issues like t hese.) When you get t o t he sit e, you see a cust om izable page t hat sum m arizes recent news, upcom ing event s, and useful links ( Figure 21- 1) .

Figu r e 2 1 1 . This example shows an file:///C|/html/0596527608/access2007tm-CHP-21-SECT-1.html (1 of 5) [1/7/2007 7:16:23 AM]

Section 21.1. Understanding SharePoint

ordinary SharePoint site without a drop of customization. You can navigate to the different areas using the panel on the left, or you can use one of the "Add" links (circled) to create a new announcement, appointment, or link. If you add items, other team members can log in and see them.

Note: Microsoft uses thousands of SharePoint sites to coordinate its own teams, including the one that created Access.

file:///C|/html/0596527608/access2007tm-CHP-21-SECT-1.html (2 of 5) [1/7/2007 7:16:23 AM]

Section 21.1. Understanding SharePoint

21.1.1. What You Can Do in SharePoint I t doesn't t ake long t o pick up t he basic feat ures in a SharePoint sit e. You can browse around a SharePoint t eam sit e as you would any ot her Web sit e. Here are som e t hings t hat SharePoint let s you do: ● ● ●

Keep an eye on im port ant dat es using t he t eam calendar. Post m essages on a t eam discussion board. Share Office docum ent s in t he Docum ent Library ( like report s you've writ t en in Word and spreadsheet s from Excel) . Different people can supply edit ed versions, and t eam leaders can rej ect ones t hey don't like.

FREQUENTLY ASKED QUESTION SharePoint Confusion What 's t he deal wit h t hese ot her versions of SharePoint ? The version of SharePoint t hat 's included wit h Windows Server 2003 is t echnically known as Windows SharePoint Services ( t hat 's WSS for t he acronym lovers am ong us) . You m ay have also heard about t wo product s t hat seem suspiciously sim ilar t o Windows SharePoint Services: ❍



M icr osoft Office Sh a r e Poin t Por t a l Se r ve r ( called SPS by t hose in t he know) . This is a non- free product t hat ext ends what SharePoint Services is able t o do. I t s key feat ures are ways t o int egrat e different t eam sit es, t he abilit y t o host personal sit es for each t eam m em ber, and it s support for anot her Microsoft product , BizTalk, which can aut om at e workflow in huge com panies. M icr osoft Office Sh a r e Poin t Se r ve r 2 0 0 7 ( or MOSS) . This is an updat e t o SharePoint Port al Server. I t plays t he sam e role in life, but it has a lit t le razzle- dazzle. I t also adds t he funct ionalit y t hat was previously sold separat ely as Microsoft Cont ent Managem ent Server.

This chapt er focuses squarely on t he SharePoint Services, which provides all t he feat ures t hat you'll use in Access.

● ● ● ●

Assign t asks t o different people and find out when t hey're finished. See a list of everyone who's on your t eam and send out em ails. Share links t o useful Web pages. Creat e and edit list s t hat st ore m iscellaneous dat a ( Figure 21- 2) . For exam ple, you can use a list t o st ore t op cust om er com plains t hat need t o be addressed or t he food it em s t hat em ployees are bringing t o t he com pany pot luck.

file:///C|/html/0596527608/access2007tm-CHP-21-SECT-1.html (3 of 5) [1/7/2007 7:16:23 AM]

Section 21.1. Understanding SharePoint

Figu r e 21-2. This example shows a SharePoint list that duplicates the infamous Dolls table from the Bobblehead database.

The last t ask is where Access com es int o t he pict ure. Even t hough you can creat e and m anage a list of inform at ion in SharePoint t hrough your browser, you m ay want t o use t hat list in Access. Maybe you have a form , query, or code rout ine t hat needs t o t ake t hat inform at ion int o account . Or perhaps you're j ust m ore com fort able edit ing dat a in t he fam iliar Access int erface. file:///C|/html/0596527608/access2007tm-CHP-21-SECT-1.html (4 of 5) [1/7/2007 7:16:23 AM]

Section 21.1. Understanding SharePoint

A SharePoint list is analogous t o an Access t able. Alt hough bot h nam es refer t o t he sam e t hing, a SharePoint list is m ore lim it ed t han an Access t able. I t doesn't support huge am ount s of t ext or validat ion rules. And alt hough it allows lookups, it doesn't let you use relat ionships t o safeguard dat a. What t his m eans is t hat a SharePoint sit e doesn't provide a good place t o st ore crit ical business inform at ion, like cust om er list s, product cat alogs, and invoices. But it 's well suit ed t o inform al list s and ad hoc scraps of inform at ion t hat you need t o pass bet ween colleagues. For exam ple, SharePoint list s are fine for keeping a list of office phone num bers or a signup sheet for t he com pany baseball t eam .

UP TO SPEED Installing SharePoint Before you can creat e a SharePoint sit e, you need t o m ake sure you have t he SharePoint Services soft ware properly inst alled. The full set up process is beyond t he scope of t his book, so if you want t o t ry it out , m ake sure you get t he help of your friendly neighborhood net work adm inist rat or. Here are few guidelines t o help you get ready: ● ●



The first t hing you need t o use SharePoint is a com put er t hat 's running Windows Server 2003. I f you've got t he lat est edit ion ( known as Windows Server 2003 R2, for release 2) , you already have all t he bit s you need. I f you don't have t he lat est release of Windows Server 2003, fear not you're ent it led t o a free add- in t hat inst alls SharePoint Services. Point your web browser t o www.m icrosoft .com / windowsserver2003/ t echnologies/ sharepoint t o get t he download you need. This sit e is also a great place t o st art if you need m ore inform at ion about SharePoint Services, or if you're t roubleshoot ing a wacky problem . The easiest way t o inst all SharePoint is t o run t he Configure Your Server wizard, and choose t he SharePoint Services role. This set s up your server by inst alling several key ingredient s, including I I S ( t he soft ware t hat t ransform s t he com put er int o a Web server) , and ASP.NET ( t he soft ware t hat let s it run dynam ic Web applicat ions, like SharePoint sit es) . Addit ionally, if you don't have t he full version of SQL Server on your com put er, t he Configure Your Server wizard inst alls a scaled- down version t o use for st oring SharePoint dat a.

I f all t his inst allat ion fiddling sounds like t oo m uch work ( or if you don't have a com pany net work t o use) , you m ay be int erest ed in paying som eone t o host SharePoint for you. Firm s are out t here t hat will allocat e a very sm all am ount of space on a high- powered Web server t o st ore your SharePoint list s, docum ent s, and so on. Paying for t his service cost s about as m uch as paying a Web host ing com pany t o host a business Web sit e. I f it sounds t em pt ing, you can sign up for a free 30- day t rial t hat let s you use all t he SharePoint feat ures described in t his chapt er; see www.m icrosoft .com / t echnet / windowsserver/ sharepoint / V2/ t echinfo/ t rial.m spx for t he det ails.

file:///C|/html/0596527608/access2007tm-CHP-21-SECT-1.html (5 of 5) [1/7/2007 7:16:23 AM]

Section 21.2. Setting Up SharePoint

21.2. Setting Up SharePoint Now t hat you know what SharePoint is, you're ready t o t ake it for a whirl. Every SharePoint server st art s out wit h one hom e sit e. Alt hough you can use t he hom e sit e for collaborat ion, m ost people prefer t o creat e addit ional sit es for each separat e t eam . ( Your com pany can have as lit t le as one t eam sit e or as m any as several t housand.)

Tip: You see the home site appear, in Internet Explorer, at the end of the setup process.

21.2.1. Creating a Team Site Here's how you creat e a new t eam sit e: 1. Su r f t o you r Sh a r e Poin t h om e sit e . Rem em ber, SharePoint gives you t he hom e sit e URL at t he end of t he set up process. Or, if you've signed up for a host ed SharePoint sit e, t he host ing com pany will give you t he URL. 2. Click t h e Sit e Act ion s bu t t on ( se e Figu r e 2 1 - 3 ) , a n d t h e n ch oose Sit e Se t t in gs. The sit e m anagem ent page appears, wit h a huge list of opt ions you can change.

file:///C|/html/0596527608/access2007tm-CHP-21-SECT-2.html (1 of 10) [1/7/2007 7:16:29 AM]

Section 21.2. Setting Up SharePoint

Figu r e 2 1 - 3 . The Site Actions button is located at the top-right corner of every SharePoint page. It gives you a quick way to configure the site or create a new item (like a list or a Web page).

3. I n t h e Sit e Adm in ist r a t ion se ct ion , click t h e " Sit e s a n d w or k spa ce s" lin k . A page appears t hat list s all t he sit es and docum ent workspaces on your current SharePoint server. ( Docum ent workspaces let people share files, like Word docum ent s and Excel spreadsheet s. Sit es have t his feat ure t oo, but t hey also have addit ional frills, like list s of announcem ent s and a shared calendar.) You can use t his page t o view one of t he ot her sit es or t o rem ove it . I nit ially, t he list of sit es is em pt y, because a new SharePoint inst allat ion st art s out wit h not hing but a hom e sit e. 4. Click Cr e a t e t o bu ild a n e w sit e . file:///C|/html/0596527608/access2007tm-CHP-21-SECT-2.html (2 of 10) [1/7/2007 7:16:29 AM]

Section 21.2. Setting Up SharePoint

A page appears where you can configure your new sit e ( Figure 21- 4) .

Figu r e 21-4. Here's where you fill in the information for the new Office Temps team site.

5. Fill in a ll t h e sit e in for m a t ion , a n d t h e n click Cr e a t e . ❍ ❍



❍ ❍

Th e Tit le a n d D e scr ipt ion se ct ion det erm ines how your sit e appears on t he m ain page. Th e W e b Sit e Addr e ss se ct ion let s you pick t he URL t hat people will use t o get t o t his t eam sit e. This address has t wo part s: t he hom e sit e URL ( which usually includes t he server nam e) , plus a cust om izable bit at t he end t hat ident ifies t he t eam . Th e Pe r m ission s se ct ion let s you choose how people are aut hent icat ed ( in ot her words, how SharePoint decides whet her it should allow t hem in) . Choose " Use unique perm issions" if you want t o cont rol exact ly who can access t his t eam sit e ( which is t he m ost flexible approach) . Ot herwise, t he perm issions for your new sit e will be t he sam e as t he perm issions for t he hom e sit e. Th e N a viga t ion se ct ion let s you choose whet her a link for t his sit e appears in t he hom e sit e. Th e Te m pla t e se ct ion let s you choose a st art ing point for t he layout of your sit e. The Team Sit e t em plat e is a good choice.

file:///C|/html/0596527608/access2007tm-CHP-21-SECT-2.html (3 of 10) [1/7/2007 7:16:29 AM]

Section 21.2. Setting Up SharePoint

Once you've creat ed t he sit e, you can t weak it t o your heart 's cont ent . 6. Click Cr e a t e . You see an " Operat ion in Progress" m essage while t he sit e is being creat ed. I f you chose " Use unique perm issions" in st ep 3, SharePoint shows a new page where you can choose t he people who are allowed t o use your sit e. 7. Ch oose t h e gr ou ps t h a t a r e a llow e d t o u se t h e sit e ( Figu r e 2 1 - 5 ) . Three levels of people can use a SharePoint sit e: ❍ ❍ ❍

Visit or s can read inform at ion left by ot her people, but t hey can't change anyt hing. M e m be r s are a part of t he t eam . They can edit inform at ion in exist ing list s, but t hey can't creat e new ones. Ow n e r s are super- m em bers. They add and rem ove ot her users, creat e list s, and change sit e set t ings.

To assign t hese different levels of perm ission t o different people, you use groups. Groups are a Windows securit y concept t hat let s you m anage large num bers of people at once. The basic idea is t hat a single group can cont ain as m any people as you need. Best of all, groups are super flexible. When som eone new j oins t he com pany, you don't need t o m odify your SharePoint sit e set t ings. I nst ead, you sim ply add t hat person t o t he right group, and SharePoint knows exact ly what t hey should be allowed t o do.

Figu r e 2 1 - 5 . If you already have a group for visitors, choose "Use an existing group," and then fill in the group name. Otherwise, file:///C|/html/0596527608/access2007tm-CHP-21-SECT-2.html (4 of 10) [1/7/2007 7:16:29 AM]

Section 21.2. Setting Up SharePoint

choose "Create a new group," and then supply a list of user names, separated by semicolons. In this example, a new group named Office Temps Members is being created with four users.

Note: Getting the correct user names and group names is important; Once again, you may need to call in a network administrator. You probably need to indicate the computer or domain that each person uses to log in. So if user jpantalone logs in to the Sales domain, you'd need to add the user name Sales\jpantalone to make that clear to SharePoint. 8. On ce you 've fin ish e d fillin g in t h e u se r in for m a t ion , click OK. This com plet es t he process. Congrat ulat ions! You have a brand new SharePoint t eam sit e t o play wit h ( Figure 21- 6) .

file:///C|/html/0596527608/access2007tm-CHP-21-SECT-2.html (5 of 10) [1/7/2007 7:16:29 AM]

Section 21.2. Setting Up SharePoint

Figu r e 21-6. Depending on the options you chose in the Navigation section (Section 21.2.1), your site may appear in the mini tabs at the top of the SharePoint pages for quick access.

file:///C|/html/0596527608/access2007tm-CHP-21-SECT-2.html (6 of 10) [1/7/2007 7:16:29 AM]

Section 21.2. Setting Up SharePoint

Tip: You can create a new Windows user without leaving the SharePoint setup page. Just click the Create button under one of the user lists. For added convenience, SharePoint can automatically send an invitation email to the lucky new team member, as long as you provide the email address.

21.2.2. Customizing Your Site SharePoint sit es are ridiculously cust om izable. That 's because t hey're act ually built out of num erous self- cont ained com ponent s, which Microsoft calls Web Part s. I f you want t o change t he page, you sim ply need t o add new Web Part s, rem ove exist ing ones, or j ust m ove t hem around t he page. To t ry t his out , head t o t he hom e page for your t eam sit e, and click Sit e Act ions m ode, as shown in Figure 21- 7.

Edit Page. The page swit ches int o edit

Figu r e 2 1 - 7 . In edit mode, you can clearly see the separate regions of your page and where each Web Part is placed. This rather unremarkable page consists of file:///C|/html/0596527608/access2007tm-CHP-21-SECT-2.html (7 of 10) [1/7/2007 7:16:29 AM]

Section 21.2. Setting Up SharePoint

four Web Parts.

Note: When you modify your site in this way, your changes affect everyone. Any site owner can configure a SharePoint team site.

You can change a lot in edit m ode. You can: ● ●



M ove a W e b Pa r t . Just click t he t it le bar ( for exam ple, t he t ext t hat says " Announcem ent s" ) , and t hen drag it t o a new place on t he page. M in im ize a W e b Pa r t . By m inim izing a Web Part , only t he t it le for t he Web Part is shown on t he page, which saves considerable space. I f people using t he page decide t o use t hat Web Part , t hey can sim ply click t he drop- down arrow next t o t he t it le t o spring t he sect ion int o view. Re m ove a W e b Pa r t . Click t he X icon at t he t op- right corner of t he Web Part box t o close it . You can always add it back lat er.

UP TO SPEED Five Fun Features to Try Out in SharePoint The rest of t his chapt er focuses on t he SharePoint feat ures t hat work wit h Accessnam ely, list s. However, you don't need t o st op your SharePoint explorat ion here. I f you're st ill curious, be sure t o check out t he following SharePoint feat ures: ❍







Book a m e e t in g w it h t h e ca le n da r . I n t he Calendar Web Part , click t he " Add new event " link. You can fill in t he t it le, descript ion, locat ion, and t im e for your m eet ing. You can even creat e a workspace t o st ore not es. Ge t im m e dia t e n ot ifica t ion s w it h a n a le r t . Alert s let you not ify people when som et hing in SharePoint changes ( whet her it 's a new event , an assigned t ask, an announcem ent , or som et hing else) . For exam ple, you can add an alert t o t he calendar. Just click Alert Me. You'll be asked t o choose t he t ype of t he " Calendar" t it le t o open up t he calendar view, and t hen choose Act ions changes you're int erest ed in and t he em ail addresses t hat SharePoint should not ify. Sh a r e a docu m e n t . Oft en, t eam s need t o send specificat ions, report s, and ot her business docum ent s t hrough a review chain. SharePoint m akes it easy. Just click t he Shared Docum ent s link in t he navigat ion panel t o head t o t he docum ent cent er, where you can browse what 's already t here and upload your own work. Assign a t a sk . When t here's work t o be done, it helps t o have an efficient way t o coordinat e who's doing what . I n SharePoint , t hat m eans clicking t he Tasks link in t he navigat ion panel t o see t he list s of out st anding j obs. You can creat e and assign new

file:///C|/html/0596527608/access2007tm-CHP-21-SECT-2.html (8 of 10) [1/7/2007 7:16:29 AM]

Section 21.2. Setting Up SharePoint



t asks wit h a wealt h of im port ant t racking inform at ion ( like priorit y, st at us, percent com plet e, st art dat e, due dat e, and even an at t ached file) . Sh a r e con t a ct in for m a t ion . Does your t eam need t o st ay in t ouch wit h t he sam e people? SharePoint has a ready- m ade list , called Cont act s, t hat 's designed j ust for t his purpose. To t ake a look, click Cont act s in t he navigat ion panel.

I f you'd like t o learn m ore about SharePoint , you m ay be int erest ed in a dedicat ed book on t he subj ect , like Essent ial SharePoint by Jeff Webb ( O'Reilly) .





Ch a n ge a W e b Pa r t . Depending on t he Web Part , you can t weak different opt ions, including t he appearance of t he Web Part , t he included elem ent s, it s behavior, and so on. To m odify a Web Part , click t he " edit " but t on at t he t op- right corner of t he Web Part box, and t hen choose Modify Shared Web Part . ( " Shared" m eans t hat a whole t eam of people see t his Web Part , so change it at your own risk.) Figure 21- 8 shows an exam ple. Add a W e b Pa r t . SharePoint has a library of useful Web Part s, as shown in Figure 21- 9. ( And it goes wit hout saying t hat ent erprising program m ers can also creat e t heir own.) To pick a new Web Part , click Add Web Part in t he sect ion of t he page where you want it t o appear.

Figu r e 2 1 - 8 . When you modify a Web Part, a dashed border appears around it. The file:///C|/html/0596527608/access2007tm-CHP-21-SECT-2.html (9 of 10) [1/7/2007 7:16:29 AM]

Section 21.2. Setting Up SharePoint

settings for that Web Part are shown in a panel on the right. In this example, the Site Image Web Part is being outfitted with a new graphic.

file:///C|/html/0596527608/access2007tm-CHP-21-SECT-2.html (10 of 10) [1/7/2007 7:16:29 AM]

Section 21.3. SharePoint and Access

21.3. SharePoint and Access Now t hat you've seen t he whole SharePoint product , you're ready t o hone in on it s list of feat ures. I n a nut shell, SharePoint list s are designed t o help you t rack any kind of m iscellaneous inform at ion t hat you need t o share wit h your t eam . Som e of SharePoint 's key feat ureslike links, announcem ent s t asks, cont act s, and even t he calendarare act ually prem ade list s.

Tip: To see all the lists on a team site, look for the Lists section in the navigation panel on the right. Click the Lists heading in the navigation panel to see a more detailed list of lists (Figure 21-10).

21.3.1. Building a List Creat ing a list using SharePoint 's Web page int erface is j ust as easy as building a t able in Access. Here's how t o do it : 1. Ch oose Sit e Act ion s

Cr e a t e .

The sit e m anagem ent page appears. 2. I n t h e Cu st om List s se ct ion , click t h e Cu st om List lin k . The list creat ion page appears. 3. Su pply a n a m e a n d a de scr ipt ion for you r list .

file:///C|/html/0596527608/access2007tm-CHP-21-SECT-3.html (1 of 25) [1/7/2007 7:16:41 AM]

Section 21.3. SharePoint and Access

Figu r e 21-9. Here, a Web Part is being added to the section named Left. Some of the Web Parts that ordinarily aren't included on the home page for a team site include Site Users (which lists the team members and shows who is currently online), User Tasks (which shows only the tasks that are assigned to the current user), and Team Discussion (which provides a messagefile:///C|/html/0596527608/access2007tm-CHP-21-SECT-3.html (2 of 25) [1/7/2007 7:16:42 AM]

Section 21.3. SharePoint and Access

board-style forum for conversation).

For exam ple, you could creat e a list nam ed Cafet eriaMenuI deas t hat list s t he it em s people would like t o see for sale in t he com pany cant een. Or, use DodgeballTeam Assignm ent t o find out who's going t o square off against t he boss. 4. Ch oose w h e t h e r t h e list sh ou ld a ppe a r in t h e n a viga t ion pa n e l. I f you choose t o place it in t he panel, t he list will be visible on every page. Ot herwise, you'll need t o head t o t he list s sect ion ( click List s) t o find it . 5. Click Cr e a t e . SharePoint creat es t he list and whisks you off t o t he list ent ry page, where you can st art filling it wit h inform at ion ( Figure 21- 11) or change it s st ruct ure. 6. Cr e a t e t h e colu m n s you n e e d for you r list . Every list begins wit h t hree colum ns: Type ( which SharePoint uses t o dist inguish bet ween different t ypes of obj ect s) , At t achm ent s ( which let s you t ack on any files t hat are relat ed t o an it em ) , and Tit le ( a descript ive line of t ext ) . The first t wo are m andat ory, but you can rem ove t he Tit le colum n ( as you'll learn in st ep 7) .

file:///C|/html/0596527608/access2007tm-CHP-21-SECT-3.html (3 of 25) [1/7/2007 7:16:42 AM]

Section 21.3. SharePoint and Access

Figu r e 2110. This page shows all the lists on the site, the number of items in each one, and the last time a change was made.

file:///C|/html/0596527608/access2007tm-CHP-21-SECT-3.html (4 of 25) [1/7/2007 7:16:42 AM]

Section 21.3. SharePoint and Access

Figu r e 21-11. Every time you want to add information to your list or change the structure of the list (by adding or modifying columns), you use this page.

Note: Every SharePoint list actually has several more columns that Access maintains behind the scenes. For example, each list item has a unique, hidden ID, and columns that track who inserted an item and the last time a change was made to it. file:///C|/html/0596527608/access2007tm-CHP-21-SECT-3.html (5 of 25) [1/7/2007 7:16:42 AM]

Section 21.3. SharePoint and Access

To add a colum n, choose Set t ings Creat e Colum n. Fill out all t he inform at ion for t he new colum n, including it s nam e, a descript ion, and t he t ype of dat a ( Figure 21- 12) . You can also set a m axim um lengt h, supply a default value, and indicat e if t he field is required ( and can't be left blank) .

Figu r e 21-12. The data types for SharePoint lists correspond to the Access data types for tables (although you don't have quite as many choices as you get with Access). If you want to draw the values from another table, then create a lookup column and indicate the list that you file:///C|/html/0596527608/access2007tm-CHP-21-SECT-3.html (6 of 25) [1/7/2007 7:16:42 AM]

Section 21.3. SharePoint and Access

want to link to.

Note: SharePoint isn't as strict with relational integrity (Section 5.2.3) as Access. For example, if you create a lookup column that links to another list and you delete that list, then Access simply clears all your linked values. 7. Opt ion a lly, you ca n m odify you r list se t t in gs by click in g Se t t in gs

List Se t t in gs.

This st ep opens t he list set t ings page ( Figure 21- 13) , where you can perform a variet y of useful t une- ups.

Figu r e 2113. The first section of the list settings page has links that let you configure various options. Beneath that is a section that lets you review the file:///C|/html/0596527608/access2007tm-CHP-21-SECT-3.html (7 of 25) [1/7/2007 7:16:42 AM]

Section 21.3. SharePoint and Access

current columns, delete those you don't want, and add new ones. Finally, at the bottom of the page (not shown here) is a section that lets you review the current views and create your own.

GEM I N TH E ROUGH Sh a r e Poin t Vie w s = Acce ss Qu e r ie s file:///C|/html/0596527608/access2007tm-CHP-21-SECT-3.html (8 of 25) [1/7/2007 7:16:42 AM]

Section 21.3. SharePoint and Access

I n SharePoint lingo, a view is a cust om izable way t o look at t he dat a in a list . Views can show a subset of t he full range of colum ns, and t hey can use filt ers t o cut down t he list t o j ust t hose rows t hat int erest you. You can also use sort ing, grouping, and t ot als. I n essence, a SharePoint view plays t he sam e role as t he versat ile Access select query t hat you m ast ered in Chapt er 6.

List Set t ings while you're viewing down t he list . This shows You can creat e new views for your list by choosing Set t ings a page chock- full of list opt ions. Scroll t o t he bot t om t o see t he current list s and add new ones. Newly creat ed list s have only a single view, called t he default view. When you creat e a new colum n, you also see an " Add t o default view" checkbox. The default view is t he view you st art in when you first open t he list . I f you don't add your colum n t o t he default view, you won't see it at all ( unless you creat e a new view t hat includes t he colum n) .

The m ost useful links on t he list set t ings page are: ❍ ❍

❍ ❍

Ge n e r a l se t t in gs let s you m odify t he list inform at ion you supplied in st eps 3 and 4. Adva n ce d se t t in gs let s you cont rol whet her list users are rest rict ed t o reading and m odifying t heir own ent ries. You can also t urn off t he at t achm ent feat ure ( which let s users t ack on t heir own files wit h an it em ) and t he folder feat ure ( which let s users creat e subfolders t o bet t er organize list it em s) . D e le t e t h is list does t he obvious. Pe r m ission s for t h is list let s you cont rol who's allowed t o edit t he list and what t hey're allowed t o do. Ordinarily, t eam sit e owners have full cont rol perm ission ( m eaning t hey can do anyt hing, including changing t he list set t ings) , norm al m em bers have cont ribut e perm ission ( m eaning t hey can add, edit , and delet e it em s) , and visit ors have read perm ission ( m eaning t hey can look only at t he exist ing inform at ion) .

8. On ce you h a ve t h e colu m n s you w a n t , it 's t im e t o e n t e r you r da t a . New I t em . SharePoint shows a page where you can ent er values for all your colum ns To add a new record, click New ( Figure 21- 14) . You can also select an it em t o edit or delet e it .

Note: SharePoint is designed for use by large numbers of people at once (also known as concurrency), so it's quite conceivable that you won't Refresh Data. be the only person editing a list. To see any recent changes and additions made by other people, choose Actions SharePoint's concurrency features are relatively weak. If two people edit the same list item at once, the one who tries to save the change last gets an error message rejecting the edit. (The situation is better if you're using Access to make your edit, as described in Section 21.3.6.)

file:///C|/html/0596527608/access2007tm-CHP-21-SECT-3.html (9 of 25) [1/7/2007 7:16:42 AM]

Section 21.3. SharePoint and Access

Figu r e 2 1 1 4 . Here's a new item for the CafeteriaMenuIdeas list.

GEM IN THE ROUGH The Access Web Datasheet I f you want t o see several list it em s at a t im e and edit t hem all at once in an Access- st yle grid, you can use t he Access Web Dat asheet , a specialized browser plug- in t hat enhances SharePoint . The Access Web Dat asheet is available only if you Edit have Office 2007 inst alled on t he current com put er, unlike t he ot her SharePoint pages. To t ry it you, choose Act ions in Dat asheet from t he list view. The Access Web Dat asheet looks like an ordinary Access dat asheet , em bedded inside your browser. You can m ove from row t o row or colum n t o colum n, m aking changes anywhere, drag colum ns from place t o place, and apply sort ing using t he dropdown arrows next t o t he colum n headers. You can also quickly add or rem ove colum ns ( again, by- right clicking t he colum n headers) . I f you like SharePoint but you m iss t he com fort s of Access, t he Access Web Dat asheet will m ake you feel right at hom e.

21.3.2. Exporting a Table to SharePoint There's anot her way t o build a SharePoint list . You can st art wit h an Access t able and export it t o SharePoint . The disadvant age of t his approach is t hat a bit of conversion is involved t o t urn t he Access dat a t ypes int o SharePoint dat a t ypes. Som e of t he finer point s ( like validat ion rules and input m asks) will be lost , so it 's not wort h cust om izing any of t hese det ails in Access. However, export ing a t able from Access is a great t echnique if you have som e exist ing dat a t hat you need t o t ransfer t o a t eam sit e so m ore people can use it . The SharePoint export process is basically t he sam e as t he export process you learned about in Chapt er 19 for ot her dat a file:///C|/html/0596527608/access2007tm-CHP-21-SECT-3.html (10 of 25) [1/7/2007 7:16:42 AM]

Section 21.3. SharePoint and Access

t ypes. Here's how it works: 1. Ope n you r Acce ss da t a ba se file . 2. Se le ct t h e t a ble you w a n t t o e x por t in t h e n a viga t ion pa n e . I f you export a child t able, Access will also export all t he linked parent t ables aut om at ically. For exam ple, if you export Product s, Product Cat egories com es along for t he ride. 3. Ch oose Ex t e r n a l D a t a

Ex por t

Sh a r e Poin t List fr om t h e r ibbon .

The Export wizard st art s ( Figure 21- 15) . 4. En t e r t h e URL for t h e Sh a r e Poin t t e a m sit e , t h e t it le you w a n t t o u se for t h e list , a n d ( opt ion a lly) a de scr ipt ion . These list set t ings are t he basic ones you learned about in Sect ion 21.3. 5. I f you w a n t t o se e t h e list in Sh a r e Poin t w h e n t h e pr oce ss is fin ish e d, ch oose " Ope n t h e list w h e n fin ish e d." I t 's always a good idea t o review your list aft er a t ransfer operat ion t o m ake sure it worked as you expect ed.

file:///C|/html/0596527608/access2007tm-CHP-21-SECT-3.html (11 of 25) [1/7/2007 7:16:42 AM]

Section 21.3. SharePoint and Access

Figu r e 21-15. In this example, Access is poised to copy the contents of the Customers table to SharePoint.

6. Click OK. I f you need a password t o access your SharePoint sit e, you need t o supply it now. Then, Access creat es t he new SharePoint list and fills it wit h dat a. Your Access dat abase is not m odified in any way. file:///C|/html/0596527608/access2007tm-CHP-21-SECT-3.html (12 of 25) [1/7/2007 7:16:42 AM]

Section 21.3. SharePoint and Access

I f you chose " Open t he list when finished" in st ep 4, Access launches a browser window t o show you t he new list when t he process is com plet e ( Figure 21- 16) . When t he export is finished, Access asks if you want t o save your export st eps. I f you do, you can repeat t he sam e export operat ion lat er on ( presum ably, t o m ove t he lat est copy of your dat a t o t he server) . You learned about t his feat ure in Sect ion 19.3.7.

Note: When you export your data to SharePoint, you create a copy of that data. That means if someone edits the SharePoint list, your database won't get the change. Similarly, if you change the database, it won't appear in SharePoint unless you export it all over again. If this isn't what you want, consider storing the data in SharePoint and managing it in Access through linked tables (Section 19.3.2). The next section has more about this approach.

21.3.3. Importing Data in Access To im port inform at ion int o Access, you have t wo opt ions. You can use t he im port process t hat you learned about in Chapt er 19. This let s you save t he im port st eps so you can repeat t hem lat er on. However, t here's anot her opt ion t hat 's m ore convenient , because it doesn't require you t o supply t he SharePoint list URL. You can perform t he export st raight from t he SharePoint t eam sit e.

Figu r e 21-16. Here's the exported Access Customers table, as a SharePoint file:///C|/html/0596527608/access2007tm-CHP-21-SECT-3.html (13 of 25) [1/7/2007 7:16:42 AM]

Section 21.3. SharePoint and Access

list. When Access opens the list for you to review, Access automatically uses the Access Web DataSheet view (Section 21.3.2), which makes it look more like the Access datasheet interface.

Note: This option is available only if you have Access installed on the current computer. If you surf to the SharePoint Web pages on someone else's computer and it doesn't have Access, you can't perform the export.

file:///C|/html/0596527608/access2007tm-CHP-21-SECT-3.html (14 of 25) [1/7/2007 7:16:42 AM]

Section 21.3. SharePoint and Access

Here's how t o do it : 1. Usin g t h e Sh a r e Poin t t e a m sit e , br ow se t o t h e list you w a n t t o e x por t . 2. Ch oose Act ion s

Ope n w it h M icr osoft Acce ss.

A pop- up window appears t hat let s you choose t he dat abase and whet her you're copying or linking t he inform at ion ( Figure 21- 17) . 3. En t e r t h e n a m e of t h e da t a ba se you w a n t t o u se . I f you specify a dat abase file t hat doesn't exist , Access creat es it . ( This is t he usual approach.) I f you specify a dat abase t hat does exist , Access adds t he t able t o it . 4. Ch oose w h e t h e r you w a n t t o im por t a copy of t h e list or cr e a t e a lin k e d t a ble . Wit h a linked t able, t he dat a is always st ored in SharePoint . You sim ply use Access t o m odify it . That way, only one copy of t he inform at ion exist s, and everyone's changes are m ade in t he sam e place.

Figu r e 2 1 - 1 7 . In this example, the CafeteriaMenuIdeas table is being exported from the SharePoint site. Access isn't even open yet.

file:///C|/html/0596527608/access2007tm-CHP-21-SECT-3.html (15 of 25) [1/7/2007 7:16:42 AM]

Section 21.3. SharePoint and Access

Wit h a copy, you have t wo separat e set s of dat a t hat can be changed independent ly ( t he SharePoint list , and t he t able in your dat abase) . You can't synchronize t hese t wo pieces. The advant age of t his opt ion is t hat you don't need t o keep connect ing t o t he SharePoint server t o apply your changes. 5. W h e n you 'r e fin ish e d, click OK. Access opens on your com put er, wit h t he dat abase you picked in st ep 3. You m ay be prom pt ed t o log in t o SharePoint again. Then, t he linked or copied t able is creat ed and appears in your dat abase ( Figure 21- 18) .

Figu r e 21-18. Now you can edit the Cafeteria Menu Ideas table right in Access. The "Online with SharePoint" message in the bottomright corner of the status bar indicates that all is wellyou can make changes, and they'll be saved on the server immediately. file:///C|/html/0596527608/access2007tm-CHP-21-SECT-3.html (16 of 25) [1/7/2007 7:16:42 AM]

Section 21.3. SharePoint and Access

Along wit h t he t able you picked ( in st ep 1) , SharePoint also export s a t able nam ed User I nform at ion List , which appears in your dat abase. This t able list s t he m em bers of your SharePoint sit e. That 's im port ant because every SharePoint list has t wo hidden fields ( Creat ed By and Modified By) t hat indicat e who creat ed and last m odified an it em . You don't need t o worry about t hese det ails, because Access m aint ains t hem aut om at ically ( alt hough you can see t hem in t he dat asheet using t he Records More Unhide Colum ns com m and) . Hom e When you st art using your dat abase, you not ice a " Publish t o SharePoint Sit e" but t on in a m essage bar at t he t op of your window ( Figure 21- 18) . Click t his but t on t o save a copy of your Access dat abase file in t he Docum ent Library in t he SharePoint sit e, where ot her people can download it .

Note: SharePoint doesn't support Access forms and reports. You can add these objects to your data-base, but people who use the SharePoint Web pages won't have any way to use them. If you want to share your forms and reports, you need to hand out copies of your linked database to other people who have Access, or use the Publish to SharePoint Site button. If you don't want to share your database's front end, there's no reason to use this feature.

21.3.4. Move a Whole Database to SharePoint Why st op at a single t able? Using Access, you can convert an ent ire dat abase t o a set of SharePoint list s. This is a great way t o upsize your dat abase. For exam ple, if you have a successful dat abase t hat 's being used in your com pany but you want t o m ake sure it can handle m ore people ( including t hose who don't have Access) , it m akes good sense t o hand it off t o SharePoint . You first saw how t o upsize a dat abase in Chapt er 20, when you used t his t echnique t o m ove Access t ables t o SQL Server. You can upsize t o SQL Server in m uch t he sam e way using t he Move t o SharePoint wizard, which does t he following j obs: ● ● ● ●

Creat es a backup of your dat abase ( j ust in case you want t o get back t o t he original, non- SharePoint version) . Creat es a SharePoint list for every t able in t he dat abase. Rem oves your t ables and replaces t hem wit h linked t ables t hat get t heir inform at ion from SharePoint . That way, all t he dat a is in t he capable hands of t he SharePoint server. Opt ionally uploads a copy of t his convert ed dat abase t o t he SharePoint sit e. Ot her Access users m ay want t o use t his dat abase if t hey need your queries, form s, report s, or code rout ines.

The following sequence of st eps walks you t hrough t he whole process: 1. I n Acce ss, ope n t h e da t a ba se you w a n t t o con ve r t . 2.

file:///C|/html/0596527608/access2007tm-CHP-21-SECT-3.html (17 of 25) [1/7/2007 7:16:42 AM]

Section 21.3. SharePoint and Access

Ch oose Ex t e r n a l D a t a

Sh a r e Poin t List s

M ove t o Sh a r e Poin t .

The wizard st art s ( Figure 21- 19) .

Figu r e 21-19. This onestep wizard makes it easy to transfer a whole database worth of information to SharePoint.

3. En t e r t h e URL for you r Sh a r e Poin t t e a m sit e . 4. I f you w a n t t o give Acce ss u se r s t h e opt ion t o u se you r for m s a n d r e por t s, se le ct t h e " Sa ve a copy of m y da t a ba se t o t h e Sh a r e Poin t sit e " opt ion . file:///C|/html/0596527608/access2007tm-CHP-21-SECT-3.html (18 of 25) [1/7/2007 7:16:42 AM]

Section 21.3. SharePoint and Access

That way, ot her people can download your dat abase and use t he ot her obj ect s it cont ains. You have no synchronizat ion problem s here, because t he uploaded dat abase uses linked t ables. That m eans all t he dat a is always st ored on t he SharePoint server, regardless of whet her you're m odifying it in Access or t hrough t he SharePoint Web pages. I f you don't want t o bot her wit h t his st ep ( perhaps your dat abase has only t ables, or no one else in your com pany uses Access anyway) , clear t he checkbox, and skip t o st ep 6. 5. Click Br ow se , a n d t h e n pick w h e r e t h e u ploa de d copy of you r da t a ba se sh ou ld be st or e d. I f you haven't creat ed any new docum ent libraries j ust for t his purpose, t hen you need t o select t he com m unal Shared Docum ent s sect ion. Unt il you m ake a select ion, t he Next but t on will be disabled. 6. Click N e x t . I f you need a password t o access your SharePoint sit e, you need t o supply it now. Then, Access begins t he t ransfer process, which can t ake som e t im e for a large dat abase. A progress indicat or will keep you up t o dat e on how m uch of t he j ob rem ains. When Access finishes, you see a final confirm at ion window. 7. Click Sh ow D e t a ils t o se e e x a ct ly w h a t Acce ss did ( Figu r e 2 1 - 2 0 ) . I f any problem s occur during t he conversion process, Access creat es a t able nam ed Move t o SharePoint Sit e I ssues. Each record in t hat t able describes a problem and t he reason why it occurred.

Note: SharePoint doesn't support strict referential integrity (Section 5.2.3). If you publish a database that uses this feature, you end up with a few warning messages in the "Move to SharePoint Site Issues" table.

file:///C|/html/0596527608/access2007tm-CHP-21-SECT-3.html (19 of 25) [1/7/2007 7:16:42 AM]

Section 21.3. SharePoint and Access

Figu r e 21-20. In this example, Access generated eight lists, created a backup copy of the database, and published the database to the Shared Documents location. Access also noted a few problems in the "Move to SharePoint Site Issues" table. (These are simply warnings about SharePoint's lack of support for referential integrity; see Section 5.2.3 for file:///C|/html/0596527608/access2007tm-CHP-21-SECT-3.html (20 of 25) [1/7/2007 7:16:42 AM]

Section 21.3. SharePoint and Access

details.)

8. Click Fin ish . You'll not ice t hat your dat abase has been changed. All t he t ables have been changed t o linked t ables t hat connect t o t he corresponding SharePoint list s. ( The t ellt ale sign is t he yellow t able- wit h- an- arrow icon t hat appears next t o each t able in t he Access navigat ion pane.)

GEM IN THE ROUGH SharePoint List Options Access gives you easy access t o a few com m on SharePoint set t ings. To see t hem , right - click a linked t able, and choose t he SharePoint List Opt ions subm enu. You see com m ands t hat let you m odify t he t able, t weak it s perm issions, or set up alert s t hat not ify you when cert ain dat a is changed. When you choose one of t hese opt ions, Access launches your Web browser, and point s it t o t he appropriat e SharePoint page.

21.3.5. Editing Your SharePoint Data in Access Whenever you com m it a change in a linked t able ( for exam ple, by m aking an edit and m oving t o anot her row) , Access sends t he new values t o t he SharePoint server. The only t hing you aren't allowed t o do is m odify t he design of t he t able. To do t hat , you need t o use SharePoint . ( One quick way t o j um p t o t he right Web page is t o right - click t he t able in Access, and t hen Modify Colum ns and Set t ings.) choose SharePoint List Opt ions

Tip: You can use the Home

Records

Refresh All command to show the latest information in your datasheet at any time.

I f you're unlucky, you can m odify a record at t he sam e t im e t hat som eone else is changing it . I f you com plet e your edit first , you won't be aware of t he conflict . ( I nst ead, t he ot her person's change will be rolled back.) But if you're caught on t he losing side and you com plet e your change aft er t he record has already been m odified by som eone else, you'll get t he m essage shown in Figure 21- 21, which let s you decide what t o do.

file:///C|/html/0596527608/access2007tm-CHP-21-SECT-3.html (21 of 25) [1/7/2007 7:16:42 AM]

Section 21.3. SharePoint and Access

Figu r e 2 1 - 2 1 . This message tells you that someone else has already modified the record you're using. You can click Save Record to blindly overwrite the other person's changes (which is always a risky move), or Drop Changes to cancel your edits. But the most interesting choice is Copy to Clipboard, which copies your values to the Windows clipboard and cancels your edit. You can then look over the current record and paste back part or all of your changes.

Tip: When you use Copy to Clipboard, Access copies the entire row. If you want to paste just a couple values, you can paste the whole selection in another program (like a text editor), and then copy only the value you need.

21.3.6. Making Offline Changes One drawback when you're using linked t ables is t hat you need t o be able t o connect t o t he SharePoint server. I f you need t o m ake changes in a pinchfor exam ple, when you're using a lapt op at hom e, or when an elect rical st orm wreaks havoc wit h your net workyou're out of luck. Or are you? I t t urns out t hat SharePoint gives linked t ables a boost wit h an ext ra feat ure for using SharePoint even while disconnect ed. Wit h t his feat ure, you can use your linked t ables offline, m ake changes, and t hen apply t hem lat er t he next t im e you connect . To t ake your dat abase offline, select Ext ernal Dat a SharePoint List s Work Offline. You've now separat ed yourself from t he server. You won't see ot her people's changes, and t hey won't see yours. When your t able is offline, t he edit ing icon rem ains next t o each record you change ( Figure 21- 22) . That indicat es t hat t he t able is st ill in edit m ode, because t he changes have yet t o be applied t o t he SharePoint server.

file:///C|/html/0596527608/access2007tm-CHP-21-SECT-3.html (22 of 25) [1/7/2007 7:16:42 AM]

Section 21.3. SharePoint and Access

Figu r e 21-22. In this example, two new records have been added, and one has been changed. The ID value of each new record is temporarily set to a negative number, because Access won't get this information until it connects to the SharePoint server and asks it to generate a new value. The editing icons file:///C|/html/0596527608/access2007tm-CHP-21-SECT-3.html (23 of 25) [1/7/2007 7:16:42 AM]

Section 21.3. SharePoint and Access

(circled) indicate that those three tables are still in edit mode.

I n disconnect ed m ode, you have t hree opt ions t o reconnect t o SharePoint : ●





Ch oose Ex t e r n a l D a t a Sh a r e Poin t List s Syn ch r on ize t o get t he lat est dat a and apply any changes you've m ade. When t he process is finished, you're st ill in disconnect ed m ode. Ch oose Ex t e r n a l D a t a Sh a r e Poin t List s W or k On lin e t o synchronize your dat abase, and t hen swit ch back int o connect ed m ode. Ch oose Ex t e r n a l D a t a Sh a r e Poin t List s D isca r d Ch a n ge s t o abandon your changes. You have t wo subopt ions: Use Discard All Changes t o sim ply t oss out what you've done, and use Discard All Changes and Refresh t o discard your changes, and t hen get t he m ost recent inform at ion from SharePoint . Eit her way, you rem ain in disconnect ed m ode.

When you reconnect t o SharePoint , Access t ries t o apply all t he changes you m ade while you were disconnect ed, one at a t im e. This process works perfect ly well unt il it finds a record t hat 's already been m odified by som eone else. This is a problem , because Access doesn't know if it should carry on wit h your m odificat ions and oblit erat e som eone else's work, or leave t he record in a pot ent ially inconsist ent st at e. Access handles t his conflict in a nicer way t han ordinary connect ed- m ode conflict s ( Figure 21- 21) . Rat her t han j ust t ell you t hat a problem has occurred, it act ually shows you t he values t hat conflict . For exam ple, in Figure 21- 23 you can see t hat t he current user rem oved t he period from t he end of t he Rat ionale field while anot her user added an " s" t o t he word " Chocolat es." That leaves t wo fields wit h conflict ing values.

Figu r e 212 3 . In this example, Access discovers a record that's already been modified file:///C|/html/0596527608/access2007tm-CHP-21-SECT-3.html (24 of 25) [1/7/2007 7:16:42 AM]

Section 21.3. SharePoint and Access

by someone else. You have two choices: Discard My Changes to keep the record as is, or Retry My Changes to apply your edits, even if they overwrite the most recent edits.

Note: The disconnected changes feature works best if you use it for short periods of time only. That's because there's a risk that your changes will clash with someone else's. Access catches these problems the next time you synchronize your database (Figure 21-23), but resolving them isn't always easy. If possible, don't make changes while disconnected.

file:///C|/html/0596527608/access2007tm-CHP-21-SECT-3.html (25 of 25) [1/7/2007 7:16:42 AM]

Part VII: Appendix

Part VII: Appendix Appe n dix : Cu st om izin g t h e Qu ick Acce ss Toolba r

file:///C|/html/0596527608/access2007tm-PART-VII.html [1/7/2007 7:16:43 AM]

Appendix A. Customizing the Quick Access Toolbar

A. Customizing the Quick Access Toolbar I n previous versions, Access let it s fans m ove t oolbars, rearrange but t ons, and even scram ble t he order of it em s in t he m ain m enu. Reckless cust om izers could t ransform Access so com plet ely t hat no one else would be able t o use t heir com put ers, and t he inst ruct ions in books like t his one would be useless. Access 2007 clam ps down on cust om izat ion. Unless you're willing t o get your hands dirt y wit h a serious program m ing language, t he ribbon's off lim it s. I nst ead, Access let s you cust om ize one t iny port ion of screen real est at et he Quick Access t oolbar. This lim it at ion m ay sound like a m aj or one, but it 's act ually a reasonable com prom ise. People who love t o t weak and refine t heir workplaces ( you know who you are) get t o add all t he t im esaving short cut s t hey need. Everyone else can relax. No m at t er what com put er you're working on, t he ribbon's always t here, wit h it s com fort ing uniform it y and carefully organized t abs.

Note: You can add a tab of your own to the ribbon. However, the process is definitely not easyin fact, it's aimed at experienced programmers who aren't intimidated by serious code. The standard for customizing the ribbon is called RibbonX, and it requires a blend of XML and a hard-core programming language like C#. Gearheads can get started with the introduction at http://msdn2.microsoft.com/en-us/library/ms406046.aspx.

file:///C|/html/0596527608/access2007tm-APP-A.html [1/7/2007 7:16:45 AM]

Section A.1. The Quick Access Toolbar

A.1. The Quick Access Toolbar You've already seen t he Quick Access t oolbar ( known t o Access nerds as t he QAT) . I t 's t he m icro- sized t oolbar t hat sit s above t he ribbon. The Quick Access t oolbar has only icons, but you can hover over a but t on if you want t o see a label describing what it does. When you first st art out wit h Access, t he Quick Access t oolbar's a lonely place, wit h but t ons for quickly saving t he current dat abase obj ect and undoing or redoing t he last act ion ( Sect ion 1.3.1) . However, Access gives you com plet e cont rol over t his space, including t he abilit y t o add new but t ons. The quickest way t o add but t ons is by clicking t he downward- point ing arrow shown in Figure A- 1.

Figu r e A- 1 . When you click the drop-down arrow on the Quick Access toolbar, Access shows a list of oftenused commands that you can add just by clicking them. These commands include ones for creating a new database, opening an existing database, sending the current database object (the one that's selected in the navigation pane) to the printer with no questions asked, emailing the data from the current database object, and firing up the spell checker. But to see all your possibilities, you need to choose More Commands.

Note: If you don't like the Quick Access toolbar's placement, Access gives you one other option. Click the drop-down arrow, and then choose Show Below the Ribbon to move your toolbar under the ribbon so your mouse has less distance to travel.

You can add but t ons t o t he Quick Access t oolbar for t wo reasons: ● ●

To m a k e it e a sie r t o ge t t o a com m a n d you u se fr e qu e n t ly. I f it 's in t he Quick Access t oolbar, t hen you don't need t o m em orize a keyboard short cut or swit ch t o a different t ab in t he ribbon. To ge t t o a com m a n d t h a t t h e r ibbon doe sn 't pr ovide . Access has a sm all set of unpopular com m ands t hat it let s you use but t hat it doesn't keep in t he ribbon. Many of t hese com m ands are holdovers from previous versions of Access. I f you have a long- lost favorit e Access feat ure t hat 's m issing, it j ust m ay be available using t he Quick Access t oolbar's ext ra but t ons. ( The next sect ion shows you how t o peruse t he full com plem ent of available but t ons.)

Keyboard lovers can also t rigger t he com m ands in t he Quick Access t oolbar wit h light ning speed, t hanks t o Access's KeyTips feat ure ( Sect ion 3.2.1) . When you press t he Alt key, Access displays a num ber superim posed over every com m and in t he Quick Access t oolbar ( st art ing at 1 and going up from t here) . You can t hen press t he num ber t o t rigger t he com m and. So in t he Quick Access t oolbar shown in Figure A- 1, Alt + 1 saves t he current ly open dat abase obj ect , Alt + 2 t riggers t he Undo com m and, and so on.

Tip: If you want to add a command that duplicates something that's already in the ribbon, here's a shortcut: Find the command in the ribbon, right-click it, and then choose Add to Quick Access Toolbar.

file:///C|/html/0596527608/access2007tm-APP-A-SECT-1.html (1 of 4) [1/7/2007 7:16:49 AM]

Section A.1. The Quick Access Toolbar

A.1.1. Adding Buttons To add a but t on t o t he Quick Access t oolbar, follow t hese st eps: 1. Click t h e dr op- dow n a r r ow on t h e Qu ick Acce ss t oolba r , a n d t h e n ch oose M or e Com m a n ds. The Access Opt ions dialog box opens and posit ions you at t he Cust om ize sect ion ( Figure A- 2) .

Figu r e A- 2 . The Customize section of the Access Options window has two areas. The list on the left lets you choose the command you want to add. The list on the right shows the commands that currently appear in the Quick Access toolbar.

2. Ch oose a ca t e gor y fr om t h e " Ch oose com m a n ds fr om " list . The library of com m ands t hat you can add t o t he Quick Access t oolbar is enorm ous. To m ake it easier t o find what you want , Access divides your choices int o a collect ion of cat egories. Many of t he cat egories overlapAccess sim ply provides t hem t o m ake finding what you want easier. Here are t he t op choices: ❍





Popu la r Com m a n ds gives you a short list of com m ands t hat Access j ockeys love. I f you're t rying t o get quick access t o a com m only used feat ure, you'll probably find it here. Com m a n ds N ot in t h e Ribbon provides all t he left overscom m ands t hat Microsoft didn't consider useful enough t o include in t he ribbon. This list holds som e com m ands t hat are superseded or part ially duplicat ed by ot her com m ands, com m ands t hat are included in ot her dialog boxes, and com m ands t hat were used in previous versions of Access and put out t o past ure in t his release. All Com m a n ds includes t he full list of choices. As wit h t he ot her cat egories, it 's ordered alphabet ically.

file:///C|/html/0596527608/access2007tm-APP-A-SECT-1.html (2 of 4) [1/7/2007 7:16:49 AM]

Section A.1. The Quick Access Toolbar



M a cr os shows all t he m acros in t he current ly open dat abase. However, t here's a problem here: I f you add a m acro com m and t o t he Quick Access t oolbar, it won't work in ot her dat abases because t hey don't have t he sam e m acro. The solut ion is t o use anot her Access feat ure t hat let s you cust om ize how t he Quick Access t oolbar appears in specific dat abases. Full det ails are in Sect ion A.1.2.

Under t hese cat egories are several addit ional cat egories t hat correspond t o t he Office m enu and various t abs in t he ribbon. For exam ple, you can choose t he Creat e t ab t o see all t he com m ands t hat appear in t he ribbon's Creat e t ab. 3. On ce you 've ch ose n t h e ca t e gor y you w a n t , pick t h e com m a n d fr om t h e list be low , a n d t h e n click Add. The com m and m oves from t he list on t he left t o t he list on t he right , placing it on t he Quick Access t oolbar ( Figure A- 3) . 4. You ca n r e pe a t t h is pr oce ss ( st a r t in g a t st e p 2 ) t o a dd m or e com m a n ds. Opt ionally, you can rearrange t he order of it em s in t he Quick Access t oolbar. Just pick a com m and, and t hen use t he up and down arrow but t ons t o m ove it . The t opm ost com m ands in t he list are displayed t o t he left on t he Quick Access t oolbar.

Tip: If you've customized the heck out of your Quick Access toolbar and want to go back to a simpler way of life, just click the Reset button. 5. W h e n you 'r e fin ish e d, click OK t o r e t u r n t o Acce ss w it h t h e r e va m pe d Qu ick Acce ss t oolba r . Adding a Quick Access t oolbar isn't a lifet im e com m it m ent . To get rid of a com m and you don't want anym ore, right - click it , and t hen choose Rem ove from Quick Access Toolbar.

Figu r e A- 3 . In this example, the Export to Excel spreadsheet command is being added to the Quick Access toolbar, so you can speedily export the contents of the current table without rifling through the ribbon.

file:///C|/html/0596527608/access2007tm-APP-A-SECT-1.html (3 of 4) [1/7/2007 7:16:49 AM]

Section A.1. The Quick Access Toolbar

Note: You may notice the tempting Modify button, which lets you change a command's name and picture. Unfortunately, it works only for macro commands.

A.1.2. Customizing Specific Databases Do you have a but t on or t wo t hat you're using incessant ly, but j ust for a specific dat abase? I n t his sit uat ion, it m ay not m ake sense t o cust om ize t he Quick Access t oolbar in t he norm al way. I f you do, t hen you'll get your ext ra but t ons in every dat abase you use, including t hose where t he com m ands aren't useful. Access has a great feat ure t o help you out in t his sit uat ion. You can cust om ize t he Quick Access t oolbar for an individual dat abase. That way, whenever you open t hat dat abase, t he but t ons you need appear in t he Quick Access t oolbar. When you close it ( or open anot her dat abase in a separat e window) , t he but t ons disappear.

Note: Customizing individual databases has advantages and disadvantages. The disadvantage is that you need to perform this task separately for every database, which can take a lot of time. The advantage is that your customizations are recorded right in your database file. As a result, they stick around even if you open the database on someone else's computer.

To cust om ize t he t oolbar for a single dat abase, you follow t he sam e st eps t hat you used in t he previous sect ion. St art by clicking t he Quick Access t oolbar's drop- down arrow, and t hen choose More Com m ands. However, before you add any com m ands, change t he select ion in t he " Cust om ize Quick Access Toolbar" drop- down m enu, which appears j ust above t he list of com m ands in t he Quick Access t oolbar. I nst ead of using " For all docum ent s ( default ) " , choose your dat abase's nam e ( as in " For C: \ MyFiles\ Secret Sant a.accdb" ) . This list st art s off em pt y. Then, follow t he norm al st eps t o add but t ons. When Access displays t he Quick Access t oolbar, it com bines t he st andard but t ons ( as configured in t he previous sect ion) wit h any but t ons you've defined for t he current dat abase. Figure A- 4 shows an exam ple.

Figu r e A- 4 . The databasespecific buttons (circled) always appear after the standard buttons and have a slightly different appearance (a darker background).

Cust om izing t he Quick Access t oolbar for a specific dat abase is a useful t rick. I t m akes great sense wit h m acros, because it let s you creat e a single dat abase t hat has a useful set of m acros and handy but t ons for running t hem . For exam ple, you could creat e m acros t hat show specific form s in your dat abase, and t hen add t hem t o t he Quick Access t oolbar. That way, t he user can zip around your dat abase wit hout using t he navigat ion pane.

file:///C|/html/0596527608/access2007tm-APP-A-SECT-1.html (4 of 4) [1/7/2007 7:16:49 AM]

Colophon

Colophon Sanders Kleinfeld was t he product ion edit or for Access 2007: The Missing Manual. Mary Brady and Marlowe Shaeffer provided qualit y cont rol. Lucie Haskins wrot e t he index. The cover of t his book is based on a series design originally creat ed by David Freedm an and m odified by Mike Kohnke, Karen Mont gom ery, and Fit ch ( www.fit ch.com ) . Back cover design, dog illust rat ion, and color select ion by Fit ch. David Fut at o designed t he int erior layout , based on a series design by Phil Sim pson. This book was convert ed by Abby Fox t o Fram eMaker 5.5.6. The t ext font is Adobe Minion; t he heading font is Adobe Form at a Condensed; and t he code font is LucasFont 's TheSans Mono Condensed. The illust rat ions t hat appear in t he book were produced by Robert Rom ano and Jessam yn Read using Macrom edia FreeHand MX and Adobe Phot oshop CS.

file:///C|/html/0596527608/colophon.html [1/7/2007 7:16:51 AM]

Index

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

file:///C|/html/0596527608/index.html [1/7/2007 7:16:55 AM]

SYMBOL

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] - (hyphen) 2nd " (quotation marks) 2nd # (pound sign) #Error code & (ampersand) 2nd ' (apostrophe) ( ) (parentheses) function parameters and functions and math operations and subroutines and .(period) modules and 2nd XML tags and * (asterisk) delete queries inserting records required fields and selecting fields for queries validating text + (plus sign) 2nd … (ellipsis) conditions and Input Mask wizard ready-made masks Visual Basic editor and 3-D charts : (colon) ; (semicolon) email addresses and input masks and SQL and

file:///C|/html/0596527608/SYMBOL.html (1 of 2) [1/7/2007 7:16:57 AM]

SYMBOL

< (less-than sign) 2nd (angle brackets) assignment statements and conditions and expressions and not-equal-to operator 2nd XML tags > (greater-than sign) 2nd ? (question mark) [] (square brackets) functions and spaces in field names 2nd \ (backslash) 2nd

file:///C|/html/0596527608/SYMBOL.html (2 of 2) [1/7/2007 7:16:57 AM]

A

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] Abs( ) function 2nd .accdb file extension information in locking down front end multi-value fields and security and .accde file extension 2nd .accdr file extension 2nd Access (Microsoft) exportable file type support importable file type support Access Developer's Toolkit Access Options window action query warnings Customize section Access runtime engine 2nd 3rd Access Web Datasheet ACCWIZ folder Action Arguments section editing macros filter expressions macro action information naming reports action queries append queries delete queries 2nd find-and-replace feature vs. parameters and 2nd select queries vs. testing viewing without running actions

file:///C|/html/0596527608/A.html (1 of 5) [1/7/2007 7:17:03 AM]

A

creating macros 2nd 3rd defined methods and 2nd 3rd 4th repeating with loops 2nd safe unsafe macro viewing list of macro ActiveX control acwztool project Add New Record command Add Table dialog box add-ins adding attachments buttons to QAT controls 2nd 3rd 4th controls to forms 2nd 3rd 4th controls to reports descriptions for fields fields between existing fields fields in forms fields in Layout view fields in pivot tables fields to end of tables fields to reports 2nd fields via Form wizard grouping levels in pivot tables label controls links to documents lookups to fields 2nd 3rd math operations for 2nd modules 2nd objects to SQL Server databases 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th pictures to reports records to forms Rectangle control references Web Parts 2nd Adobe Reader 2nd

file:///C|/html/0596527608/A.html (2 of 5) [1/7/2007 7:17:03 AM]

A

.adp file extension 2nd AdventureWorks sample database 2nd After Del Confirm event After Insert event After Update event 2nd Alert Me action All tab (Property Sheet) Allow […] View property Allow Additions property 2nd Allow Deletions property 2nd Allow Edits property 2nd Allow Filters property 2nd Allow Multiple Values option Allow Zero Length property Alt key macros and ampersand (&) anchoring controls 2nd 3rd 4th 5th 6th subforms and And operator conditions and 2nd field validation filtering and table validation apostrophe (') Append or Make Table dialog box append queries 2nd 3rd 4th 5th 6th 7th Application category ApplyFilter method (DoCmd) arguments OpenForm method reading from forms 2nd 3rd 4th arithmetic operators arithmetic rounding As keyword As String clause ASCII code ASP.NET 2nd

file:///C|/html/0596527608/A.html (3 of 5) [1/7/2007 7:17:03 AM]

A

assignment statement calling functions with example Attachment control 2nd Attachment data type description lookup support one-to-one relationships and showing pictures from databases SQL Server attachments database considerations for SQL Server conversion and Attachments column (SharePoint) Attachments dialog box 2nd authentication SharePoint SQL Server Auto Center property Auto Tab property AutoCorrect feature 2nd 3rd AutoExec macro AutoFilter icon AutoFormat feature 2nd 3rd AutoFormat wizard AutoKeys macro 2nd automatic refreshes automatic save feature AutoNumber data type append query guidelines changing values in fields creating primary key field description filtering support forms and linking with ID number 2nd manipulating start values 2nd parent-child relationships and sorting options

file:///C|/html/0596527608/A.html (4 of 5) [1/7/2007 7:17:03 AM]

A

SQL Server validation support Avery number Avg option (Total)

file:///C|/html/0596527608/A.html (5 of 5) [1/7/2007 7:17:03 AM]

B

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] Back Style property Back Up SQL Database command back-end databases Access versions and automatic refreshes naming passwords and placement of splitting with wizard 2nd 3rd 4th BackColor property 2nd 3rd 4th background color backslash (\) 2nd backups before action queries 2nd changing data types and corrupt databases and 2nd SharePoint and SQL Server databases banker's rounding bar charts 2nd Beep method (DoCmd) Before Del Confirm event 2nd Before Insert event 2nd 3rd Before Update event 2nd 3rd 4th 5th binary format blank fields preventing blank values email addresses as empty text vs. functions and unlinked records

file:///C|/html/0596527608/B.html (1 of 2) [1/7/2007 7:17:05 AM]

B

.bmp file extension Boole Boolean data type (VB) Border Style property borders controls with formatting for reports removing from text boxes reusing settings Bound Column setting (SQL Server) bound controls 2nd Bound Object Frame control Boutique Fudge tutorial 2nd 3rd break mode 2nd breakpoints using British postal code mask business tasks adding products during orders 2nd 3rd 4th managing order fulfillment 2nd 3rd 4th running with VB 2nd updating stock numbers 2nd 3rd Button wizard 2nd 3rd 4th buttons adding to QAT closing forms with command 2nd drawing on forms forms and OnClick event pictures on properties for selecting from Property Sheet spacing controls Windows XP support Byte option (Field Size property)

file:///C|/html/0596527608/B.html (2 of 2) [1/7/2007 7:17:05 AM]

C

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] calculated fields crosstab queries and defined Expression Builder support functions and pivot tables and 2nd 3rd 4th simple math with SQL Server and text expressions 2nd text functions and Calculation tab (pivot tables) calculations expressions in forms 2nd grouping for subtotals pivot table support for queries performing reports and calendar smart tag Calendar Web Part Can Grow property Canadian postal code mask CancelEvent action 2nd capitalization case sensitivity spell checker and Caption property Attachment data type and modifying text Cascade Delete Related Fields setting 2nd cascading deletes 2nd 3rd cascading updates categorizing

file:///C|/html/0596527608/C.html (1 of 7) [1/7/2007 7:17:11 AM]

C

database objects filtering and 2nd 3rd navigation pane 2nd 3rd Character Map tool Chart control Check Box control circular references Clear All Sorts command 2nd Clear Filter command Clip Art Close action Close Button property Close Form command Close method (DoCmd) Close Print Preview command collect-by-email feature colon (:) colors background predefined names for Column Count setting (SQL Server) column fields (pivot tables) column headers formatting for reports 2nd grouping and moving Column Heads setting (SQL Server) Column Width dialog box Column Widths setting (SQL Server) Columnar option (layouts) 2nd columns default for lists exporting considerations filtering filtering pivot table hiding labels and layouts and 2nd moving

file:///C|/html/0596527608/C.html (2 of 7) [1/7/2007 7:17:11 AM]

C

naming ordering for reports picking right groups pivot charts and pivot table fields rearranging 2nd removing filters from resizing resizing for reports Columns button Combo Box control description list controls and navigating with 2nd 3rd 4th Command Builder wizard 2nd 3rd Command Button wizard 2nd 3rd command buttons 2nd 3rd 4th commands customizing QAT 2nd menu 2nd 3rd comments 2nd compact and repair feature 2nd compacting databases compound forms 2nd compound indexes 2nd Computer Name tab Condition column 2nd conditional formatting 2nd 3rd 4th conditional macros 2nd 3rd 4th 5th 6th conditions building 2nd making decisions with validating data with 2nd Conditions column Configure Your Server wizard configuring navigation list 2nd 3rd trusted locations constants

file:///C|/html/0596527608/C.html (3 of 7) [1/7/2007 7:17:11 AM]

C

Contacts list (SharePoint) Continuous Form view contribute permission Control Box property control events Control wizard adding controls creating links controls adding 2nd adding to forms adding to reports anchoring 2nd 3rd 4th 5th arranging on forms 2nd 3rd 4th automatically resizing bound 2nd Design view support formatting 2nd 3rd forms support for 2nd 3rd gridlines and icons for layouts for methods for overlapping programming objects and properties for 2nd repositioning in tab order sizing spacing subform control 2nd 3rd tab 2nd 3rd 4th unbound useful properties validation rules in 2nd wizards for converting information to other types macros to VB code 2nd negative numbers

file:///C|/html/0596527608/C.html (4 of 7) [1/7/2007 7:17:11 AM]

C

versions of databases copy-and-paste operation 2nd CopyDatabaseFile method (DoCmd) copying as unsafe macro action attachments cells from Excel data types tables elsewhere Count option (Total) Created By field (SharePoint) Created Date mode (navigation pane) 2nd 3rd creating calculated fields 2nd 3rd calculated fields in pivot tables controls crosstab queries 2nd 3rd 4th 5th 6th custom functions 2nd 3rd customized subform controls databases 2nd 3rd email messages 2nd 3rd 4th 5th 6th expressions form layouts 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th forms 2nd 3rd 4th forms in Design view forms in Layout view labels 2nd 3rd 4th links links in fields lists 2nd 3rd lookups macros 2nd 3rd 4th menu commands one-to-one relationship primary key field projects queries 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th report headers/footers reports

file:///C|/html/0596527608/C.html (5 of 7) [1/7/2007 7:17:11 AM]

C

reports in Design view 2nd 3rd SharePoint team sites 2nd 3rd 4th simple reports 2nd split forms SQL Server databases 2nd 3rd 4th 5th 6th 7th switchboards 2nd 3rd 4th 5th tables 2nd 3rd 4th 5th 6th 7th tables while importing 2nd totals queries 2nd 3rd union queries 2nd variables credit cards 2nd 3rd 4th 5th Crosstab property 2nd crosstab queries creating 2nd 3rd 4th 5th Crosstab Query wizard 2nd pivot tables and SQL Server support totals queries vs. 2nd Crosstab Query wizard 2nd 3rd 4th 5th 6th Ctrl key Ctrl+" key combination Ctrl+; key combination Ctrl+Alt+Space key combination 2nd Ctrl+C key combination Ctrl+End key combination Ctrl+F key combination Ctrl+F1 key combination Ctrl+Home key combination Ctrl+K key combination Ctrl+S key combination Ctrl+V key combination Ctrl+X key combination Ctrl+Z key combination 2nd Currency data type custom string sorting options SQL Server Visual Basic

file:///C|/html/0596527608/C.html (6 of 7) [1/7/2007 7:17:11 AM]

C

Currency option Format field property 2nd Format( ) function formatting numeric fields Query Parameter dialog box Cursor On Hover property Custom Dictionaries dialog box Custom mode (navigation pane) custom spell check dictionary 2nd cut-and-paste operation import/export and Windows Explorer and

file:///C|/html/0596527608/C.html (7 of 7) [1/7/2007 7:17:11 AM]

D

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] DAO (data access objects) importing and data access pages data corruption shared databases and split database and Data Entry property data fields (pivot tables) Data Link Properties dialog box Data tab (Property Sheet) calculations with expressions exporting tables data types considerations when changing filtering support identifying for variables lookups support overview Required field property support SharePoint SQL Server 2nd text-based 2nd data validation applying rules 2nd creating table rules 2nd Design view input masks 2nd 3rd 4th 5th 6th 7th lookups preventing blank fields preventing duplicate values 2nd 3rd 4th 5th setting default values 2nd 3rd writing rules 2nd

file:///C|/html/0596527608/D.html (1 of 7) [1/7/2007 7:17:17 AM]

D

database catalog database corruption database design 2nd 3rd 4th 5th 6th database diagram building relationships defined database objects categorizing filtering 2nd 3rd front-end database and grouping hiding naming reports as security considerations types of Database Splitter wizard 2nd 3rd 4th databases blocked updates compacting consistency and copying 2nd creating 2nd 3rd creating in previous versions customizing data corruption in 2nd 3rd deleting dividing into files front end to linking managing moving moving to SharePoint 2nd 3rd on networks 2nd opening 2nd opening in Exclusive mode opening multiple opening previous versions password-protection feature 2nd

file:///C|/html/0596527608/D.html (2 of 7) [1/7/2007 7:17:17 AM]

D

planning preparing for sharing 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th saving saving as previous version saving with different names/formats security and 2nd 3rd server-side shrinking tables and taking offline templates for transferring records to upsizing 2nd 3rd 4th using someone else's Datasheet Find feature Datasheet option (layouts) Datasheet view copying rows in exporting and hyperlink support primary key and switching views 2nd tables and datasheets Access Web Datasheet advanced editing 2nd customizing filtering records 2nd 3rd 4th 5th find-and-replace feature formatting 2nd forms and forms vs. moving around 2nd printing query results as searching records 2nd 3rd 4th sorting records 2nd 3rd 4th split forms Date data type

file:///C|/html/0596527608/D.html (3 of 7) [1/7/2007 7:17:17 AM]

D

filtering support Visual Basic date expressions queries and validation rules and date functions 2nd 3rd 4th Date( ) function current date and 2nd 3rd description filter condition with time information and Date/Time data type custom formats SQL Server date/time information arranging for reports 2nd calculations with date components 2nd expressions and Group sample mask for Date/Time option (Query Parameter) DateAdd( ) function DateDiff( ) function DatePart( ) function 2nd 3rd DateSerial( ) function DAvg function Day( ) function dBase DCount function debugging debug mode macros 2nd 3rd single-step 2nd 3rd VB code 2nd 3rd 4th decimal numbers 2nd Decimal option (Field Size property) Decimal Places field property default property

file:///C|/html/0596527608/D.html (4 of 7) [1/7/2007 7:17:17 AM]

D

Default Value property 2nd default values dynamic setting SQL Server and default view Default View property delete queries saving Delete Record command DeleteObject action deleting attachments cascading deletes 2nd commands from QAT controls fields 2nd fields from reports label controls records 2nd 3rd records from forms relationships Design view accessing data types controls and 2nd 3rd 4th 5th 6th 7th 8th creating forms in creating queries 2nd creating reports in customizing forms in 2nd 3rd 4th 5th 6th 7th 8th 9th 10th data validation debugging macros in defining relationships field validation rules for forms lookup lists moving fields out of layouts 2nd ready-made masks report sections 2nd setting primary key in

file:///C|/html/0596527608/D.html (5 of 7) [1/7/2007 7:17:17 AM]

D

SQL Server switching to 2nd 3rd updates in viewing reports in detail fields (pivot tables) 2nd Detail section (Design view) DFirst function dialog mode digital certificates digital signatures Dim keyword Disabled Mode disaster recovery disconnected changes feature (SharePoint) Display Control setting (SQL Server) Display When property Dividing Lines property DLast function DLookup function 2nd 3rd DMax function DMin function Do/Loop block 2nd DoCmd object converting macros to VB code document element 2nd document prolog document workspaces documents domain functions 2nd dot operator Double option (Field Size property) double-clicking collapsing ribbon Edit mode toggle launching queries opening tables Down Arrow key DSum function Duplicate Record command

file:///C|/html/0596527608/D.html (6 of 7) [1/7/2007 7:17:17 AM]

D

duplicate records importing considerations preventing 2nd dynamic default values

file:///C|/html/0596527608/D.html (7 of 7) [1/7/2007 7:17:17 AM]

E

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] Edit Hyperlink window Edit Message property Edit mode Edit Relationships dialog box 2nd Edit Switchboard Item window Edit Switchboard Page window editing attachments conflicts in shared databases 2nd 3rd join query limitations locking records while 2nd macros overlapping changes 2nd 3rd 4th records 2nd 3rd records in forms relationships SharePoint data sorted columns special characters 2nd splitting tables tables elements Access rules for ellipsis (…) Input Mask wizard emailing collect-by-email feature data 2nd 3rd exporting data embedded macros 2nd empty text Enable Content button

file:///C|/html/0596527608/E.html (1 of 4) [1/7/2007 7:17:20 AM]

E

Enable Referential Integrity option Enabled property 2nd 3rd encryption 2nd End Sub statement end tags Enforce Referential Integrity option 2nd Enter Parameter Value dialog box EOF property error handling relationships and types of macro errors Visual Basic and 2nd 3rd 4th Visual Basic with error messages conditional logic and corrupt databases and debugging code and debugging macros SQL Server Express installation Esc key adding records to forms editing records form controls and evaluating the condition 2nd event handlers Event tab (Property Sheet) attaching macros to events connecting macros to forms events control form 2nd 3rd 4th 5th 6th section subroutines and Excel (Microsoft) Attachment data type support copying cells from exporting data to importing from 2nd 3rd special character support

file:///C|/html/0596527608/E.html (2 of 4) [1/7/2007 7:17:20 AM]

E

exclamation mark icon 2nd Exclusive mode 2nd 3rd Execute method (CurrentDb) exit condition Exit Function statement Exit Sub statement explicit relationships exponents Export As dialog box Export wizard 2nd 3rd exporting basic steps for 2nd data 2nd file types supported 2nd reports 2nd 3rd reusing settings for 2nd tables 2nd 3rd tables to SharePoint 2nd 3rd to XML 2nd 3rd Expression Builder 2nd 3rd 4th Expression property expressions actions and applying to different forms calculations in forms complex conditions and date 2nd 3rd defined domain functions and errors displayed Expression Builder 2nd 3rd filter 2nd 3rd 4th 5th filtering multiple fields macros and manipulating values operators and records and reports and

file:///C|/html/0596527608/E.html (3 of 4) [1/7/2007 7:17:20 AM]

E

SQL Server views and text 2nd validating numbers expressions and

file:///C|/html/0596527608/E.html (4 of 4) [1/7/2007 7:17:20 AM]

F

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] F2 key F5 key F8 key Field List pane adding fields creating reports field properties Field Properties section setting maximum length Field Size property AutoNumber data types and Length column and Number data types and 2nd Replication IDs and fields adding between existing fields adding/removing from reports as controls breaking down information in building expressions out of creating primary keys data types and 2nd defined hidden 2nd 3rd listing in Design view locking down lookups for matching moving in forms multi-value 2nd multiple layouts 2nd naming

file:///C|/html/0596527608/F.html (1 of 7) [1/7/2007 7:17:26 AM]

F

one-to-one relationship order of pivot table 2nd pointing to files removing from pivot tables renaming in queries selecting for queries 2nd sorting on multiple 2nd swapping content of timestamp writing validation rules file already in use error file extensions file management tools File New Database dialog box 2nd file paths adding links to documents Shell function and UNC file types 2nd files embedding in databases Windows security filter by condition 2nd 3rd filter by form feature 2nd 3rd 4th filter by selection 2nd 3rd filter expressions building Criteria box and for duplicated values for unlinked records lookups and filter fields (pivot tables) Filter On Load property Filter property filtering crosstab queries database objects 2nd 3rd date functions and

file:///C|/html/0596527608/F.html (2 of 7) [1/7/2007 7:17:26 AM]

F

delete queries and DoCmd methods and filter by condition filter by selection for unmatched records forms and 2nd 3rd 4th 5th indexed fields and linked records navigation pane and 2nd 3rd null values and pivot tables 2nd 3rd 4th queries vs. query parameters and Query wizard and quick filters 2nd records in queries records in tables 2nd 3rd 4th removing reports saving operations top/bottom validation rules and Find Duplicates Query wizard 2nd Find feature Find Unmatched Query wizard find-and-replace feature action queries vs. Find and Replace dialog box 2nd FindNext method (DoCmd) FindRecord action example 2nd FindRecord method (DoCmd) First option (Total) Fix( ) function Fixed option Format( ) function folders backups and changing access uses

file:///C|/html/0596527608/F.html (3 of 7) [1/7/2007 7:17:26 AM]

F

trusted locations FontBold property FontItalic property FontName property fonts FontSize property 2nd footers form Group page 2nd For/Next block 2nd 3rd Force New Page property 2nd 3rd ForeColor property form events 2nd 3rd 4th 5th 6th Form Operations category Form view Form wizard 2nd 3rd Format field property Currency data type and Date/Time data type and Number data type Format Operations category Format Painter Format property Format tab button properties control properties Property Sheet 2nd 3rd Format( ) function description place an order task FormatNumber( ) function FormatPercent( ) function formatting AutoFormat wizard borders columns/column headers for reports conditional 2nd 3rd controls and 2nd

file:///C|/html/0596527608/F.html (4 of 7) [1/7/2007 7:17:26 AM]

F

custom currency string custom number string datasheets 2nd Date/Time data type Design view and exporting considerations Format Painter tool gridlines 2nd 3rd Memo data type and 2nd numbers numeric fields pivot table fields Property Sheet settings and reports 2nd 3rd forms anchoring controls 2nd 3rd 4th 5th attaching macros to AutoNumber fields in changing properties compound 2nd connecting macros to 2nd 3rd continuous controlling controls 2nd 3rd 4th 5th 6th 7th 8th controls supported 2nd 3rd 4th 5th creating creating layouts for 2nd 3rd 4th customizing in Design view datasheets vs. deleting records different parts of filtering 2nd 3rd formatting front-end database and hyperlinks in 2nd junction tables and layouts and linked records in separate 2nd 3rd 4th 5th linked tables and 2nd 3rd navigating with lists 2nd

file:///C|/html/0596527608/F.html (5 of 7) [1/7/2007 7:17:26 AM]

F

navigation controls navigation features in 2nd 3rd 4th 5th 6th 7th picture backgrounds for pivot tables in preventing corruption printing records 2nd properties 2nd putting code in 2nd 3rd 4th 5th 6th 7th 8th reading/writing fields on reference values on saving SharePoint support showing multiple records 2nd shrinking sizing controls 2nd sorting split 2nd 3rd 4th startup 2nd 3rd subform control 2nd switchboard alternatives 2nd 3rd 4th switchboards and 2nd tab control 2nd 3rd table relationships and text field size considerations types of validation rules viewing modes free-floating windows 2nd freezing columns 2nd FROM statement (SQL) 2nd front-end databases creating different for SharePoint locking down 2nd SQL Server and full control permission functions blank values and 2nd calling

file:///C|/html/0596527608/F.html (6 of 7) [1/7/2007 7:17:26 AM]

F

creating custom date 2nd 3rd 4th domain Expression Builder 2nd formatting numbers 2nd mathematical nested SQL Server summary 2nd 3rd testing credit cards 2nd 3rd text 2nd 3rd user-defined

file:///C|/html/0596527608/F.html (7 of 7) [1/7/2007 7:17:26 AM]

G

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] General Date format (Date/Time data type) General Number option (Format property) 2nd getting started creating databases creating tables 2nd editing tables 2nd 3rd Getting Started page 2nd 3rd understanding tables Getting Started page creating SQL Server databases live content from Web opening databases .gif file extension globally unique identifier (GUID) Go To First Record command Go To Last Record command Go To Next Record command Go To Previous Record command Go to Switchboard command GoToControl method GoToRecord action GoToRecord method (DoCmd) gridlines controls breaking free from Group 2nd 3rd 4th 5th 6th Group By option (Total) group names groups/grouping crosstab queries and 2nd 3rd custom 2nd database objects 2nd 3rd Group

file:///C|/html/0596527608/G.html (1 of 2) [1/7/2007 7:17:28 AM]

G

join queries and macros and 2nd 3rd multiple pivot charts and pivot tables and queries and records reports and 2nd 3rd 4th 5th 6th 7th 8th 9th SharePoint totals queries 2nd GUID (globally unique identifier)

file:///C|/html/0596527608/G.html (2 of 2) [1/7/2007 7:17:28 AM]

H

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] headers form Group orphaned page 2nd Height property hiding columns 2nd 3rd database objects groups pivot table details pivot table groups queries Hour( ) function Hourglass method (DoCmd) HTML clipboard and exporting considerations importing considerations Hyperlink control Hyperlink data type SQL Server hyperlinks forms and launching programs with to related data 2nd 3rd hyphen (-)

file:///C|/html/0596527608/H.html [1/7/2007 7:17:30 AM]

I

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] icons AutoFilter for controls Message box window navigation pane paper clip union queries ID numbers AutoNumber and 2nd linking tables with lookups and related tables and SQL Server and Identity Increment property Identity Seed property If block structure 2nd 3rd Image control 2nd Immediate window (VB editor) implicit relationships Import wizard importing from text files saving settings importing basic steps for 2nd 3rd from Excel files 2nd from XML files 2nd 3rd linked tables vs. 2nd SharePoint data 2nd 3rd tables 2nd Increment option (New Values field property) Indexed field property indexes

file:///C|/html/0596527608/I.html (1 of 2) [1/7/2007 7:17:33 AM]

I

compound 2nd performance and speeding up searches Indexes window InfoPath (Microsoft Office) inner joins 2nd Input Mask property prebuilt masks and Input Mask wizard 2nd 3rd 4th input masks creating mask list placeholders for 2nd special characters for Insert Hyperlink dialog box Insert Rows command installing SharePoint SQL Server Express 2nd 3rd 4th 5th 6th Instr( ) function Int( ) function integer division Integer option Field Size property IntelliSense (Visual Basic) 2nd Internet Explorer browser 2nd IP (Internet Protocol) address Is Hyperlink property 2nd IsNull( ) function Item property ItemsSelected property

file:///C|/html/0596527608/I.html (2 of 2) [1/7/2007 7:17:33 AM]

J

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] Join Properties dialog box join queries groupings and modifying information via multiple joins parent-child relationships and relationships vs. tables in 2nd 3rd 4th .jpeg file extension junction tables multi-value fields and 2nd multiple joins and Justified option (layouts) 2nd

file:///C|/html/0596527608/J.html [1/7/2007 7:17:34 AM]

K

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] Keep Together property keystrokes assigning macros to 2nd running macros via KeyTips feature commands and

file:///C|/html/0596527608/K.html [1/7/2007 7:17:35 AM]

L

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] label controls adding Label wizard 2nd 3rd 4th 5th 6th labels 2nd 3rd 4th .laccdb file extension 2nd Landscape option (Page Layout) landscape orientation 2nd 3rd Last option (Total) Layout view for forms 2nd 3rd for reports 2nd 3rd 4th layouts anchored controls and control limitations in creating for forms 2nd Form wizard options page 2nd report options 2nd tabular 2nd 3rd 4th using multiple 2nd 3rd LCase( ) function Left Arrow key Left property Left( ) function 2nd 3rd Len( ) function 2nd 3rd length line continuation character Line control 2nd Link Child Fields property 2nd Link Master Fields property 2nd linked records cascading updates and

file:///C|/html/0596527608/L.html (1 of 3) [1/7/2007 7:17:38 AM]

L

controlling display of in separate forms Linked Table Manager window linked tables bad links in forms and 2nd 3rd importing vs. projects vs. split databases and 2nd SQL Server and 2nd with relationships 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th 26th 27th 28th 29th 30th 31st linking/links creating fields with relationships reports and 2nd to related data 2nd 3rd 4th List Box control 2nd 3rd 4th 5th list controls combo boxes and List wizard lists building modifying settings for setting options SharePoint 2nd Lists section (SharePoint) Locked property locks editing records and for front-end database for overlapping edits 2nd 3rd logical operators logos arranging for reports forms and Long data type (VB) Long Date format (Date/Time data type) Long Integer option (Field Size property) 2nd 3rd

file:///C|/html/0596527608/L.html (2 of 3) [1/7/2007 7:17:38 AM]

L

Long Time format (Date/Time data type) lookup lists relationships and sorting Lookup wizard setting allowed values lookups creating data validation 2nd 3rd filter expressions and primary key and refreshing relationships and SQL Server and table-based with fixed values 2nd 3rd Lotus 1-2-3 Luhn algorithm

file:///C|/html/0596527608/L.html (3 of 3) [1/7/2007 7:17:38 AM]

M

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] macro builder 2nd macro groups 2nd Macro tab (Action Arguments section) macros assigning to keystrokes conditional 2nd 3rd 4th configuring startup connecting to forms 2nd 3rd debugging disabled editing embedded 2nd FindRecord action 2nd managing printing reports privacy options Quick Access toolbar and running 2nd security and 2nd 3rd 4th 5th 6th 7th 8th setting up trusted locations trust center and unsafe actions 2nd 3rd 4th VB programming and mail merge feature 2nd make-table queries 2nd 3rd 4th Manage Data Tasks dialog box 2nd many-to-many relationship 2nd 3rd 4th 5th MAPI (Messaging Application Programming Interface) mapped network drives mapping SQL Server data types margins Margins option (Page Layout)

file:///C|/html/0596527608/M.html (1 of 3) [1/7/2007 7:17:41 AM]

M

mask list matching fields math operations order of with numeric fields 2nd 3rd mathematical functions 2nd Max option (Total) maximum length guidelines for Memo data type and text fields 2nd .mdb file extension 2nd Medium Date format (Date/Time data type) Medium Time format (Date/Time data type) menu commands 2nd 3rd message bar Message box window condition example debugging changes and error handling with 2nd Message Text property meta-language methods control DoCmd object 2nd Microsoft Corporation 2nd Microsoft Office Developer Center Microsoft Office InfoPath Microsoft Office Security Options dialog box 2nd 3rd Microsoft Office SharePoint Portal Server (SPS) Microsoft Office SharePoint Server (MOSS) Mid( ) function 2nd 3rd Min option (Total) minibar Minute( ) function Miscellaneous category Mixed mode authentication security and SQL Server databases

file:///C|/html/0596527608/M.html (2 of 3) [1/7/2007 7:17:41 AM]

M

Mod operator modal dialog Modified By field (SharePoint) Modified Date mode (navigation pane) 2nd 3rd modules adding calling code in 2nd 3rd functions and modulus monitor resolution Month( ) function MonthName( ) function MOSS (Microsoft Office SharePoint Server) mouseover effects 2nd Move method MoveNext method (Recordset) moving columns controls fields fields in forms fields out of layouts Web Parts MsgBox action 2nd 3rd MsgBox command MsgBox( ) function 2nd MSysObjects system table 2nd multifield indexes 2nd multiple joins Multiple-Record view multiplication 2nd My Computer icon

file:///C|/html/0596527608/M.html (3 of 3) [1/7/2007 7:17:41 AM]

N

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] Name field (system tables) 2nd Name property 2nd 3rd named range naming buttons database objects events fields macros tabs navigating around forms designating startup forms and form tab order and 2nd 3rd form-to-form forms capable of 2nd 3rd 4th 5th 6th 7th 8th 9th linking to related data 2nd print preview relationships 2nd with lists 2nd with Tab key 2nd Navigation Buttons property 2nd Navigation Options dialog box manipulating groups 2nd showing system tables navigation pane browsing tables with 2nd configuring navigation list congestion on custom groups 2nd form modules and hiding objects

file:///C|/html/0596527608/N.html (1 of 2) [1/7/2007 7:17:43 AM]

N

organizing queries printing reports from running queries in searching navigation list 2nd sort options view options Navigation section (SharePoint) 2nd negative number values Number data type nested functions nesting XML elements 2nd 3rd .NET Framework networks databases on 2nd mapped drives SQL Server on New Database dialog box New Label dialog box New Label Size dialog box New Query dialog box New Values field property Normal mode Notepad Now( ) function 2nd 3rd 4th Number data type Field Size property numbers decimal in text fields 2nd negative 2nd random rounding validating numeric fields formatting Group Nz( ) function 2nd

file:///C|/html/0596527608/N.html (2 of 2) [1/7/2007 7:17:43 AM]

O

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] Object Dependencies box 2nd object model 2nd objects adding to SQL Server databases 2nd database objects and Visual Basic and 2nd 3rd 4th 5th 6th working with 2nd 3rd ODBC On Before Update event On Change event example macro programming timing of On Click event 2nd 3rd 4th 5th On Close event 2nd On Current event 2nd 3rd On Dirty event 2nd On Enter event On Error statement 2nd On Key Press event On Load event On Mouse Move event example 2nd On Not In List event 2nd 3rd 4th On Open event On Undo event 2nd On Update event handler OnClick property one-to-many relationships 2nd one-to-one relationships cautions for OnError action

file:///C|/html/0596527608/O.html (1 of 3) [1/7/2007 7:17:46 AM]

O

Open Recent Databases section 2nd Open Report command 2nd 3rd OpenArgs property OpenForm action child forms and OpenForm method and OpenForm method (DoCmd) example 2nd OpenForm macro and opening databases 2nd databases in Exclusive mode multiple databases multiple subdatasheets previous version databases tables 2nd Zoom box 2nd OpenQuery method (DoCmd) OpenRecordset method (CurrentDb) OpenReport action OpenReport method (DoCmd) 2nd OpenTable action arguments to debugging OpenTable method (DoCmd) operators dot expressions and Option Button control Option Compare Database instruction Option Explicit instruction Option Group control Or operator filtering and Order By On Load property Order By property ORDER BY statement (SQL) order of operations Other tab (Property Sheet) 2nd 3rd

file:///C|/html/0596527608/O.html (2 of 3) [1/7/2007 7:17:46 AM]

O

out-of-stock orders tutorial 2nd 3rd 4th outer joins 2nd 3rd Outlook (Microsoft) 2nd 3rd 4th 5th 6th 7th overlapping changes 2nd 3rd controls 2nd edits 2nd 3rd fields windows

file:///C|/html/0596527608/O.html (3 of 3) [1/7/2007 7:17:46 AM]

P

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] Page Break control 2nd Page Down key 2nd Page Footer property page footers description Page Header property page headers column headers in page layouts 2nd page numbers (reports) 2nd Page Up key 2nd paper clip icon paper orientation landscape 2nd portrait 2nd paper size Paradox parameters action queries and 2nd domain functions parent-child relationships exporting tables and junction tables and navigating subform controls parentheses ( ) function and passwords split databases and SQL Server and Path property PDF files

file:///C|/html/0596527608/P.html (1 of 4) [1/7/2007 7:17:49 AM]

P

exporting reports as saving reports as pencil icon percent symbol (%) performance indexes and indexes speeding up searches projects and split databases and SQL Server and 2nd permissions Permissions section (SharePoint) phone number mask 2nd 3rd Picture Alignment property Picture property 2nd 3rd Picture Size Mode property Picture Tiling property pictures adding to reports clipboard support form backgrounds and pivot charts printing types of pivot tables building 2nd creating calculated fields 2nd features of 2nd 3rd filtering 2nd 3rd forms for hiding/showing details manipulating pivot charts 2nd PivotTable Field List window 2nd 3rd placeholders Expression Builder and point-in-time data 2nd Pop Up property Portrait option (Page Layout)

file:///C|/html/0596527608/P.html (2 of 4) [1/7/2007 7:17:49 AM]

P

portrait orientation 2nd PowerPoint (Microsoft) 2nd Preview Report command previewing reports 2nd primary keys duplicate records and 2nd SQL Server tables Print Current Form command Print Preview mode changing page layouts forms and Print Record command Print Report command printing changing settings for print preview feature 2nd records from forms relationships reports 2nd reports with macros PrintOut action 2nd PrintOut method (DoCmd) private subroutines 2nd procedures Project window (VB editor) adding code to forms projects creating creating queries via linked tables vs. properties button control control validation rules default DoCmd object and field fine-tuning reports with 2nd 3rd form 2nd split form 2nd

file:///C|/html/0596527608/P.html (3 of 4) [1/7/2007 7:17:49 AM]

P

SQL Server subform controls tab order Properties window relationships and Property Sheet gridlines property names on split form settings subdatasheet settings table validation and tweaking settings with public subroutines Publish As PDF dialog box

file:///C|/html/0596527608/P.html (4 of 4) [1/7/2007 7:17:49 AM]

Q

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] queries analyzing append 2nd 3rd 4th 5th 6th based on queries calculated fields 2nd 3rd 4th 5th 6th delete 2nd 3rd 4th Design view and 2nd 3rd 4th 5th 6th 7th 8th filters vs. finding unmatched records flagging out-of-stock orders for system tables grouping and hiding join make-table pivot table limitations projects and Query wizard 2nd 3rd 4th reports based on select 2nd SharePoint views and SQL Server and SQL view and 2nd 3rd 4th summary 2nd 3rd totals 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th transferring tables and union 2nd 3rd update 2nd 3rd 4th 5th viewing top records 2nd 3rd 4th way to create query functions 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th query parameters

file:///C|/html/0596527608/Q.html (1 of 2) [1/7/2007 7:17:51 AM]

Q

action queries Query Parameters dialog box Query wizard 2nd 3rd 4th 5th 6th Quick Access toolbar customizing commands 2nd 3rd 4th Undo command quick search feature Quit action Quit Application command Quit method (DoCmd) quotation marks (")

file:///C|/html/0596527608/Q.html (2 of 2) [1/7/2007 7:17:51 AM]

R

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] random numbers Random option (New Values field property) read permission reading arguments from forms 2nd Recalc method (Form) 2nd Recent Document list (Office menu) Record Locks property Record Navigation category Record Operations category Record Selectors property 2nd Record Source property 2nd records AutoNumber data type in blank values for unlinked changing in shared databases 2nd 3rd 4th 5th 6th changing SharePoint copying in one step corrupted deleting editing 2nd filtering in tables 2nd 3rd 4th finding/editing in forms FindRecord action grouping 2nd identifying before deleting indicating changes in 2nd 3rd 4th linked 2nd 3rd locking while editing many-to-many relationships one-to-one relationships searching 2nd

file:///C|/html/0596527608/R.html (1 of 4) [1/7/2007 7:17:55 AM]

R

showing multiple sorting in queries sorting in tables 2nd 3rd updating Recordset object Rectangle control adding formatting redundant data 2nd 3rd 4th References dialog box Refresh All command 2nd refresh interval 2nd Refresh method 2nd refreshes Regional and Language Options dialog box related data 2nd 3rd relational database management system (RDBMS) relationship diagram Relationship window relationships Chocolate Store practice 2nd 3rd 4th defining between tables editing explicit lookups with related tables many-to-many 2nd Music School practice 2nd 3rd one-to-many one-to-one 2nd printing redundant vs. related data referential integrity 2nd 3rd 4th 5th SQL Server and relationships and 2nd 3rd 4th 5th Relationships tab defining relationships 2nd 3rd Remove Filter command renaming fields in queries

file:///C|/html/0596527608/R.html (2 of 4) [1/7/2007 7:17:55 AM]

R

Replication ID option (Field Size property) replication IDs 2nd Report Name property Report Operations category 2nd report title 2nd 3rd Report view (reports) 2nd 3rd Report wizard 2nd 3rd reports adding/removing fields adjusting settings creating 2nd exporting 2nd 3rd 4th filtering fine-tuning with properties 2nd formatting 2nd 3rd 4th 5th 6th 7th 8th 9th 10th grouping 2nd 3rd 4th 5th 6th 7th hidden fields in improving in Design view 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th labels as links in previewing printing 2nd 3rd 4th saving saving as PDF files views for 2nd Requery action Requery method 2nd 3rd Require Variable Declarations option Required field property Allow Nulls column and empty values and 2nd manipulating AutoNumber values support for resizing columns in forms controls controls automatically 2nd 3rd 4th 5th report components 2nd 3rd 4th rows and columns 2nd

file:///C|/html/0596527608/R.html (3 of 4) [1/7/2007 7:17:55 AM]

R

resolution result RGB function ribbon (Access 2007) Alt key and collapsing formatting datasheets 2nd Print Preview mode Visual Basic editor rich text 2nd Right Arrow key 2nd Right( ) function 2nd Rnd( ) function root element 2nd Round( ) function calculated fields and nesting and rounding numbers row fields (pivot tables) Row Source property 2nd Row Source Type setting (SQL Server) rows copying elsewhere formatting alternate Run dialog box Run Macro command Run Query command RunApp action RunCommand method (DoCmd) 2nd RunMacro action RunMacro method (DoCmd) RunSQL method (DoCmd)

file:///C|/html/0596527608/R.html (4 of 4) [1/7/2007 7:17:55 AM]

S

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] safe actions Save As dialog box Save As menu command Save button (Quick Access toolbar) Save Record command Save Splitter Bar Position property saving changes to clipboard database diagram databases export settings filters import settings macros report export settings reports schemas scientific notation scrolling through tabs searching forms and navigation list records 2nd 3rd Second( ) function section events security database objects and databases and macros and 2nd 3rd 4th 5th 6th manually splitting databases SQL Server and 2nd VB code and

file:///C|/html/0596527608/S.html (1 of 6) [1/7/2007 7:17:59 AM]

S

Windows SELECT statement (SQL) bound controls and SendObject action 2nd 3rd server-side processing shared databases and SQL Server and 2nd service packs Set Control Defaults button SetFocus method SetProperty action setting up SetValue action 2nd shared databases approaches for 2nd changing records data corruption and editing conflicts without Access 2nd 3rd Shared Documents folder Shared Documents section (SharePoint) 2nd shared folders permission considerations SharePoint connection options creating team sites customizing sites editing data front end for fun features importable file type support installing offline changes 2nd sharing data with transferring data in/out SharePoint support Shell function Shift key Shift+F2 key combination 2nd 3rd 4th

file:///C|/html/0596527608/S.html (2 of 6) [1/7/2007 7:17:59 AM]

S

Shift+Tab key combination 2nd Short Date format (Date/Time data type) 2nd Short Time format (Date/Time data type) shortcut keys clipboard Show Dialog box Show Table dialog box adding tables creating append queries creating queries with parameters creating update queries Queries tab ShowAllRecords method (DoCmd) Simple Query wizard Single data type (VB) Single option (Field Size property) Single-Record view single-step debugging 2nd 3rd 4th Site Administration section (SharePoint) Site Users Web Part Size option (Page Layout) Snapshot Viewer program 2nd sorting crosstab queries forms Group groups in pivot tables navigation pane options random numbers and records in tables 2nd 3rd Source Object property 2nd spaces adding between report rows control anchors and controls and property names and sort order of special characters Access support

file:///C|/html/0596527608/S.html (3 of 6) [1/7/2007 7:17:59 AM]

S

spell checking 2nd 3rd 4th 5th Spelling window 2nd split databases corrupt data and linked tables and 2nd 3rd manual process 2nd security and Split Form Datasheet property Split Form Orientation property Split Form Printing property Split Form Size property Split Form Splitter Bar property split forms properties for SPS (SharePoint Portal Server) SQL (Structured Query Language) analyzing queries 2nd DAO and text commands in union queries validation rules and SQL Server firewalls and installing 2nd upsizing databases 2nd Web pages and SQL Server Agent SQL Server Books Online 2nd SQL Server databases adding objects to backing up creating 2nd 3rd 4th 5th creating tables 2nd 3rd 4th SQL Server Express limitations of 2nd Microsoft and 2nd SQL Server Management Studio tool 2nd 3rd SQL view 2nd 3rd 4th 5th 6th 7th Sqr( ) function

file:///C|/html/0596527608/S.html (4 of 6) [1/7/2007 7:17:59 AM]

S

stacked bar charts 2nd stacked column charts 2nd start tags startup forms Access runtime engine startup macros StDev option (Total) stored procedures storing information in variables 2nd SharePoint sites and String data type (VB) string manipulation functions Sub statement Subdatasheet Expanded setting Subdatasheet Height setting Subdatasheet Name setting subdatasheets adding and linking support changing settings subreports subroutines naming parentheses in private 2nd public writing simple 2nd subtotals placing orders task 2nd subtraction 2nd Sum option (Total) summaries crosstab queries and 2nd 3rd queries performing 2nd 3rd summary functions pivot tables and Switchboard Items table Switchboard Manager 2nd 3rd switchboards

file:///C|/html/0596527608/S.html (5 of 6) [1/7/2007 7:17:59 AM]

S

alternatives for 2nd 3rd building 2nd syntax 2nd system tables 2nd

file:///C|/html/0596527608/S.html (6 of 6) [1/7/2007 7:17:59 AM]

T

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] Tab (or Enter) key 2nd 3rd 4th tab character tab control 2nd 3rd 4th Tab Index property tab order 2nd 3rd Tab Order dialog box Tab Stop property tables appending data to 2nd back-end database and bypassing locks combining related corrupted records in creating 2nd data types and 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th database design principles Datasheet view Design view 2nd 3rd 4th 5th duplicate information in 2nd exporting 2nd exporting to SharePoint filter by selection importing joining in queries 2nd 3rd 4th junction 2nd 3rd 4th lists and many-to-many relationships one-to-one relationships ordering records primary key 2nd 3rd redesign cautions relationship diagram and

file:///C|/html/0596527608/T.html (1 of 3) [1/7/2007 7:18:02 AM]

T

Relationships tab and 2nd removal restrictions splitting switchboard system union query and 2nd validation rules for 2nd 3rd tabs Access Options window setting order on forms 2nd 3rd tabular layouts 2nd 3rd 4th 5th Tabular option (layouts) 2nd tags 2nd tasks data operations and getting pricing information grouping around objects and 2nd 3rd 4th 5th 6th 7th placing orders shipping orders using objects 2nd 3rd 4th 5th Visual Basic editor 2nd 3rd 4th Tasks link (SharePoint) Team Discussion Web Part Template section (SharePoint) testing action queries assumptions Text Align property Text Box control anchoring Text data type length considerations 2nd mask support 2nd 3rd 4th 5th Text option (Query Parameter) Text property 2nd text-based information expressions with 2nd functions manipulating 2nd 3rd

file:///C|/html/0596527608/T.html (2 of 3) [1/7/2007 7:18:02 AM]

T

numbers in 2nd special characters in timestamp fields Title and Description section (SharePoint) Title column (SharePoint) To Widest command Toggle Button control Top property top/bottom filtering 2nd Total property 2nd totals queries grouping 2nd joins in 2nd 3rd transactions TransferSpreadsheet action TransferText action Trim( ) function trust center 2nd 3rd trusted publishers 2nd Try It text box tutorial Type column (SharePoint) Type field (system tables) 2nd

file:///C|/html/0596527608/T.html (3 of 3) [1/7/2007 7:18:02 AM]

U

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] UCase( ) function unbound controls Unbound Object Frame control UNC (Universal Naming Convention) UNC path Undo command form changes and moving fields between layouts Undo method Undo Record command unfreezing columns Unhide Columns dialog box unhiding columns UNION ALL statement (SQL) union queries creating UNION statement (SQL) universal dates Unrelated Objects category unsafe macro actions 2nd 3rd 4th 5th Up Arrow key update queries 2nd 3rd 4th 5th updates cascading Design view and linked tables modifying records 2nd 3rd 4th 5th shared databases and 2nd 3rd upsizing databases SQL Server and 2nd 3rd 4th 5th 6th Upsizing wizard 2nd 3rd 4th 5th Use Control Wizards button

file:///C|/html/0596527608/U.html (1 of 2) [1/7/2007 7:18:05 AM]

U

Use Trusted Connection checkbox User Information List table user names User Tasks Web Part user-defined functions

file:///C|/html/0596527608/U.html (2 of 2) [1/7/2007 7:18:05 AM]

V

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] Val( ) function Validation Rule property 2nd validation rules conditional logic and conditions and credit card example 2nd 3rd 4th date expressions expressions for numbers field 2nd 3rd 4th filters and for forms 2nd for text 2nd table 2nd 3rd Validation Text property 2nd Value property Var option (Total) variables debugging parameters as storing information in 2nd typos in VBA (Visual Basic for Applications) Vieira views creating for forms SharePoint split forms Visible property 2nd Visual Basic editor 2nd 3rd 4th 5th Visual Basic IntelliSense 2nd Visual Basic language

file:///C|/html/0596527608/V.html (1 of 2) [1/7/2007 7:18:07 AM]

V

debugging with 2nd 3rd 4th error handling with macros and objects and 2nd 3rd reference help running businesses with 2nd types of errors 2nd

file:///C|/html/0596527608/V.html (2 of 2) [1/7/2007 7:18:07 AM]

W

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] Web Parts minimizing Web Site Address section (SharePoint) Webb WeekdayName( ) function Where Condition property 2nd 3rd WHERE statement (SQL) 2nd width Width property windows overlapping Windows authentication mode Windows Calculator Windows environment buttons face-lift regional settings Windows Explorer Windows file security Windows SharePoint Services (WSS) Windows Task Scheduler Windows Update Windows Vista SQL Server and Windows XP facelift and XPS format Windows XP Wingdings font wizards for controls Word (Microsoft) launching workbooks

file:///C|/html/0596527608/W.html (1 of 2) [1/7/2007 7:18:08 AM]

W

workflow workgroup workgroup security worksheets (Excel) workspaces writing fields on forms 2nd WSS (Windows SharePoint Services)

file:///C|/html/0596527608/W.html (2 of 2) [1/7/2007 7:18:08 AM]

X

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] XML (extensible markup language) Access support 2nd 3rd 4th exporting to 2nd 3rd importing from 2nd rules of 2nd 3rd 4th schemas and .xml file extension .xsd file extension .xsl file extension

file:///C|/html/0596527608/X.html [1/7/2007 7:18:10 AM]

Y

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] Year( ) function Yes/No option (Format)

file:///C|/html/0596527608/Y.html [1/7/2007 7:18:11 AM]

Z

Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] Zoom box displaying column contents opening zoom feature 2nd

file:///C|/html/0596527608/Z.html [1/7/2007 7:18:12 AM]