Making Access Project and Data Technologies Choices
Total Page:16
File Type:pdf, Size:1020Kb
05 0672321025 CH03 8/10/01 8:20 AM Page 71 Making Access Project and CHAPTER Data Technologies Choices 3 IN THIS CHAPTER • Using Microsoft Database Versus Access Database Project 72 • Using DAO Versus ADO Versus XML 75 05 0672321025 CH03 8/10/01 8:20 AM Page 72 The Root of Power Programming 72 PART I Before Access 2000, when you created an application, you had to plan whether you wanted to use a Jet (the database engine Access uses natively) or a client/server back end. Depending on the type of back end chosen, you would use various methods to create the application. Although this is still the case, you now have more choices to make when starting on a project. Now, in addition to the back-end choice, you must decide what type of database container to use: the traditional MDB or ADP. The other choice to make is the method of accessing the data while working in VBA: DAO (Data Access Objects), which has been used since Access 2, or ADO (ActiveX Data Objects), the data-access technology now used throughout a number of Microsoft products, including Visual InterDev. You now have an additional choice of XML (Extensible Markup Language), which transfers data between systems and applications. Helping you decide which technology to use in which case is what this chapter is all about. When you first look at the choices, it’s hard to see when one should be used over another. NOTE This chapter isn’t intended as an in-depth discussion of these technologies. Each is dis- cussed at length in various parts of the book. At the end of this chapter you can see where each technology is discussed further. Using Microsoft Database Versus Access Database Project The choice of whether to use MDB versus ADP actually follows the Jet versus client/server choice pretty closely. ADP, used as a front end for SQL Server, contains tools for editing not only Access objects such as forms and Data Access Pages, but also views and stored procedures. Microsoft also provides a desktop solution to use with the ADP, known as the Microsoft Data Engine (MSDE). This is aimed at small workgroup applications. Generally, you want to use an ADP with MSDE when you think you will be moving your application to the full functionality of SQL Server 7/2000. TIP You can also use the MSDE to test your ADP and then easily modify the connection string to hook you up to the production database. Chapter 24, “Developing SQL Server Applications by Using ADP,” covers more about MSDE. 05 0672321025 CH03 8/10/01 8:20 AM Page 73 Making Access Project and Data Technology Choices 73 CHAPTER 3 Looking at the Objects Used in Each Your standard MDB contains the usual objects, plus the Data Access Pages (DAPs) available as of Access 2000. Data Access Pages let you create an application in Access, and then move it over to the Web. You can read more on DAPs in Chapter 12, “Working with Data Access Pages.” Figure 3.1 shows the standard Access Database window displaying the Northwind sample data- base that comes with Access. 3 T ECHNOLOGY P M ROJECT AND FIGURE 3.1 AKING Here is the good old MDB you’ve come to know and love. A CCESS C D HOICES ATA NOTE Features found in both ADP and MDB are Data Access Pages and the Outlook style toolbar. The Groups feature (refer to Figure 3.1) is great when you’re working on one area of a project and want to group multiple objects for development purposes. In Access 2002, you can choose to work with Access 2000 or 2002 file formats (notice the title bar in Figure 3.1). Both Northwind.mdb and NorthwindCS.adp are provided in the Access 2000 file format. You can take the same Northwind database and upsize it to SQL Server and an ADP by choos- ing Database Utilities, Upsizing Wizard from the Tools menu while in the Database window. (If you decide to do this, you must have the MSDE installed and running or be connected to SQL Server. For more information on how to do this, see Chapter 24.) After the upsizing is done, you see the ADP in Figure 3.2, which, although it looks similar to the standard MDB, has different objects. Table 3.1 lists the objects found in each and how they correspond with each other. 05 0672321025 CH03 8/10/01 8:20 AM Page 74 The Root of Power Programming 74 PART I Queries, views, functions, and stored procedures Tables Database Diagrams FIGURE 3.2 In a ADP, the objects in Tables, Queries (now consisting of views, functions, and stored procedures), and Database Diagrams are actually stored in the back end. TABLE 3.1 Comparing Objects Between MDB and ADP MDB ADP Table Table* Relationship Database Diagram* Select Query View* Action Query Stored Procedure* Parameterized Query Stored Procedure* Form Form Report Report Data Access Page Data Access Page Macro Macro Module Module * Stored in the back-end database on the server. TIP Stored procedures can actually buy you everything that views can and more, although they’re a little harder to create. One drawback to views is that you can’t 05 0672321025 CH03 8/10/01 8:20 AM Page 75 Making Access Project and Data Technology Choices 75 CHAPTER 3 specify ordering. You can use the View Designer to create a SELECT statement and then copy the SQL text into the stored procedure editor, where you can add parame- ters and ordering. For more on this, check out Chapter 24. Using DAO Versus ADO Versus XML How you design your application also varies with which front-end type you use. The choice of using DAO versus ADO is fast becoming a moot point because Microsoft is aiming that way, made even more apparent in Access 2002 since the company made only bug fixes to DAO, not really any enhancements. As mentioned at the beginning of this chapter, DAO has been around for several versions of Access and has pretty well been the standard for database manipulation with Jet from VB and all Office products. Then along came ADO. ADO came on the scene because DAO was written and optimized mainly for Jet. The idea is that with the way the world is going with the Internet and multiple 3 T ECHNOLOGY data sources, an easier, more generic way to access that data was believed to be needed— P M ROJECT AND hence, ADO. AKING A CCESS C D HOICES NOTE ATA In Access 2000/2002, not all functionality is provided in ADO to replace DAO. For example, when using objects and methods such as Me!subForm.Requery, the DAO object model is still used under the covers. Where using DAO requires a reference to one object model, ADO requires three to cover most of the same ground. You can see this in Figure 3.3, by choosing References from the Tools menu in the VBE. As just mentioned, DAO uses one library, Microsoft DAO 3.6 Object Library, whereas ADO uses three (see Table 3.2). Chapter 5, “Introducing ActiveX Data Objects,” discusses each library in more detail. 05 0672321025 CH03 8/10/01 8:20 AM Page 76 The Root of Power Programming 76 PART I FIGURE 3.3 When converting to ADO from DAO, you can have code that references both in the same application. TABLE 3.2 ADO Libraries and Their Purpose Library Purpose Microsoft ActiveX Objects 2.6 Library Data manipulation Microsoft ADO Ext. 2.6 for DDL and Security Data definition and security Microsoft Jet and Replication Objects 2.6 Replication TIP Whichever version you want as the default, place it before the other. For example, if I want to use ADO recordsets as the default, I move its library up before DAO’s. This is important because when you Dim something as a recordset, you want to get the right type. Otherwise, errors can occur. You can also use the Library.ClassName syntax: Dim rstX As ADODB.Recordset Dim dynY As DAO.Recordset NOTE In revising this book for Access 2002, I decided to fall into line and switch all the code to ADO. However, if you want to see most of the examples in DAO, you can pick up a copy of my Microsoft Access 2000 Power Programming. Trying to cover both ADO and DAO to the extent of all the examples would make this book about 2,000 pages long. 05 0672321025 CH03 8/10/01 8:20 AM Page 77 Making Access Project and Data Technology Choices 77 CHAPTER 3 Just because you’re using SQL Server as a back end doesn’t automatically mean that you should use an ADP with ADO. There are still good reasons to use Jet-linked table SQL Server applications in many situations: • Your application requires storage on the front end, such as user preferences or SQL strings in tables. In an ADP, you have to use the Registry or file system for such storage. • Your application requires users to be able to create and store ad hoc queries, and you can’t or don’t want to give the users permissions to create server objects. • Linked-table applications are still better at joining information from heterogeneous data sources (ISAM stuff). Although I mentioned that ADO is harder to use than DAO in the previous edition of this book, it really is just a matter of getting used to the new syntax.