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 Cont ent s | I ndex
Com pared t o indust rial- st rengt h dat abase product s such as Microsoft 's SQL Server, Access is a breeze t o use. I t runs on PCs rat her t han servers and is ideal for sm all- t o m id- sized businesses and households. But Access is st ill int im idat ing t o learn. I t doesn't help t hat each new version cram m ed in yet anot her set of feat ures; so m any, in fact , t hat even t he pros don't know where t o find t hem all. Access 2007 breaks t his pat t ern wit h som e of t he m ost dram at ic changes users have seen since Office 95. Most obvious is t he t horoughly redesigned user int erface, wit h it s t abbed t oolbar ( or " Ribbon" ) t hat m akes feat ures easy t o locat e and use. The feat ures list also includes several long-await ed changes. One t hing t hat hasn't im proved is Microsoft 's docum ent at ion. To learn t he ins and out s of all t he feat ures in Access 2007, Microsoft m erely offers online help.
Access 2007: The Missing Manual 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
Chapter 5. Linking Tables with Relationships Section 5.1. Relationship Basics
Section 6.1. Query Basics 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 Section 11.5. Expressions Section 12.3. Creating Better Layouts Section 12.4. The Form Wizard Chapter 13. Designing Advanced Forms
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 Chapter 18. Sharing a Database with Multiple Users Section 18.1. Opening Up Your Database to the World 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
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
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 han- life 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.
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, 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
Front 2003: The Missing Manual by Jessica Mant aro
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
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 abases
carefully 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 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.
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 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?
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: 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.
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 .
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
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 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 ) .
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.
Figu r e I - 2 .
The ribbon's full of craftsman-like detail. When you hover over a button, you don't see a paltry two- or threeword description in a yellow box. Instead, you see a friendly pop-up box with a complete mini-description. Here, the mouse is hovering 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 .
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 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.
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
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?
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).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, 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.
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 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.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 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
Figu r e I - 7 .
Print's both a clickable menu 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
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 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 fine- t une
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 ) .
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
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.
cust 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
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.)
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.Contextual tabs
Figu r e I - 1 0 . 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
Figu r e I - 1 1 . 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 m enu. For exam ple, say you're direct ed t o " Hom e Views View
Design View." That t ells you t o select t he Hom e t ab, 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 refer t o m enu levels. The inst ruct ion " Choose File Open" m eans " Click t he File m enu heading. Then, inside t he File m enu, click t he Open com m and."
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.
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.
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
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.
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.
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.
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 ) .
FREQUENTLY ASKED QUESTION
Using Someone Else's Database
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 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
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
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.)
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:
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 ) . 1 .
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 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.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.
3 .
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.
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. 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.)
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.
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.
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) . dat abase pros prefer Design view, and you'll st art using it in Chapt er 2 .
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.
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 identify your rows.2 .
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
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.
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. 4 .
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, double-click the column title. Next, type in the real field name, and then 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.)
5 .
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 ) . 6 .
Type a su it a ble t a ble n a m e , a n d t h e n click OK .
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 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 . underneat h. You can repeat t his process endlessly t o add as m any rows as you want ( Access can handle m illions) .