Link to home
Start Free TrialLog in
Avatar of mjustman
mjustman

asked on

SubReport-TOC/Html-linked TOC

Two questions with a common thread:
I have a simple report (done) that needs a simple Table of Contents (done, and in place as a subreport, but I've disassociated it for now, partly because I couldn't force a page break at its end...make that an added value item!).  The  TOC needs to pick up the page numbers from the generated report pages (per item of course).  I'm guessing the secret is in some code in the Print event of the report? ...  but do I need to bury any hooks in the underlying tables?

Then: I got "creative" and tried out the export-to-html function. Overall, not bad. BUT I need to build (this time, two levels of) TOC pages hyperlinked to the detail below.  Can I make Access do the work?  It's generating the pages and knows their titles, tho I could probably guess most of string (up to the sequence number).  What function could I put where to make this happen?

many thanks as usual!

Marilyn Justman

Ask for more points if it's trickier than I think!
ASKER CERTIFIED SOLUTION
Avatar of paasky
paasky
Flag of Finland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you don't want to add PageNum field to your source tables, you can easily do a (temporary) worktable which should contain grouping and page number fields and instead of updating it, you need to fill it on the first run and then join its fields to report tables with a query.
Forgot to mention that I there's always page break before "Article section" - it will force next article always start from new page.
After thinking more of this (I've been suffering flu few days now so my mind doesn't work as well as it could) I might have an idea how to create html TOC that has hyperlink links to articles:

You need a code that creates only TOC html page. It could work like this (here's pseudo-code):

1. Open file for output
2. Open Recordset "Articles"
3. Print the html page header tags to file
4. Loop all articles and write the following information to file: <A href="Article_Page" & Cstr(rs![pagenum] &) ".html>" & rs![Topic] & "</A><P>"
5. Write html footer tags
6. Close file and recordset

If you need any assistance with these, please let me know.

Regards,
Paasky
Avatar of mjustman
mjustman

ASKER

Adjusted points from 100 to 150
Paasky:

Many thanks!

I'm accepting your first "Comment" as answer, but anyone who reads this should read the following comments as well.

I haven't tried it yet--that is a volunteer project and I've got a "real" one cooking today.  Will try to comment after I've tried it.

Sure: I'd LOVE to see your model. If it'll zip down to 2 meg or less, please just email pkg to
mjustman@enteract.com
Otherwise, send correspondence there and we'll figure out a better way.

Marilyn Justman
Enchantment...

Here's the code of form which saves report as HTML and creates TOC in HTML format:

' define here the html file path and name
' when using output-method, the name is usually
' <reportname>Page<pagenumber>.html
' the code will add <pagenumber>.html
Const PAGENAME = "Article"

Private Sub B_BuildHTML_Click()
Dim Outputfile As String
Dim rst As Recordset
Dim html As Recordset
Dim f As Integer

    On Error GoTo Build_Error

    Outputfile = InputBox("Enter HTML TOC file name:", "TOC file", "c:\TOC.html")
    If Outputfile = "" Then Exit Sub
   
    Set rst = CurrentDb.OpenRecordset("Articles")
   
    ' no articles?
    If (rst.BOF And rst.EOF) Then
        Set rst = Nothing
        Exit Sub
    End If
   
    f = FreeFile()
    Open Outputfile For Output As f
   
    ' write html header to file
    Set html = CurrentDb.OpenRecordset("select [data] from [HTML] where [SectionCode]=1 order by [RowID]")
    html.MoveFirst
    While Not html.EOF
        Print #f, html![Data]
        html.MoveNext
    Wend
   
    ' write toc and link to file
    With rst
        .MoveFirst
        While Not .EOF
            Print #f, "<A HREF=" & Chr(34) & PAGENAME & ![PageNum] & ".html" & Chr(34) & ">";
            Print #f, ![Topic];
            Print #f, "</A><P>"
            .MoveNext
        Wend
    End With
   
    Set rst = Nothing
   
    ' write html footer to file
    Set html = CurrentDb.OpenRecordset("select [data] from [HTML] where [SectionCode]=2 order by [RowID]")
    html.MoveFirst
    While Not html.EOF
        Print #f, html![Data]
        html.MoveNext
    Wend
   
    Set html = Nothing
    Close f
   
    MsgBox "TOC succesfully written to file " & Outputfile

Build_Exit:
    Exit Sub
   
Build_Error:
    MsgBox Err.Description
    Resume Build_Exit
   
End Sub

Private Sub B_SaveAsHtml_Click()
    DoCmd.OutputTo acOutputReport, "Article", acFormatHTML
End Sub

Table HTML contains the following data:

RowID      Data      SectionCode
1      <HTML>      1
2      <HEAD>      1
3      <TITLE>Table Of Contents</TITLE>      1
4      </HEAD>      1
5      <BODY>      1
6      <H2>Table Of Contents</H2>      1
100      </BODY>      2
101      </HTML>      2

SectionCode defines which part of HTML document the data is, 1 = header, 2 = footer.

And this is an example of TOC.html created with code:

<HTML>
<HEAD>
<TITLE>Table Of Contents</TITLE>
</HEAD>
<BODY>
<H2>Table Of Contents</H2>
<A HREF="ArticlePage3.html">A Technical Introduction to XML (By Norman Walsh)</A><P>
<A HREF="ArticlePage13.html">Beyond HTML: XML and Automated Web Processing</A><P>
<A HREF="ArticlePage19.html">Exploring XML-RPC (Byte Magazine)</A><P>
<A HREF="ArticlePage20.html">Going from HTML to XML</A><P>
<A HREF="ArticlePage24.html">Introduction to XML (By Lars Marius Garshol)</A><P>
</BODY>
</HTML>