Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I'd like to see some HTML code for report template 1

Status
Not open for further replies.

Saintor

Technical User
Sep 19, 2000
21
CA
I have two fields id and desc

How should the fields be referenced in the htm code? I have tried many format included <%variable%> ... doesn't work.

<html>
<table>
<tr>Id</th> <th>Desc</th>
<tr valign=&quot;top&quot;>
<td><%id%></td>
<td><%desc%></td>
</tr>

</table>
</html>

 
You do not reference the fields of a database table in HTML. You must provide the actual field values that are to be displayed (client side) by the browser. To do this, you must open the table (server side) and read through it, generating table cells for each value you want to display.

Here's an example of how to generate HTML code that displays a table. This example uses VBScript (server side) instead of JavaScript. It connects to an MSDE (SQL Server) engine running on the local PC.
Code:
<%@ Language=VBScript %>
<HTML>
<HEAD>
<TITLE>Sample Table Display</TITLE>
</HEAD>
<BODY>
<DIV ALIGN=CENTER>
<H1>Sample Table Display</H1>
<%
  '
  'Connect to database
  '
  Dim cnn
  Dim rs
  
  Set cnn = Server.CreateObject(&quot;ADODB.Connection&quot;)
  cnn.Open &quot;Provider=SQLOLEDB.1;&quot; _
         & &quot;Data Source=(local);&quot; _
         & &quot;Initial Catalog=MySampleDatabase;&quot; _
         & &quot;User ID=sa;&quot; _
         & &quot;Password=&quot;
  '
  'Retrieve data
  '
  Set rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
  rs.Open &quot;SELECT FirstName, LastName, BirthDate &quot; _
        & &quot;FROM MySampleTable &quot; _
        & &quot;ORDER BY LastName, FirstName&quot;, cnn
%>
<TABLE BORDER='1'>
  <THEAD>
    <TH>First Name</TH>
    <TH>Last Name</TH>
    <TH>Birth Date</TH>
  </THEAD>
  <TBODY>
<%
  Do Until rs.EOF
    Response.Write &quot;<TR>&quot;
    Response.Write &quot;<TD>&quot; & rs(&quot;FirstName&quot;) & &quot;</TD>&quot;
    Response.Write &quot;<TD>&quot; & rs(&quot;LastName&quot;) & </TD>&quot;
    Response.Write &quot;<TD>&quot; & Format$(rs(&quot;BirthDate&quot;), &quot;mm/dd/yyyy&quot;) & &quot;</TD>&quot;
    Response.Write &quot;</TR>&quot;
    rs.MoveNext
  Loop
%>
  </TBODY>
</TABLE>
<!-- Footer -->
<H5>Current as of <%Response.Write Now%></H5>
</DIV>
</BODY>
</HTML>
 
<html>
<table>
<tr>Id</th> <th>Desc</th>
<tr valign=&quot;top&quot;>
<td><%=id%></td>
<td><%=desc%></td>
</tr>

</table>
</html>
-----------------------------------------------------------------
[pc] Be nice. It's only doing what you tell it to do.
mikewolf@tst-us.com
 
Please clarify. Are these fields (&quot;id&quot; and &quot;desc&quot;) defined in a database table, or are they defined in an HTML document structure of some sort (e.g., <form>)? This makes a big difference in how you reference them.
 
I mean HTML to be used with Docmd.openreport
 
The DoCmd.OpenReport statement is not designed for use with HTML pages. It is designed for the reports that are stored within the Access database container. To work with HTML in Access you can use DataAccessPages. For that, you'll need at least Access 2000 to design the pages. Then you may use the DoCmd.OpenDataAccessPage statement to view the pages. This is a complex subject, and I would recommend that you review the Microsoft Access online help or pick up a good reference book on this topic.
 
You are correct; make that sendobject instead of openreport, where you can specify an HTML template. TIA
 
OK. Please refer to the Access online help for how to code an HTML Template for either DoCmd.OutputTo or DoCmd.SendObject. Microsoft provides an example HTML Template file to get you going. Basically, Access generates the whole <BODY> section of the HTML document at run time. You do not have control over what goes in the section, except in the sense of choosing the fields to output in a query or report. A report is the best way to format data using this method to generate HTML. The whole report is placed into the <BODY> section of the document, and separate HTML pages are generated for each page of the report. Navigation links are coded into each page to help the browser.
 
This is good for datasheet, but I was hoping for something for one record in a column-type layout like a form. Not possible?

The other application was to see how a html template for genericdb in edit or view mode would look like. Different beast I assume.
 
No, Access does not actually merge data records with the HTML template on a record-by-record basis. Access builds the full report or dataset that you open, then merges the whole output product into the <BODY> section of the HTML template document.
 
I don't know how complicated your application requirements are. If you need just a basic table display with no fancy formatting, try using the DoCmd.TransferText statement with the acExportHTML option.

If you need record-by-record merging capability with fancy formatting, you might look into DHTML (Dynamic HTML) using the Tabular Data Control (TDC). You would have to hand code a DHTML page--Access won't build it for you. The DHTML page acts as a template for record-by-record merges into a table structure. The data source for the merge can be a comma delimited file. So, your application could export a table or query into a comma delimited file (DoCmd.TransferText) that is hosted along with the DHTML page. When a browser requests the page the Web server downloads the data to the client where the browser performs the merge to produce the displayable result. You can search Microsoft's Web site for &quot;Data Binding&quot; to learn more about this technique.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top