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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save as HTML

Status
Not open for further replies.

shane01

IS-IT--Management
Apr 19, 2004
13
0
0
NZ
I want to create a module which will output a table as html using the web publication profile I have created. I wish for this action to take place behind the scenes as it were. My purpose for wanting to achieve this is: I have static html pages sitting on a private server these will be linked to from the Intranet site of the company. If there are changes made to the database table I would like to replace the old html files with new ones of the same name. Can anyone help?
 
Have a look for the quiz.zip file on my website.
It's not quite what you want it to do, but it might give you an idea for the way ahead.
Let me know how you get on.

B ----------------------------------
Ben O'Hara
Home: bpo@RobotParade.co.uk
Work: bo104@westyorkshire.pnn.police.uk
Web: ----------------------------------
 
I would do it like below(it's just an example, if you want table borders, colors and so on, you'll have to modify the code to insert tags in the appropriate places in your file)...
I tested it with a table 'Downloads'. Change the name to what you have and test it.

Code:
Sub myhtml()
Dim rst As DAO.Recordset
Dim i As Long
Dim j As Long
Dim fld As Field
Set rst = CurrentDb.OpenRecordset("Downloads")
'create/overwrite the original file
Open "C:\test.html" For Output As #1
'start with the html tag
Print #1, &quot;<html>&quot;
    'body tag, you can insert whatever you want here
    Print #1, &quot;<body>&quot;
    With rst
    .MoveFirst
        'table tag
        Print #1, &quot;<table>&quot;
        
            'First row: table names
            Print #1, &quot;<TR>&quot;
                Print #1, &quot;<TD>Record number</TD>&quot; 'just to count the records
                'print field names
                For j = 0 To .Fields.Count - 1
                Print #1, &quot;<TD>&quot; & .Fields(j).Name & &quot;</TD>&quot;
                Next
            'First row finished
            Print #1, &quot;</TR>&quot;
            
            'start looping through the recordset
            Do Until .EOF
                'evaluate each row of data
                Print #1, &quot;<TR>&quot;
                
                Print #1, &quot;<TD>&quot; & i + 1 & &quot;</TD>&quot; 'insert record counter
                    'find and output field values in current record
                    For Each fld In rst.Fields 'For j = 0 To .Fields.Count - 1
                    Print #1, &quot;<TD>&quot; & fld.Value & &quot;</TD>&quot;
                    Next

                'finish row
                Print #1, &quot;</TR>&quot;
            i = i + 1 'record counter
            'move to next record
            .MoveNext
            Loop
            'close recordset
            .Close
        End With
        Print #1, &quot;</table>&quot;
        Set rst = Nothing

    'end with the body
    Print #1, &quot;</body>&quot;

'html end here
Print #1, &quot;</html>&quot;

'close new html file
Close #1
End Sub

Hope this helps,

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top