Programming Skills to the

Gone are the times when working with Access required the presence of the Microsoft Access application on a user's desktop. Thanks to the development of Internet technologies, you can now publish both static and dynamic Access data to the web.

In this part of the book you learn how Active Server Pages (ASP) and Extensible Markup Language (XML) are used with Microsoft Access to develop database solutions for the World Wide Web.

Chapter 28 Access and Active Server Pages Chapter 29 XML Features in Access 2003

Access and Active Server Pages

In today's world, everyone wants to be able to access data via the company intranet or the World Wide Web. This book would not be complete without showing you how to take your skills where the demand is. So, how can you make the information stored in your Access database available for others to view or query in a web browser? By adding some HyperText Markup Language (HTML) and Microsoft Visual Basic Scripting Edition (VBScript) to your current VBA skill set, you can start making your applications web-ready. Microsoft Access 2003 continues to offer the File menu's Export command, which you can use to save tables, queries, and forms to the web in one of the following formats: HTML documents (*.html; *htm), Microsoft Active Server Pages (*.asp), Microsoft IIS 1-2 (*.htx; *.idc), and XML (*.xml).

The following hands-on exercise demonstrates how to use the Export command to save a table in the Microsoft Active Server Pages format and later view the file in a web browser.

© Hands-On 28-1: Generating an Active Server Page from an Access Table

1. Create a new folder named Learn_ASP for this chapter's files.

2. Open the Acc2003_Chap28.mdb file from the downloadable files, or create a new Microsoft Access database named Acc2003_Chap28.mdb. If you are creating this file from scratch, use the File | Get External Data | Import command and import all the tables from the Northwind sample database.

3. Select the Employees table in the Database window and choose File | Export.

4. In the Export Table 'Employees' As window (Figure 28-1), use the Save in drop-down list to switch to the Learn_ASP folder that you created in step

1 above. Choose Microsoft Active Server Pages (*.asp) from the Save as type drop-down list, and click Export.

Part V

Export Table "Employees' As

m

Save [n :

L_3 Leam_ASP v @ • ^ > - Tools -

My Recent

Documents ©

Desktop

My Documents

My Computer

My Networfc Races

Filename: | Employees v| [ Export

Save as type: jMcrosoft Active Server Pages (*. asp) v | Cancel

Figure 28-1: This window appears when you choose the Export command on the File menu. To create a dynamic HTML page, type the filename and select Microsoft Active Server Pages from the Save as type drop-down list.

Figure 28-1: This window appears when you choose the Export command on the File menu. To create a dynamic HTML page, type the filename and select Microsoft Active Server Pages from the Save as type drop-down list.

After clicking the Export button, the Microsoft Active Server Pages Output Options window appears (Figure 28-2).

5. Enter the following information in the Microsoft Active Server Pages Output Options window:

Data Source Name: Northwind User to Connect As: Admin Server URL: http://localhost

Figure 28-2: The Microsoft Active Server Pages Output Options window allows you to specify the details of your ASP pages.

Microsoft Active Server Pagffs Output Options

mm

HTML Template:

[ Browe,,, J

Data Source Information

Data Source Name: iftothwind

[

User to Connect As: ¡Admin

[

Password for User:

Microsoft Active Server Pages Output

Server URL: jhttp://localhost|

Session timeout (iriih):

| OK || Cancel |

The Microsoft Active Server Pages Output Options window (Figure 28-2) consists of the following three sections:

The top section allows you to specify the formatting of your data. This is done via the HTML Template text box. You can find some sample templates in the \Program Files\Microsoft Office\Templates\1033 folder. Notice that we did not use a template in this hands-on exercise.

Taking Your VBA Programming Skills to the Web

The middle section is Data Source Information. You must specify the data source name in the text box. The data source name defines the connection that will be used by the server to connect to the Access database to retrieve data. You can use any name you wish. Do not forget what you've called your data source, as the name you entered here will be needed later for setting up the connection. For this hands-on, we've named our data source "Northwind." If the database you'll be connecting to is secured, you will need to specify a username and password to access the database. For this hands-on, we kept the default setting, Admin, and left the password box blank.

The bottom section is Microsoft Active Server Pages Output. Here you specify the URL and timeout values for the ASP. Server URL is the network name of the web server. We entered the value "http://localhost" to indicate that the web server is on our computer. The Session timeout value allows you to specify how long a connection will be left open for an idle user. Here we left the text box blank to accept the default value of 5 minutes. However, in a real-life situation, if you find that users are complaining about their sessions timing out, you may want to increase this timeout value.

6. After entering the data in step 5 above, click OK. Clicking OK in the window creates the Active Server Pages file named Employees.asp in the Learn_ASP folder. This ASP file is dynamically linked to the Employees table. Because you selected the ASP format, this page will immediately reflect any changes in the underlying data. We will look at the contents of the Employees.asp file in Hands-On 28-2. If you try to access this page now, you'll get an ODBC error because you have not defined the data source.

Before you can actually display this ASP page in your browser, there are extra steps involved that you will perform later in this chapter after you've learned more about Active Server Pages and have taken a look at the contents of the ASP page in Hands-On 28-2:

Set up and configure your web server so that the Server URL you indicated in the dialog box above can be accessed (see Hands-On 28-3 and 28-4). Create an ODBC Data Source with the exact name as indicated in the Data Source Name box in the Microsoft Active Server Pages Output Options window (see Hands-On 28-5).

Using the Access built-in Export command to create dynamic web content (as demonstrated in Hands-On 28-1) can get you up and running quickly. However, this chapter's focus is on showing you how you can create your own ASP files from scratch so that you will feel comfortable when displaying, querying, inserting, updating, and deleting data stored in a Microsoft Access database from any web browser.

Part V

0 0

Post a comment