access vba programming for dummies (isbn - 0764574116)

410 735 0
access vba programming for dummies (isbn - 0764574116)

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

by Alan Simpson Access VBA Programming FOR DUMmIES ‰ 00a_574116_ffirs.qxd 7/27/04 9:03 PM Page i 00a_574116_ffirs.qxd 7/27/04 9:03 PM Page iv by Alan Simpson Access VBA Programming FOR DUMmIES ‰ 00a_574116_ffirs.qxd 7/27/04 9:03 PM Page i Access VBA Programming For Dummies ® Published by Wiley Publishing, Inc. 111 River Street Hoboken, NJ 07030-5774 www.wiley.com Copyright © 2004 by Wiley Publishing, Inc., Indianapolis, Indiana Published by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permis- sion of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4355, e-mail: brandreview@ wiley.com. Trademarks: Wiley, the Wiley Publishing logo, For Dummies, the Dummies Man logo, A Reference for the Rest of Us!, The Dummies Way, Dummies Daily, The Fun and Easy Way, Dummies.com, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates in the United States and other countries, and may not be used without written permission. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REP- RESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CRE- ATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FUR- THER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ. For general information on our other products and services or to obtain technical support, please contact our Customer Care Department within the U.S. at 800-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. Library of Congress Control Number: 2004104566 ISBN: 0-7645-7411-6 Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 1O/RT/QY/QU/IN 00a_574116_ffirs.qxd 7/27/04 9:03 PM Page ii About the Author Alan Simpson is the author of over 90 computer books on databases, Windows, Web site design and development, programming, and networking. His books are published throughout the world in over a dozen languages and have millions of copies. Alan has also taught introductory and advanced computer programming courses at San Diego State University and the UCSD Extension. He has served as a consultant on high-technology, education- oriented projects for the United States Navy and Air Force. Despite that, Alan has no fancy job title because he has never had a real job. 00a_574116_ffirs.qxd 7/27/04 9:03 PM Page iii 00a_574116_ffirs.qxd 7/27/04 9:03 PM Page iv Dedication To Susan, Ashley, and Alec, as always. Author’s Acknowledgments Even though only one author’s name appears on the cover, every book is a team project. This author would like to thank the many people who contributed to this book. To Matt Wagner and all the folks at Waterside Productions, a big thanks for helping to make it all happen. Many thanks to Terry Varveris and Christopher Morris at Wiley for their enduring patience (and Terry’s relentless friendly reminders). And of course, thanks to all the people at home for putting up with the neglect while Daddy cranked out yet another book. 00a_574116_ffirs.qxd 7/27/04 9:03 PM Page v Publisher’s Acknowledgments We’re proud of this book; please send us your comments through our online registration form located at www.dummies.com/register/. Some of the people who helped bring this book to market include the following: Acquisitions, Editorial, and Media Development Project Editor: Christopher Morris Acquisitions Editor: Terri Varveris Senior Copy Editor: Teresa Artman Technical Editor: Wiley-Dreamtech India Pvt Ltd Editorial Manager: Kevin Kirschner Media Development Specialist: Angela Denny Media Development Manager: Laura VanWinkle Media Development Supervisor: Richard Graves Editorial Assistant: Amanda Foxworth Cartoons: Rich Tennant, www.the5thwave.com Composition Project Coordinator: Courtney MacIntyre Layout and Graphics: Andrea Dahl, Denny Hager, Joyce Haughey, Michael Kruzil, Lynsey Osborn, Melanee Prendergast, Jacque Roth, Heather Ryan, Mary Gillot Virgin Proofreaders: Laura Albert, TECHBOOKS Production Services Indexer: TECHBOOKS Production Services Publishing and Editorial for Technology Dummies Richard Swadley, Vice President and Executive Group Publisher Andy Cummings, Vice President and Publisher Mary Bednarek, Executive Editorial Director Mary C. Corder, Editorial Director Publishing for Consumer Dummies Diane Graves Steele, Vice President and Publisher Joyce Pepple, Acquisitions Director Composition Services Gerry Fahey, Vice President of Production Services Debbie Stailey, Director of Composition Services 00a_574116_ffirs.qxd 7/27/04 9:03 PM Page vi Contents at a Glance Introduction 1 Part I: Introducing VBA Programming 7 Chapter 1: Where VBA Fits In 9 Chapter 2: Your VBA Toolkit 21 Chapter 3: Jumpstart: Creating a Simple VBA Program 35 Part II: VBA Tools and Techniques 49 Chapter 4: Understanding Your VBA Building Blocks 51 Chapter 5: Controlling Access through VBA 71 Chapter 6: Programming Access Forms 87 Part III: VBA, Recordsets, and SQL 115 Chapter 7: The Scoop on SQL and Recordsets 117 Chapter 8: Putting Recordsets to Work 147 Part IV: Applying VBA in the Real World 173 Chapter 9: Creating Your Own Dialog Boxes 175 Chapter 10: Customizing Lists and Drop-Down Menus 201 Chapter 11: Creating Your Own Functions 241 Chapter 12: Testing and Debugging Your Code 267 Part V: Reaching Out with VBA 295 Chapter 13: Using VBA with Multiple Databases 297 Chapter 14: Integrating with Other Office Applications 317 Part VI: The Part of Tens 349 Chapter 15: Ten Commandments of Writing VBA 351 Chapter 16: Top Ten Nerdy VBA Tricks 357 Chapter 17: (Way More Than) Ten Shortcut Keys 367 Index 371 00b_574116_ftoc.qxd 7/27/04 9:03 PM Page vii 00b_574116_ftoc.qxd 7/27/04 9:03 PM Page viii [...]... all the information you need to get started If you’ve already been using VBA for a few months or years, you can skim this part If you don’t know a VBA procedure from a PTA Meeting, you might want to take a closer look at Part I before venturing forth to the upcoming parts 3 4 Access VBA Programming For Dummies Part II: VBA Tools and Techniques Here you discover how to write VBA code to make Access do... not built into Access That’s where VBA comes in When you want Access to perform a task that it doesn’t already know how to perform, you write the steps to be performed in the VBA programming language When you’re writing VBA code or just looking at some VBA code written by someone else, Access doesn’t do anything Access doesn’t actually perform the steps described by that code until Access executes... Chapter 1: Where VBA Fits In 2 Right-click the name of any form or report and choose Design View To see the class module for the open form or report, click the Code button on the toolbar or choose View➪Code from the Access menu bar (see Figure 1-5 ) Figure 1-5 : Class modules are accessible from form and reports Design views Form open in Design view From VBA to Access When you open a module, whether... use VBA “instead of” other objects like tables and forms You use VBA to enhance the capabilities of other object types Therefore, it makes no sense to even try VBA until you have a firm grasp of the purpose and capabilities of those other object types in Access Understanding VBA Visual Basic is a programming language — a language for writing instructions that a computer can read and process VBA is a programming. .. version of Access So now, before launching into VBA, take a moment to discuss what tables, queries, forms, and reports are all about, and how VBA fits into the overall scheme of things 10 Part I: Introducing VBA Programming Taking a Look at Access Access, part of the Microsoft Office suite, is a huge database management system that you work by using modern object-oriented methods (The term object-oriented... multiple related tables ߜ Forms: Access forms are similar to printed fill-in-the-blank forms, but they allow you to view and change data stored in Access tables ߜ Reports: Reports are objects that define how data should be presented on printed reports ߜ Pages: Pages are similar to forms, but users can access data in tables through a Web browser rather than directly through Access ߜ Macros: Macros provide... you intended Part V: Reaching Out with VBA VBA isn’t a programming language solely for Microsoft Access You can use VBA to customize all the Microsoft Offce application programs, including Microsoft Word, Microsoft Excel, and Microsoft Access Furthermore, VBA can import data from, and export data to, a variety of formats that extend its reach even beyond Microsoft Access Part V will show you how that’s... Understanding how VBA works T his is a book about using Visual Basic for Applications (VBA) , which is a programming language that helps you program, tweak, and squeeze productivity from Access VBA, which is embedded in Access, is a sophisticated set of programming tools that you can use to harness the power of a packaged application like Access Just like you need to know how to walk before you can run,... create queries, forms, reports, and macros to help manage those data All these steps take place before you even get into VBA So in this book, I have to assume that you’re already an experienced Access user who needs more than what queries, forms, reports, and macros can provide If you’re new to Access, this is not a good place to start If you need to brush up further on Access, Access 2003 For Dummies (John... you write VBA code, you’re actually writing a set of instructions that Access can perform at any time, over and over again Seeing Where VBA Lurks In an Access database, VBA code is stored in modules Despite the fancy name, a module is basically an electronic sheet of paper on which VBA code is typed The two types of modules in Access are ߜ Standard module: A page that contains VBA code that’s accessible . Alan Simpson Access VBA Programming FOR DUMmIES ‰ 00a_574116_ffirs.qxd 7/27/04 9:03 PM Page i 00a_574116_ffirs.qxd 7/27/04 9:03 PM Page iv by Alan Simpson Access VBA Programming FOR DUMmIES ‰ 00a_574116_ffirs.qxd. 367 General VBA Editor Shortcut Keys 369 Debug Shortcut Keys 369 Index 371 Access VBA Programming For Dummies xiv 00b_574116_ftoc.qxd 7/27/04 9:03 PM Page xiv Introduction W elcome to Access VBA Programming. and event for the code 92 Access VBA Programming For Dummies x 00b_574116_ftoc.qxd 7/27/04 9:03 PM Page x Showing and hiding controls 95 Making controls read-only 96 Responding to Form Events

Ngày đăng: 07/04/2014, 12:47

Từ khóa liên quan

Mục lục

  • Access VBA Programming For Dummies

    • About the Author

    • Dedication

    • Author’s Acknowledgments

    • Contents at a Glance

    • Table of Contents

    • Introduction

      • About This Book

      • Conventions Used in This Book

      • What You’re Not to Read

      • Foolish Assumptions

      • How This Book Is Organized

      • Icons Used in This Book

      • Web Site for This Book

      • Where to Go from Here

      • Part I: Introducing VBA Programming

        • Chapter 1: Where VBA Fits In

          • Taking a Look at Access

          • Understanding VBA

          • Seeing Where VBA Lurks

          • Finding Out How VBA Works

          • Chapter 2: Your VBA Toolkit

            • Using the Visual Basic Editor

            • Referring to Objects from VBA

            • Setting References to Object Libraries

Tài liệu cùng người dùng

Tài liệu liên quan