Beginning Access 2002 VBA (Programmer to Programmer)

One of the great benefits of Access 2002 is its ability to interact with SQL Server. This process has been improved with each release of Microsoft Access, and Access 2002 continues the process. The Upsizing Wizard was introduced to Access in Version 2, but not actually included as part of the Access Menu until Access 2000. Over this period the wizard has been improved but is still limited in how it will move your database to SQL Server. In this section we look at how to move your Access file to SQL Server 2000.

Before you Start

Of course, before you begin the move to SQL Server, that is running the upsizing wizard on your MDB file, there are a few things to do:

A really useful tool is Upsizing Pro which is available from: http://www.ssw.com.au/ssw/UpsizingPRO/Default.aspx . Upsizing Pro is used before you upsize and highlights any problems you may have with your mdb file before you actually upsize. This tool can save you hours of work looking through tables and code, and is well worth investing in.

The upsizing wizard is designed to move your tables to SQL Server by hook or by crook, everything else, forms, reports and queries are secondary to that main task, and the result can be a bit hit and miss as we shall see. Let's get right to it, and as we go, you will see some of the problems that can arise when moving databases.

Try It Out-Using the Upsizing Wizard

  1. To run the upsizing wizard from the Access main menu select Tools Database Utilities Upsizing Wizard to begin the process.

  2. The first step in the process requires you to either create a new SQL Server database or work with an existing database. On this occasion we will create a new database. Accept the default Create new database and click Next .

  3. You will then be prompted to select the name of the SQL Server instance to use to store the database. In the majority of cases, you will have a single instance, so you can simply accept the default database. If not, always check that your connection is to the correct instance of SQL Server on your machine. At this point, you will also be asked to select the security model for the server data, either Windows Authentication or SQL Server security. Unless you have a good reason for using SQL Server security, you should select Use Trusted Connection . A trusted connection connects to the database as a Windows Administrator. For this example, I am logged into my machine as the Windows Administrator. You may accept the suggestion or enter a new name for the database. Click Next to proceed.

You are now required to select the tables to be upsized to SQL Server. In this case, we will select all the tables with the exception of tblPasswords . Remember in the new ADP you will be using SQL Server security, so this table is no longer required, as it is an Access security table created in this example database. Use the arrow buttons to move the required tables from the Available Tables list to the Export to SQL Server list. Once done click Next to proceed.

In addition to the data the upsizing wizard can also export several table attributes:

  1. The last option in this screen permits you to instruct the wizard to simply export the table structure and leave the actual data behind in Access. The data would then have to be manually imported into SQL Server later. On this occasion, we want the tables and the data, so accept the default and click Next to continue.

  2. This next screen in the upsizing process also provides you with several options:

    Create a new Access client/server application

    This moves everything into the world of SQL Server. Tables will be moved to the server and a new SQL Server database will be created. All user objects, forms, reports and any VBA code will be migrated into a new ADP on the client side. You may also use the Browse button to select a location for the ADP file or accept the default. On this occasion, I have created a folder for the database and simply navigated to that location. If you have created a folder for the ADP, then navigate to it now.

    Link SQL Server tables to existing application

    In this case, you simply create a link to the SQL Server database tables and your file type remains the standard Access mdb file. All local tables will be retained with the prefix _local added to the table name and stored in the mdb file.

    No application changes

    Export the tables, but make no changes to the Access application. This option creates the table structure on SQL Server, but little else. No changes will be made to the mdb file, that is, links will not be made and no connection will be provided to SQL Server.

  3. Click Next to proceed. The final screen in the process asks if you want to Open the new ADP file or Keep the MDB file open . Select your option, and click Finish to generate the ADP. The choice of which option to use depends on what you want to do. If you want to begin working with the new ADP file right away, then select Open the new ADP file , otherwise select Keep the MDB file open .

  4. In addition to generating the ADP files Access will produce an Upsizing report. Make sure you print this file as it contains a record of all changes made during the process, including information on any objects that did not upsize. Print this out NOW . The report will be saved as an Access Snapshot file in the same folder as the ADP file. You cannot save the report using the Access Menus, so it really is a case of print it, export it, or lose it.

What's New in your Database?

From here on in, when we refer to a database we are referring to the database as a SQL Server 2000 database and an ADP file, as opposed to Microsoft Access. When you reopen the database, you will find that you have left the world of Jet behind and that there are several new things you will need to learn or relearn. The database window, while looking the same, will contain many different objects, and this is apparent when you come to create queries. Queries are now replaced by SQL Server objects, including:

The following table also highlights some areas that also tend to catch out the Access developer moving to ADPs.

Access

SQL Server

Commment

&

+

Concatenation

*

%

Wildcard

#

'

Date separator

 

Категории