Share this Page URL

Part I: Getting Started > Using Visual Basic to Automate Your Database - Pg. 137

137 Chapter 5. Using Visual Basic to Automate Your Database In this chapter, you will learn how to: · · · · · · · · · · Convert a macro to Visual Basic code Create an event procedure Create an Access code module Declare variables Control database operations with standard programming statements Set up options in the Visual Basic Editor Use the Visual Basic online help Add code to handle errors and debug your code Work with data using data access object models Use the object model for another Microsoft Office application from Access In this chapter, we'll cover some of the fundamental concepts and techniques you need to know to program an Access database with Visual Basic. By adding code to a database, you can automate routine tasks as well as direct the flow of database operations. We'll demonstrate elements you use in a program, including variables, constants, objects, methods, and properties; explain some basic programming structures; and describe features of the Visual Basic Editor. Later in this chapter, we'll look at ways to help prevent and handle errors that might occur when a Visual Basic program runs, describe examples that show how to use Access database objects in a program, and demonstrate how to work with the data in a database by using data access technologies known as Data Access Objects (DAO) and Microsoft ActiveX Data Objects (ADO). To work through this chapter: · You should understand the basics of tables and fields. You'll find this information in Chapter 1, "The Hel- loWorld Database"; Chapter 2, "The Basics of Database Design"; Chapter 3, "Managing the Consistency, Format, and Integrity of Your Data." You should also understand the requirements for importing data and for creating a simple macro. For information, see Chapter 4, "Importing and Linking to Data." Because this chapter is longer than most in this book, you might consider working through the chapter in two or three sessions. You'll learn only the basics in a single chapter about Access and Visual Basic, but even with a basic understanding of Visual Basic, you can add a lot of practical and valuable features to an Access database. You'll see some of the examples we illustrate in this chapter in Part II of this book, "The Database Application," when we build forms, reports, and data access pages. In Chapter 17, "Using Visual Basic to Manage Data," we'll look at how to use ADO in more detail.