How It Works

The OutputToHTML procedure uses the OutputTo method with various parameters that indicate what should be exported, in what format, and to where. In this example, the tblComplaints table is exported to an HTML format into a new file called complaints.html. The True parameter at the end of the statement that follows is for the AutoStart parameter to indicate that the Web browser should automatically launch to display the file.

Sub OutputToHTML()

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

End Sub

After you run the preceding procedure, the Web browser does indeed launch and displays the newly created HTML file in a screen similar to Figure 8.6.

Creating ASP Pages

Active Server Pages (ASP) run on a Web server and can be used to display current data whenever you access them. ASP files typically contain code written in a script language, such as VBScript, for retrieving the data. They also contain code written in an HTML syntax that gets returned to the client browser to display the content.

You can use the OutputTo method to create an ASP page in a fashion very similar to the way you create an HTML file. For example, the following command creates an ASP page based on the tblComplaints table.

DoCmd.OutputTo acOutputTable, "tblComplaints", acFormatASP, "c: \temp\complaints.asp"

The tblComplaints table exported to an ASP file looks similar to the following:

<META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=windows-1252">

<TITLE>tblComplaints</TITLE>

If IsObject(Session("_conn")) Then Set conn = Session(M_conn")

Else

Set conn = Server.CreateObject("ADODB.Connection")

Set Session("_conn") = conn

End If

If IsObject(Session("tblComplaints_rs")) Then Set rs = Session("tblComplaints_rs")

sql = "SELECT * FROM [tblComplaints]"

Set rs = Server.CreateObject("ADODB.Recordset")

If rs.eof Then rs.AddNew End If

Set Session("tblComplaints_rs") = rs

End If

<TABLE BORDER=1 BGCOLOR=#ffffff CELLSPACING=0><FONT FACE="Arial" COLOR= #000000><CAPTION><B>tblComplaints</B></CAPTION></FONT>

<TH BGCOLOR=#c0c0c0 BORDERCOLOR=#0 0 0 0 0 0 ><FONT style= FONT-SIZE:10pt FACE="Arial" COLOR=#0 0 0 0 0 0>ComplaintId</FONT></TH> <TH BGCOLOR=#c0c0c0 BORDERCOLOR=#0 0 0 0 0 0 ><FONT style= FONT-SIZE:10pt FACE="Arial" COLOR=#0 0 0 0 0 0>ComplaintDate</FONT></TH> <TH BGCOLOR=#c0c0c0 BORDERCOLOR=#0 0 0 0 0 0 ><FONT style= FONT-SIZE:10pt FACE="Arial" COLOR=#0 0 0 0 0 0>CustomerName</FONT></TH> <TH BGCOLOR=#c0c0c0 BORDERCOLOR=#0 0 0 0 0 0 ><FONT style=

FONT-SIZE:10pt FACE="Arial" COLOR=#0 0 0 0 0 0>CustomerDayPhone</FONT></TH> <TH BGCOLOR=#c0c0c0 BORDERCOLOR=#0 0 0 0 0 0 ><FONT style=

FONT-SIZE:10pt FACE="Arial" COLOR=#0 0 0 0 0 0>CustomerEveningPhone</FONT></TH> <TH BGCOLOR=#c0c0c0 BORDERCOLOR=#0 0 0 0 0 0 ><FONT style=

FONT-SIZE:10pt FACE="Arial" COLOR=#0 0 0 0 0 0>IssueDescription</FONT></TH> <TH BGCOLOR=#c0c0c0 BORDERCOLOR=#0 0 0 0 0 0 ><FONT style= FONT-SIZE:10pt FACE="Arial" COLOR=#0 0 0 0 0 0>Resolved</FONT></TH> <TH BGCOLOR=#c0c0c0 BORDERCOLOR=#0 0 0 0 0 0 ><FONT style=

FONT-SIZE:10pt FACE="Arial" COLOR=#0 0 0 0 0 0>ResolutionDescription</FONT></TH>

On Error Resume Next rs.MoveFirst do while Not rs.eof %>

<TR VALIGN=TOP>

<TD BORDERCOLOR=#c0c0c0 ALIGN=RIGHT><FONT style=FONT-SIZE:10pt FACE="Arial"

COLOR=#000000><%=Server.HTMLEncode(rs.Fields("ComplaintId").Value)%><BR>

<TD BORDERCOLOR=#c0c0c0 ALIGN=RIGHT><FONT style=FONT-SIZE:10pt FACE="Arial"

COLOR=#000000><%=Server.HTMLEncode(rs.Fields("ComplaintDateM).Value)%><BR>

<TD BORDERCOLOR=#c0c0c0 ><FONT style=FONT-SIZE:10pt FACE="Arial"

COLOR=#000000><%=Server.HTMLEncode(rs.Fields("CustomerName").Value)%><BR>

<TD BORDERCOLOR=#c0c0c0 ><FONT style=FONT-SIZE:10pt FACE="Arial"

COLOR=#00 0000><%=Server.HTMLEncode(rs.Fields("CustomerDayPhone").Value)%><BR>

<TD BORDERCOLOR=#c0c0c0 ><FONT style=FONT-SIZE:10pt FACE="Arial"

COLOR=#000000><%=Server.HTMLEncode(rs.Fields("CustomerEveningPhone").Value)%>

<TD BORDERCOLOR=#c0c0c0 ><FONT style=FONT-SIZE:10pt FACE="Arial"

COLOR=#000000><%=Server.HTMLEncode(rs.Fields("IssueDescription").Value)%><BR>

<TD BORDERCOLOR=#c0c0c0

ALIGN=RIGHT><FONT style=FONT-SIZE:10pt FACE="Arial"

COLOR=#00000 0><%=Server.

.HTMLEncode(rs.Fields("Resolved").Value)%><BR>

</FONT></TD>

<TD BORDERCOLOR=#c0c0c0

><FONT style=FONT-SIZE:10pt FACE="Arial"

COLOR=#00000 0><%=Server.

.HTMLEncode(rs.Fields("ResolutionDescription").Value)%>

<BR></FONT></TD>

</TR> <%

rs.MoveNext

loop%>

</TBODY>

<TFOOT></TFOOT>

</TABLE>

</BODY>

</HTML>

Notice in the previous ASP page that various VBScript commands create a recordset to retrieve the current values from the tblComplaints table. Also, various HTML commands display the retrieved values to the user. It's okay if you do not understand all the preceding commands. The example demonstrates that you can create ASP pages that dynamically retrieve data from your Access database. It also shows that ASP pages must run from a Web server that supports ASP pages.

ASP pages can be opened from Notepad, Microsoft FrontPage, or other programs because it is a script file that contains only text.

When you move the ASP page to a Web server and then access the ASP page from a client browser, you see results similar to what is shown in Figure 8.6. The only difference is that the page is generated on the fly with current data instead of the prior static HTML format.

0 0

Post a comment