ffirs.indd ii 7/18/2013 2:59:33 AM PROFESSIONAL Access® 2013 Programming

ffirs.indd i 7/18/2013 2:59:32 AM ffirs.indd ii 7/18/2013 2:59:33 AM PROFESSIONAL Access® 2013 Programming

Teresa Hennig Ben Clothier George Hepworth Dagi (Doug) Yudovich

ffirs.indd iii 7/18/2013 2:59:33 AM Professional Access® 2013 Programming

Published by John Wiley & Sons, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com

Copyright © 2013 by John Wiley & Sons, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-1-118-53083-2 ISBN: 978-1-118-53082-5 (ebk) ISBN: 978-1-118-78961-2 (ebk) Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 No part of this publication may be reproduced, stored in a retrieval system or transmitted in any or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions. Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifi cally disclaim all warranties, including without limitation warranties of fi tness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional ser- vices. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the pub- lisher endorses the information the organization or Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written and when it is read. For general information on our other products and services please contact our Customer Care Department within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http://booksupport.wiley.com. For more information about Wiley products, visit www.wiley.com. Library of Congress Control Number: 2013907974 Trademarks: Wiley, Wrox, the Wrox logo, to Programmer, and related trade dress are trademarks or regis- tered trademarks of John Wiley & Sons, Inc. and/or its affi liates, in the United States and other countries, and may not be used without written permission. Access is a registered trademark of Corporation. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc., is not associated with any product or vendor mentioned in this book.

ffirs.indd iv 7/18/2013 2:59:34 AM To my family and my dearest friends — you are my inspirations, role models and mentors. Whatever I am facing, I can fi nd strength and guidance by thinking of what my Mom, Papa, Dad, or brother might say or do. Every day I have reasons to say thank you for teaching us to work, to accept responsibility for our actions, to do the right thing, and to help others. You taught us to do what we enjoy and to do our best. What a great formula to be happy, energized, and resilient, and to appreciate all that we have! You set the foundation for me to embrace the thrills, lessons, and adventures in life. And, throughout life, to be compassionate and to give generously — especially laughter and smiles, a hug or a helping hand.

—Teresa Hennig

To Suzanne and Harry, for being just plain awesome. I couldn’t have done it without you two!

—Ben Clothier

I want to dedicate my part in this book to my mother and father, who not only brought me into the world, but showed me how to live properly once I got here. Family comes fi rst, but that is easy when you have a family like mine. To my siblings, JoAnna, Tom, Sam, Jack, Nancy, and Jane: Your encouragement (and unusually high tolerance for bad jokes, lies, and war stories) helps keep me going. Thanks. I promise I’ll the family website again soon. I also need to make special mention of my daughter, Lyndsey; you give me reason to be proud every day. Love ya, sweetie. We’ll make up for the missed weekend dinners soon.

—George Hepworth

To my wife, Lisa, who still patiently picks up the slack as I dive head-fi rst into new adventures. None of it would have been possible without you. I love you.

—Dagi Yudovich

ffirs.indd v 7/18/2013 2:59:34 AM CREDITS

EXECUTIVE EDITOR PRODUCTION MANAGER Robert Elliott Tim Tate

PROJECT EDITOR VICE PRESIDENT AND EXECUTIVE GROUP Christina Haviland PUBLISHER Richard Swadley TECHNICAL EDITORS F. Scott Barker VICE PRESIDENT AND EXECUTIVE PUBLISHER Jerry Dennison Neil Edde Jerry Wood ASSOCIATE PUBLISHER PRODUCTION EDITOR Jim Minatel Christine Mugnolo PROJECT COORDINATOR, COVER COPY EDITOR Katie Crocker Nancy Rapoport PROOFREADER EDITORIAL MANAGER Sarah Kaikini, Word One New York Mary Beth Wakefi eld INDEXER FREELANCER EDITORIAL MANAGER John Sleeva Rosemarie Graham COVER DESIGNER ASSOCIATE DIRECTOR OF MARKETING Wiley David Mayhew COVER IMAGE MARKETING MANAGER © iStockphoto.com/PhekThong Lee Ashley Zurcher

BUSINESS MANAGER Amy Knies

ffirs.indd vi 7/18/2013 2:59:34 AM ABOUT THE AUTHORS

TERESA HENNIG has been an Access developer and business consultant since 1997, when she decided to start her own business on the second day that she used Access. Her company’s name, Data Dynamics Northwest, aptly refl ects her dynamic per- sonality and her innate ability to quickly grasp a situation, formulate and implement a solution, and motivate others. With a strong background in business and project management, Teresa focuses on providing intuitive, cost-effective solutions that sup- port all levels of an organization. One of her favorite aspects of being a consultant is working with an endless variety of businesses across many industries and in numerous locations. As a self-taught developer, Teresa quickly became involved with the Seattle Access Group and has been the President since 1999. It wasn’t long before she was asked to help run, and then became President of, the Pacifi c Northwest Access Developer Group. Her first book Access 2003 Programmer’s Reference (Wiley, 2003) opened the door to new opportunities to help fellow develop- ers share their passion and expertise with the community. Over the past 10 years, Teresa has helped dozens of colleagues to become authors, editors and contributors. This is her sixth book, and she already has requests to do more. Teresa has been recognized as a Microsoft MVP continuously since 2006, and has twice earned INETA’s National Community Champion award. Teresa thrives on challenges, project management, and creating cost-effective solutions. Her skills for motivating and helping others are refl ected in her contributions to the developer community and support of numerous non-profi t organizations. She is expanding her reach by doing presentations and offering customized training, mentoring, and consulting for development as well as business and project management. You can contact Teresa at [email protected] to learn more about any of these services. You can also read about some of her adventures and charitable endeavors by visiting her website, www.DataDynamicsNW.com.

BEN CLOTHIER is a Lead Developer with IT Impact, Inc., a premier Access and SQL Server development shop based in Chicago, Illinois. He has worked as a freelance consultant with notable shops including J Street Technology and Advisicon, and has worked on Access projects from small, one-man solutions to company-wide line- of-business applications. Notable projects include job tracking and inventory for a cement company, a Medicare insurance plan generator for an insurance provider, and order management for an international shipping company. Ben is an administrator at UtterAccess and was a coauthor, with Tim Runcie and George Hepworth, on Microsoft Access in a SharePoint World (Advisicon, 2011), and a contributing author for Access 2010 Programmer’s Reference (Wiley, 2010). He is a certifi ed MySQL 5.0 Developer and a Microsoft Certifi ed Technology Specialist for SharePoint 2010 confi gurations. He has been a Microsoft MVP since 2009. Ben lives in San Antonio, Texas with his wife, Suzanne, and his son, Harry.

ffirs.indd vii 7/18/2013 2:59:34 AM GEORGE HEPWORTH began his Access career by creating tools to track sales and exam results for his business, which created and sold training and exam materials. Realizing that Access were more interesting and rewarding than writing training materials, he soon transitioned to full-time Access development and started his company, Grover Park Consulting (www.GPCData.com), specializing in resuscitat- ing “owner-built” Access databases for small- and medium-sized organizations. As a self-taught developer, George believes that any day on which he doesn’t learn at least one new thing is a day wasted. George is a database developer for Data and Domains, a development organization near Bellevue, Washington, creating Access and Access/SQL Server solutions for clients in the Puget Sound region. George is part of the administrator team, and a regular contributor, at UtterAccess, the most popu- lar Access support site on the Internet. He is the author or contributor to several books on Access, and a presenter at the Pacifi c Northwest Access Developer Group and Seattle Access Group. George holds a BS in English and an MA in TESL from Utah State University. And now, George’s daughter and his money go to Seattle University.

DAGI (DOUG) YUDOVICH is the Assistant Director of Departmental Computing for the University of Washington School of Medicine. One of the department’s primary BI responsibilities is developing database solutions using Access and SQL Server. Doug is an Administrator on UtterAccess forums and the UtterAccess wiki. Doug was a contributing author to Microsoft Access Small Business Solutions and the Access 2010 Programmer’s Reference. Additionally, Doug is an active member of the Pacifi c Northwest Access Developers Group (PNWADG) and a presenter in the Seattle Access Group (SAG). Doug has been awarded the Access MVP award since 2009.

ffirs.indd viii 7/18/2013 2:59:34 AM ABOUT THE TECHNICAL EDITORS/ CONTRIBUTORS

JERRY DENNISON has over 20 years of professional experience in the design and development of Microsoft Access database applications. He was one of the coauthors of Microsoft Access 2010 Programmer’s Reference (Wiley, 2010) and a contributing editor on other Access books. Jerry was a four-year recipient of the Microsoft Offi ce Access MVP award and is considered by his peers to be one of the foremost experts on the forms of data normalization. Jerry is the owner of TradeIt! Software Support Services, where he provides database consulting for businesses and other Access developers. He is an automation engineer at Rexam Healthcare Packaging, where he has worked for 22 years providing design, installation, and service support for automated inspection and test systems. Jerry lives with his wife of 24 years in Hixson, Tennessee.

PATRICK WOOD is the founder of Gaining Access Technologies, which provides consult- ing and custom software development. Originally a minister with a bachelor’s degree in biblical studies, he decided one day while he was between churches to develop an application to manage the many tasks involved with small- to medium-sized churches. That sparked his interest in Microsoft Access development, which led to the founding of his company. He learned ASP.NET to build the company website, and began developing SQL Server and Azure SQL databases. Pat’s articles about cutting-edge technology software develop- ment have been featured on several websites. He received the MVP Award for Microsoft Access in 2011. Pat still preaches at a small country church and enjoys taking walks, playing the guitar, hunting and fi shing, and spending time with his wife and three young grandsons.

F. SCOTT BARKER is the owner of AppsPlus, where he develops software for industries ranging from government agencies, insurance companies, banks, medical analy- sis fi rms, and even for Microsoft. Scott is a former Microsoft MVP and Microsoft employee, and was a member of the original Access team. He is also the author of a number of books on programming techniques using Microsoft technologies.

LEO (theDBguy™) is an Access MVP and moderator of the UtterAccess (UA) Forums. Since joining UA in 2007, Leo has made over 50,000 posts responding to questions and solving worldwide database dilemmas. Leo is a renowned Access expert with over 17 years of experience creating complex and intuitive Access solutions. He currently works as a Knowledge Manager for the Navy and manages the SharePoint portal for his com- mand, which supports over 1500 sites and more than 5500 users. Leo’s free time is dedicated to his family and to helping others leverage the powers of Access. In addition to being an active member and presenter at the Access Group of San Diego, he also shares his expertise through his website at www.accessmvp.com/thedbguy and his blog site at www.thedbguy.blog.com.

ffirs.indd ix 7/18/2013 2:59:34 AM TECHNICAL CONTRIBUTORS

GREG LINDHORST is the Principal Program Manager for Microsoft Access. He has been a member of the Microsoft Access engineering team since 2006, specializing in Access web apps and the pro- gramming model. Greg is a 20-year veteran at Microsoft, where he has worked on a wide range of application development tools in Offi ce and Visual Studio.

TOM VAN STIPHOUT is an Access MVP and the software development manager for Kinetik I.T. (www.kinetik-it.com), a premier provider of website design, SEO Internet marketing, software development, and computer network services and solutions in Phoenix, Arizona. Tom can be reached at [email protected].

JACK D. LEACH is an Access MVP with a strong background in the manufacturing business. He runs Dymeng Services (www.dymeng.com), a software development company in upstate New York, specializing in database and website solutions for small businesses. Jack can be found on www.utteraccess.com as jleach and at [email protected].

PETER DOERING is an Access MVP from Bamberg, Germany and an expert on migrations to SQL Server as well as SQL Azure and Offi ce 365. He’s been an independent developer on international projects for over 20 years. Peter is an acclaimed speaker at developer conferences in Europe and can be reached at [email protected].

GLEN KRUGER is an Access MVP and the Developer/Owner of KNK Consulting, assisting clients using Access and . Glen graduated from NAIT’s Computer Systems Technology (CST) program. He is an administrator of the UtterAccess Forums, and can also be reached at [email protected].

RIK HEPWORTH is a Microsoft vTSP and is the IT Director and head of the SharePoint Practice at Black Marble in the UK. With over 20 years in IT, Rik has worked in nearly every aspect of comput- ing. As a technology evangelist, Rik is a regular presenter at events around the UK and Ireland. He is easiest to fi nd on Twitter as @rikhepworth.

JONATHAN SAMPSON is an IE MVP and the Director of Support at AppendTo (appendTo.com). Jonathan is a full-stack developer who participates on stackoverfl ow.com and produces content for sampson.ms. Jonathan can be found on Twitter at @jonathansampson.

ffirs.indd x 7/18/2013 2:59:35 AM ACKNOWLEDGMENTS

AS A TEAM, WE WOULD LIKE TO EXPRESS our respect and appreciation for all of the people who contributed to the content, editing, and production of this book. This project truly epitomizes the concept of team work and community — especially the MVP community. We wanted this book to refl ect a wide perspective of expertise, but we didn’t anticipate the extent that would become. We reached around the world to leverage the expertise and passion of more than a dozen MVPs and experts from multiple disciplines. They invested an unprecedented amount of time, research, and resources to create this book and all of the supporting fi les and examples. Much like creating a solu- tion for your clients, the team has invested hundreds of hours to create or enhance developer tools that you can incorporate directly into your fi les. Over the course of a number of months, we conquered many hurdles, forged new connections, and helped to expand the functionality for Access web apps. We couldn’t have done it without the timely and invaluable efforts of our editors and technical contributors. These guys stepped up the moment they were called upon — and yes, that often meant at a point of near panic and urgency! Whether it was to resolve a version confl ict, expand into associated technologies, or to share tools and tech- niques, they generously shared their expertise and passion with the community and you, the readers. Please take a moment to read about our contributing editors and technical contributors. Of course, we wouldn’t have anything to write about if it weren’t for the incredible people on the Microsoft Access team. Their passion, dedication, and commitment to continuously expand and enhance Access are truly remarkable and inspiring. And we wouldn’t have a book without all of the editors and teams at Wiley — Bob, Rosemarie, Mary Beth, Nancy, and so many more. Plus a very spe- cial thank you to Chris Haviland for her remarkable skills, attitude, and encouragement while guiding us through months of reviews and production. Hmm, we’ve lost track of all the IOUs, but suffi ce it to say they should include a spa day, margaritas, chocolate dipped strawberries, and many massages! —The Authors

ffirs.indd xi 7/18/2013 2:59:35 AM FIRST AND FOREMOST, I WANT TO EXPRESS heartfelt appreciation to my family and dearest friends. I am immensely grateful for the opportunities, encouragement, and support that you continue to give me — personally, professionally, and for so many charitable endeavors. From the summit of Mt. Rainier to Uganda, and from fundraisers to books, you help me to stay focused, energized, and positive. Life can take us on quite a roller coaster ride fi lled with excitement, challenges, accomplishments, and les- sons. People and life have so many facets to relish and cherish; thank you for sharing the adventures. I also want to thank my colleagues, especially my MVP family, and everyone working on this book. This project has been like no other. When we started planning over 12 months ago, no one could have foreseen the amount of time and effort, or the extensive and ongoing changes, that would be involved. On behalf of myself and the entire Access community, I want to thank Ben and George for their vision, perseverance, and dedication to not only proving that an Access 2013 web app can be a robust business solution, but also providing a model and guide for others to follow. At critical moments, we also gained the invaluable expertise of Greg, Rik, and Jonathan. And to ensure that the traditional Access solutions demonstrate multiple perspectives and signifi cant new approaches, Doug and I incorporated content and tips from several of our MVP colleagues. Their involvement was also instrumental in completing a second round of technical reviews and testing; with many thanks to the Herculean efforts by Leo, who reviewed nearly all of the web chapters! Over the months, the team has undergone major transitions. Starting with a team of four authors, we added more than a dozen experts with a seeming exponential increase in coordination tasks. (Talk about lessons in project management!) Fortunately, those challenges also enriched my life with new friends as they joined our team. In working countless hours with Leo, Glen, Jack, and Pat, I gained the utmost respect for their expertise and dedication. Similarly, it is always a pleasure to work with my treasured colleagues, Tom, Peter, Jerry, and Scott. Your contributions helped make our book a truly remarkable and invaluable resource for all Access users. I am grateful for being able to share both the opportunity and the credits with so many. In recognition of the invaluable part that they played, we have designated a new role, Technical Contributor. These are remarkable people, so please take a moment to read their bios. This is truly a team effort and it epitomizes the spirit of the MVP community. With all of the turmoil on the book, I essentially took a 4+ month hiatus from consulting to support the team. So I also want to thank my clients for understanding the delays and for working with me to prioritize and schedule tasks so that we could meet their immediate needs and defer others. THANK YOU! I must also express very special, heartfelt appreciation to Christina Haviland — for her patience, guidance, humor, and compassionate understanding. Thank you for doing whatever it took to pull all of the pieces together to get everything to production and print! Your entryway should be over- fl owing with gift baskets, massage certifi cates, and a lifetime of gratitude. This project has tested and strengthened us individually and collectively. We did this for you, the Access community. Our greatest reward is helping you to help others, so it is with great pride that we present this book. As you benefi t from this compilation of resources, we hope that you too will realize that it is indeed priceless. This demonstrates yet again that life is fi lled with opportunities — celebrate them all! —Teresa Hennig

ffirs.indd xii 7/18/2013 2:59:35 AM WITHOUT THE HELP OF MANY WONDERFUL PEOPLE, this book would not have happened. Thank you, Greg Lindhorst, for helping us to set the parameters and providing guidance. Thank you, Rik Hepworth and Jonathan Sampson, for your excellent contribution when we found ourselves deep in the new and brave world of SharePoint and web development. I’m indebted to Jerry Dennison, Patrick Wood, and Leo theDBGuy™ for their meticulous diligence. Thank you, Christina Haviland and Teresa Hennig, for your guidance in the project. And most importantly, thank you, George Hepworth, for putting up with me! —Ben Clothier

THE CONTRIBUTIONS OF VARIOUS PEOPLE have been of great help in this journey. Greg Lindhorst, Access Program Manager at Microsoft, was an early and on-going source of key information about Access web apps. His help was invaluable. Later, when it became clear we had ventured some dis- tance into the SharePoint realm, we were fortunate to obtain the assistance of Rik Hepworth in shoring up that part of the narrative. We also appreciate Jonathan Sampson for his important con- tributions in reviewing some of the JavaScript code. I also want to thank the partners at Data & Domains, Eric Change and Frank Wilson, for their generosity in allowing me time off to work on this book. We also want to acknowledge the contributions of Leo “theDBGuy” and Jerry Dennison for their excellent reviews and comments that helped make the book better. —George Hepworth

SPECIAL THANKS to my coauthors — Teresa, Ben, and George. It’s been a wild ride, but riding along with you made it all worthwhile. Your support during the project was nothing short of amazing. Extra thanks to Teresa for leading the project with an unlimited amount of energy and enthusiasm. To my fellow MVPs and friends, Tom van Stiphout and Peter Doering — thank you for your help, insight, and input. Your knowledge seems boundless, and I’ve learned a lot from you. I’d also like to thank Pat Wood for taking the time to solve the puzzle after fi nding a missing piece. To Chris, our project editor, thank you for your patience and guidance throughout the project and for being a calm port in the storm. To the technical editors, technical advisors, and anyone else who helped iron out the wrinkles — thank you. —Dagi Yudovich

ffirs.indd xiii 7/18/2013 2:59:35 AM ffirs.indd xiv 7/18/2013 2:59:35 AM CONTENTS

INTRODUCTION xxvii

PART I: ACCESS DESIGN AND DEVELOPMENT

CHAPTER 1: INTRODUCTION TO ACCESS WEB APPS AND ARCHITECTURE 3

Deprecated Components 4 Access Data Projects 5 Jet Replication 6 Menus and Toolbars 6 Import/Export/Link to Jet 3.x and dBASE Files 7 PivotTables and PivotCharts 8 Collect Data via E-mail 8 SharePoint Workfl ow 8 Control Extension 9 Packaging Wizard 10 Wizard 10 Creating Access Web Databases 11 New Components Added 12 Database Compare 12 Audit and Control Management Server 13 What Is an App? 13 How Is an App Hosted? 15 How Is an App Distributed? 16 App Marketplace for Publicly Available Solutions 16 App Catalogs for Internal-Facing Solutions 16 How Are Security and Trust Managed in Apps? 18 Setting Up a SharePoint Site for Your Apps 20 Setting Up an Offi ce 365 Trial Account 21 Solving Business Problems 24 The Maid To Order Work Schedule Database 24 Summary 24 CHAPTER 2: DESIGNING TABLES 25

Creating a Blank App 26 Keeping Your Log Ins Straight 27

ftoc.indd xv 7/18/2013 4:15:48 PM CONTENTS

Creating Tables 29 Creating Tables Using Nouns 29 Creating Tables from Imported Data Sources 31 Creating Tables the Traditional Way 36 Tables and Their Related Views 37 Changes from Previous Versions 38 Text Data Type 38 Hyperlink Fields 39 Numeric Data Type 39 Date/Time Data Type 40 Image Data Type 40 Lookup Data Type 40 Field Properties 40 Linking SharePoint Lists 41 Summary 42 CHAPTER 3: UNDERSTANDING THE NEW 45

Web Navigation 46 Navigation Tools 46 The New Approach to Layout 51 The New 55 Mobile Devices Support 60 SharePoint and Offi ce 365 65 Creating a Web App via Team Site 67 Deleting Web Apps 69 Sharing Web Apps with Others 69 Summary 70 CHAPTER 4: DESIGNING VIEWS 73

View Design Surface 74 Ribbon 75 Tiles 76 Links and Creating Views 78 Field List 79 Popup Properties 84 Manipulating Control Placement 88 Duplicating a View 92 Action Bar and Action Bar Buttons 93 Action Bar Button Properties 93 Default Action Button 94 Custom Action Buttons 95

xvi

ftoc.indd xvi 7/18/2013 4:15:48 PM CONTENTS

Controls 96 Changed Controls 96 New Controls 103 Common Properties 108 Client Controls with No Counterparts 109 Web Browser Control 110 Summary 114 CHAPTER 5: CREATING QUERIES AND WRITING EXPRESSIONS 115

Query Architecture 116 SQL Server Views 116 Table-Valued Functions 117 Changes in the Query Designer 119 Creating, Editing, Saving, and Previewing Queries 119 Action Queries 125 Parameterized Queries 125 Aggregates, Unique Values, and Top Values 126 Query Properties 127 Functions and Expressions 128 Delimiters 129 Operator Diff erences 129 New Constants 131 Data Type Inspection and Conversion 132 String Functions 135 Date and Time Functions 139 Math Functions 141 Other Functions 145 Availability by Context 146 Summary 148 CHAPTER 6: Creating Macros 149 Why We Need a New Web-Compatible Language 150 Where We’ve Been 150 Access’s Traditional Role as Tool of First Choice 151 Macro Designer 152 Action Catalog 153 Expressions and Expression Builder 153 Data Macro Tracing 154 Parameter Box 155 Macro Links 155 Interacting with the Macro Designer 155

xvii

ftoc.indd xvii 7/18/2013 4:15:48 PM CONTENTS

Diff erent Types of Macros 157 UI Macros 157 Data Macros 157 Data Macro Architecture 158 UI Macro Architecture 159 Block Macro Action 160 Creating and Editing Data Macros 160 Creating a Standalone Data Macro 162 Using the Action Catalog 162 Using the Add New Action Drop-Down 162 Using Program Flow Actions 162 How to Use the LookupRecord Data Block 165 How to Use ForEachRecord and EditRecord 165 How to Use DeleteRecord 166 Creating and Editing UI Macros 166 How to Use SetProperty 168 How to Use ChangeView and OpenPopup 169 How to Use RequeryRecords 171 How to Use Data Entry Operations 171 Using UI and Data Macros Together 172 How to Create and Use Parameters 172 How to Return Values 174 Summary 175 CHAPTER 7: DESIGNING THE TABLE STRUCTURE 177

New Data Types 178 Short and Long Text Fields 178 Number Fields 182 Date/Time Fields 183 Currency 187 Yes/No 188 Hyperlink 188 Image 189 Calculated Fields 190 Lookup Fields 191 Validation Rules and Text 193 Field Level Validation 193 Record Level Validation 195 Editing Validation Rules with Existing Data 195 Validation Rules Design Consideration 196 Leveraging Calculated Fields 197 Creating Concatenated Fields 197

xviii

ftoc.indd xviii 7/18/2013 4:15:48 PM CONTENTS

Confi guration Tables 199 Tally Table 199 Utility Table 200 Summary 200 CHAPTER 8: DESIGNING THE USER INTERFACE 203

Naming Convention for Web Apps 204 Planning the User Interface 205 Reusing Create, Read, Update, and Delete Views 205 Eff ective Navigation Design 206 Traditional Navigation Patterns 206 Web Design Principles 211 Tile-Bound View and Popup Views 215 Creating a Splash Screen 216 Designing an Index Form 219 List View: Searching on a fi eld 219 Summary View: Searching on an Aggregated Value 223 Datasheet: Filtering Cumulatively 230 Creating a Query By View 237 SQL Construction 237 Techniques for Filtering 241 Design Requirements 246 Creating Filter Tables 248 Creating Data Macro to Clear Selections 249 Creating Query By View 249 Filtering Query 252 Building Data Macros to Populate Filter Tables 257 Building a Popup View to Display the Filter Results 260 Building a Click Event Handler 261 Summary 263 CHAPTER 9: SOLVING BUSINESS PROBLEMS WITH MACROS 265

Macro Design Considerations 266 When to Use Data Macros 266 When to Use UI Macros 268 On Start Macro 269 Using Freestanding Macros 270 Cloning a Record 270 Generating a Set of Records with Variable Parameters 278 Generating Records in Diff erent Tables 290 Updating and/or Deleting Several Records 294 Using Table Events 296 Performance Considerations 297 xix

ftoc.indd xix 7/18/2013 4:15:48 PM CONTENTS

Preventing Deletions of Completed Records 298 Acquiring Default Values from Other Tables 300 Maintaining a History of Change 301 Summary 303 CHAPTER 10: EXTENDING WEB APPS 305

Integration Options 306 Security Considerations 307 Introduction to Web Services 310 Linking a Web App for Additional Functionality 311 Locating and Adding the Locations Mapper App 311 Confi guring and Using the Locations Mapper App 315 Inlining a Web App in Access Web App 322 Adding a PayPal Button 333 Getting the PayPal HTML 333 Authoring a Custom Page in SharePoint Designer 336 Allowing Framing of Custom Page 338 Adding the PayPal HTML 339 Showing a PayPal Button on an Access Web App 340 Adding a Site Mailbox 341 Confi guration for a Site Mailbox 342 Setting Up the Site Mailbox 343 Team Site Mailbox as a Shared Tool 347 Using with a Web Browser Control 362 Building a Page to Handle JavaScript Code 363 Development Experience 366 Adding the Charting Page to Access Web App 368 Consuming ZIP-Lookup Web Services in the Client 371 Creating a User Account for the Web Service 372 Library References and Code 373 Summary 394 CHAPTER 11: CONNECTING TO YOUR WEB APP 397

Info Backstage 398 Connections 399 Enable/Disable Connection 400 Getting Connection Details 401 Reset Passwords 401 Using the Access Client 401 Adding VBA Code to Relink 406 Best Practices 409

xx

ftoc.indd xx 7/18/2013 4:15:48 PM CONTENTS

Using Excel 412 Creating an ODC Connection 412 Creating an Excel Table 415 Creating an Excel PivotChart 416 Creating an Excel PivotTable 420 External Data Considerations 421 Sharing Excel Workbooks on the Web 425 Using SSMS 430 Connecting to a Web App Database 430 Adding a Linked Server on the Web App Database 433 Querying Data in a Linked Server 437 Using Linked Server Programmability Objects 442 Summary 446 CHAPTER 12: WEB APPS IN THE ENTERPRISE 449

Creating a Document Library 450 Creating a Custom Content Type 452 Importing Image Files 455 Customizing a Library 456 Customizing a Library Ribbon 458 Version Control 460 Customizing an App Package 463 Linking to a Template File 467 Synchronizing Data Between App Databases 468 Local Diff erential Backup 468 Choosing Approaches 479 Summary 479 CHAPTER 13: IMPLEMENTING SECURITY MODELS FOR THE ACCESS WEB APP 481

Security Considerations 482 File-Based Security 482 Agent-Based Security 482 Securing Web Apps on SharePoint 483 Security in the Application Layer 484 SharePoint Security 485 Team Sites and Personal Storage 486 Managing User Accounts 486 Extending Permissions 490 External User Accounts 491 Anonymous Access 492

xxi

ftoc.indd xxi 7/18/2013 4:15:48 PM CONTENTS

Securing Web Apps in the Web Browser 494 Using Subsites to Restrict Users to Specifi c Apps 498 Sites and Subsites 499 Traditional Methods for Security in Client Solutions 509 Web App Linked File Security 513 DSN-Less Linking and Relinking 514 Password Storage/Non-Storage 515 Local SQL Server 532 Summary 537 CHAPTER 14: DEPLOYING ACCESS WEB APPS 539

Deploying Access Web Apps 540 Web Apps and App Catalogs 540 On-Premises SharePoint Server 541 Versioning Web Apps 551 Summary 562

PART II: CLIENT-SERVER DESIGN AND DEVELOPMENT

CHAPTER 15: MANAGING DATA SOURCES 565

Normalization 566 First Normal Form: Eliminate Repeating Groups 566 Second Normal Form: Eliminate Duplicate Data 567 Third Normal Form: Eliminate Fields That Do Not Depend on the Key 567 Other Normalization Forms 568 Normalization Examples 568 Un-Normalized Table 568 First Normal Form: Eliminate Repeating Groups 568 Second Normal Form: Eliminate Duplicate Data 569 Third Normal Form: Eliminate Fields That Do Not Depend on the Key 569 Primary Keys 570 Overview of Access Files and the Database Engine 572 Other Data Sources 572 Overview of ODBC Linking 573 Managing Linked Objects 576 Querying External Data Eff ectively 579 Linked Object Performance and 579 Passthrough Query and T-SQL 580 Comparing Access SQL and T-SQL 581 Summary 582

xxii

ftoc.indd xxii 7/18/2013 4:15:48 PM CONTENTS

CHAPTER 16: PROGRAMMING USING VBA, APIS, AND MACROS 585

VBA 586 Procedures 586 User-Defi ned Functions 586 Error Handling 591 Debugging 596 Leveraging Queries 597 Enhancing Query Techniques 597 Query by Form 604 Creating a Query On the Fly Using VBA 606 API 608 Obtaining Documentation for API Functions 609 Mapping Data Types 609 VBA User-Defi ned Types and C-Style Structs 610 Pointers and Handles 611 32-Bit vs. 64-Bit 611 Putting It All Together: Create and Manage an Explorer Window 613 API Declaration 617 Declaring the Enumeration Function 618 Declaring the Callback Function 619 Determining the Class Name of a Window 619 Preparing the EnumChildProc for Two Diff erent Uses 620 Creating the Main Procedure 620 Retrieving Window Information 621 Tips and Techniques 622 Introduction to Data Macros 624 Why Use Data Macros? 625 Diff erences in Client and Web Data Macros 625 Use Cases for Data Macros 626 Creating Data Macros 628 Maintaining Calculated Values to Support Indexing 628 Maintaining Quantity On Hand to Support Business Logic 631 Data Macros and VBA 640 Summary 641 CHAPTER 17: CREATING INTUITIVE FORMS 643

Creating Intuitive Forms 644 Clean Layout 645 Guiding the User Through the Process 645 Showing and Verifying Data in a Timely Manner 646 User-Friendly Messages and Tips 646

xxiii

ftoc.indd xxiii 7/18/2013 4:15:48 PM CONTENTS

Leveraging Built-in Functionality 647 Textbox 647 Label 648 Command Buttons 649 Split Forms 650 Pop-up, Modal, or Dialog Forms 652 The Demo Forms 653 Tag Property 653 Displaying Images 654 List and Combo Boxes 656 Datasheet View Search Forms 657 Multiple Instances of a Form 660 Multi-Value Fields 663 Appending MVFs 664 Appending Attachments 665 Report Runner 668 Creating the Foundation 668 Setting Up the Report and Its Criteria Fields 669 Selecting the Criteria and Running the Report 673 Summary 685 CHAPTER 18: CREATING POWERFUL REPORTS 687

Introduction to Reports 688 Creating Reports 689 Fundamentals 689 Creating and Customizing Reports 693 SubReports 696 Drill Down Reports 698 Report Examples 700 Grouping Data 700 Reports with Simple Criteria 701 Reports with Simple Groupings 702 One Flexible Report 702 Calling the Criteria Form from the Report 706 Reports that Compare Values 706 Professional Polish 709 Report Criteria 709 Confi dentiality Statement 711 Page Numbers and Report Date 711 Report Name 711 Using Work Tables 711

xxiv

ftoc.indd xxiv 7/18/2013 4:15:48 PM CONTENTS

Filling Out PDF Forms Using Access 712 Using Reports 712 Using an XFDF fi le 713 Summary 715 CHAPTER 19: AUTOMATING AND INTEGRATING WITH OTHER PROGRAMS 717

Overview of Interoperability 717 Getting Started with Automation 719 Declare and Instantiate Variables 721 Early Binding Versus Late Binding 722 Automating Offi ce Programs 724 Integration 725 Integration with Excel Using Ribbons, Menus, and Macros 725 Referencing the Excel Object Library 728 Working with the Excel Object Model 728 Using Automation to Send Data to Excel 728 Creating an Excel PivotTable from Access 731 Generating an Excel Chart from Access 734 Word Integration 737 Integration with Word Using Ribbons, Menus, and Macros 737 Referencing the Word Object Library 737 Working with the Word Object Model 738 Sending Access Data to Word with Automation 738 Using Access Automation to Create Word Tables 741 PowerPoint Integration 744 Setting a Reference to the PowerPoint Object Library 745 Working with the PowerPoint Object Model 745 Creating a Presentation from an Access Table 745 Outlook Integration 749 Sending Outlook Mail Using a Macro Action 750 Referencing the Outlook Object Model 751 Sending Mail Using VBA and Automation 751 Reading and Moving Mail Using VBA and Automation 753 Creating Other Outlook Items Using VBA and Automation 755 Integrating Access with Other Applications 759 Summary 762 CHAPTER 20: SECURING, DEPLOYING, AND MAINTAINING ACCESS APPLICATIONS 763

User Level Security and Audit Trail 764 Local User Table 765

xxv

ftoc.indd xxv 7/18/2013 4:15:48 PM CONTENTS

Network Identity 766 Network Identity with a User Table in Access Database 766 Diff erent Front-end Files for Diff erent User Roles 767 Security Summary 767 Converting from .mdb with User Level Security to .accdb 768 Audit Trail 769 Using VBA 770 Using Data Macros 771 Remote Query 772 Deployment Considerations 772 Deploying Front-end Files 773 Auto-Updating the Front End 775 Deploying Back-end Changes 776 Maintaining Diff erent Environments 778 Development, Test, and Production Environments 778 Promoting Files from Test to Production 784 Version Control 785 Data Maintenance 786 Automating Backups 786 Automating Maintenance 789 How to Kick Users Out of the Application 791 Ownership of Code 791 Intellectual Property Rights 791 Trial Version 792 Summary 794 CHAPTER 21: MAXIMIZING SQL SERVER CAPABILITIES 795

Upsizing 795 When to Upsize 796 The Upsizing Process 802 Things to Watch for When Upsizing 805 Working with SQL Server as the Back End 807 SQL Server Management Studio 807 SQL Server Objects 814 Troubleshooting 817 Summary 820

INDEX 823

xxvi

ftoc.indd xxvi 7/18/2013 4:15:49 PM INTRODUCTION

THANK YOU FOR BUYING THIS BOOK. We wrote it with you (the developer, the manager, the busi- ness owner) in mind to provide valuable tips, techniques, and tools applicable to a wide spectrum of experience, expertise, and industries. Each time you use one of the tools that we’ve provided, you’ve more than recouped the price of the book. As the most popular database system in the world, Microsoft Access keeps getting better with each new version. The new Access 2013 provides signifi cant new features that will enhance your experi- ence of building web-based and traditional database applications. This book shows you everything you need to get started immediately, and it guides you through exploring a multitude of program- ming tools and techniques for building Access 2013 solutions. Written by a team of Microsoft Access MVPs, this book leverages our expertise and passion for Access. In expanding the reach of Access, we incorporated the knowledge and experience of over a dozen experts to consult, test, and provide examples working with SharePoint, SQL Server, .NET, and web development. And to make sure that we could provide a model for a robust business solu- tion, we worked closely with the Microsoft Access team to be at the forefront of defi ning, testing, and implementing the new features for Access 2013 web apps. In creating the demo apps and writing this book, our team pushed the limits of what was provided and helped to delineate the required functionality. We not only blazed the way into a new frontier, but we also expanded the horizon. In doing so, we created an application that will guide you on a successful journey to create and deploy your own Access web apps. With the countless variations of platforms and confi gurations, there are unprecedented opportunities for security and other issues that you might encounter. To help you avoid and resolve such challenges, we have also provided a list of some of the potential issues you may encounter. The chapters in Part II, “Client Server Design and Development,” draw from resources far beyond the author team. We wanted to ensure that we addressed the needs of developers from a wide spec- trum of expertise and industries. To that end, we enlisted the contributions of fellow MVPs from around the world. That culminated in providing you with tools, tips, techniques, and examples that incorporate the experience, style, and perspective of more than a dozen developers. The emphasis is on creating cost-effective solutions based on real-world scenarios. The techniques in this book focus on rapid development, stability, and automation. They will help you to work more effectively with multiple data sources and integrate with other programs, leverage SQL Server, and deploy polished, professional solutions. In addition to demonstrating how to enhance and work with Access’s built-in features, we also dis- cuss critical changes that may affect legacy programs — such as the deprecation of ADPs. Our book clearly communicates these changes and future alternatives so that developers and businesses can make informed decisions about how to move forward and how to maintain their applications when incorporating the new features.

flast.indd xxvii 7/18/2013 3:00:21 AM INTRODUCTION

This book encompasses thousands of hours of development, testing, writing, and reviews. We designed it to serve as a learning manual, a reference, and a means to expand your expertise that will pave the way to new opportunities. The more you use it, the greater your rewards.

WHO THIS BOOK IS FOR

Professional Access 2013 Programming is a complete guide to the latest tools and techniques for building Access 2013 applications for both the web and the desktop. The information and examples are structured so that developers and businesses can make decisions and move forward with confi - dence. Whether you want to expand your expertise with client-server deployments or start develop- ing web apps, you will fi nd this book to be an invaluable manual, companion, and reference. Access 2013 web applications are completely new, so the material is new to everyone. The web sec- tion starts with the basic fundamentals and lays a strong foundation. The subsequent chapters then provide a step-by-step process to build the structure resulting in a robust web application. In the client-server section, the premise is that readers have been using Access and have some famil- iarity with VBA, so we breeze through the fundamentals to provide a foundation and then quickly dig into features, development techniques, and examples that you can relate to. The emphasis is on cost-effective solutions that address rapid development, stability, working with multiple data sources, integration with other programs, automation, and leveraging SQL Server. The book is also an informative guide for decision makers who are seeking to identify and evaluate available options to make informed decisions and invest in solutions that will support their current and anticipated needs. You will see solutions to real-world scenarios that have strong correlations to your activities and needs.

WHAT THIS BOOK COVERS

This book is the professional developer’s resource for Access 2013 web apps and traditional client solutions. As the training manual and proving ground for Access 2013 web apps, this book shows you everything you need to immediately start developing new solutions, upgrading existing projects, and planning future enhancements. It uses real-world scenarios to demonstrate how to use Access to provide custom solutions — whether you are working with a traditional client-server, web, or hybrid application. The book is structured to support the two major deployment environments for Access 2013: Web applications and the traditional client-server (desktop) solutions. But regardless of your current needs or focus, you will fi nd invaluable tips and techniques in both sections. In a nutshell, this book: ➤ Explores the new development environment for Access web apps ➤ Focuses on the tools and techniques for developing robust web applications

xxviii

flast.indd xxviii 7/18/2013 3:00:22 AM