Exporting Access Data to Web Formats

As you learned in Chapter 7, you have various ways to export data from Access to other formats. The OutputTo method allows exporting to various formats: ASP, DAP, HTML, IIS, RTF, SNP, TXT, and XLS. The examples in this section will focus on Web examples, but you could also use the OutputTo method to export to text files or other supported formats. The basic syntax for the OutputTo method is shown in the following code:

DoCmd.OutputTo(ObjectType, ObjectName, OutputFormat, OutputFile, AutoStart, TemplateFile, Encoding)

Various parameters can specify how the method should execute. The following table explains the use of each parameter.

Parameter

Description

ObjectType

Type of object to be exported. See the help documentation for the complete list of objects.

ObjectName

Name of the object being exported.

OutputFormat

The format to which the object should be exported.

OutputFile

The full name, including the path, of the file to which the object should be exported.

AutoStart

Indication whether the destination program is to start immediately. False is the default.

TemplateFile

The full name, including the path, of the file to use as a template.

Encoding

Optional variant.

Now that you are familiar with the basic syntax of the OutputTo method, let's look at how to use it to export data to HTML, Active Server Pages (ASP), and data access pages (DAP) formats.

Creating Static HTML Pages

You have no doubt heard of HTML pages and are probably aware that they are typically used to display Web pages. You can use the OutputTo method to export a database table, query, results of a SQL statement, or other data to a static HTML document. A static HTML document is disconnected from the original data source and does not change as the underlying data changes—hence the name static.

To export the results of a report to an HTML document, you might use a statement similar to the following:

DoCmd.OutputTo acOutputReport, "ReportName", acFormatHTML, "c: \temp\ReportName.html"

Now, try it out so you can see how this works.

Try It Out Exporting the tblComplaints Table to HTML

This example will export the data contained in the tblComplaints table you created earlier in the chapter to an HTML file.

1. Add the following procedure to the module you created earlier.

Sub OutputToHTML()

DoCmd.OutputTo acOutputTable, "tblComplaints", "c: \temp\complaints.html", True

. acFormatHTML,

End Sub

2. Run the OutputToHTML procedure from the Immediate Window by typing OutputToHTML and then pressing Enter.

3. The exported HTML document should open automatically in a Web browser, as shown in Figure 8.6.

y tblComplaints

- Microsoft Internet Explorer provided by Woodard, Emhardt, Moriarty, LLP

000

File Edit View Favorites Tools Help

Tr

Qßack ■ Q

|~)t] ¡g] ^ y ' Seardi ^ Favorites ^ Media

0

DiiS

3

Address § C:\Temptomplalnt5.html

□ a GO

Links

»

Google-

V

(jfe Search Web -

0 gb 249 blocked Q 0 Options

$

tbLComplaiuts

A

Id

ComplaintDate

CustomerName

CustomerOay Phone

CustomerEveningPhone

|lssueDescription

Resolved

Resol utionDescr

4/23/2004

John Doe

501-723-1111

501-723-2222

Leaky faucet

No

2

4/23/2004

Jack Smith

987-654-3211

987-654-3211

Storm door that will not shut

No

J

3

4/24/2004

Betty Doe

111-222-3333

111-222-3333

Neighbor in other apartment has loud parties

No

4

4/25/2004

Amber Smith

999-888-7777

999-8884444

Stove in kitchen not working

No

<

1 E_-

INI

>

■¿j Done

v My Computer

Figure 8.6

0 0

Post a comment