this was written by : danvlas
in thread : 181-327708
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.
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, "<html>"
'body tag, you can insert whatever you want here
Print #1, "<body>"
With rst
.MoveFirst
'table tag
Print #1, "<table>"
'First row: table names
Print #1, "<TR>"
Print #1, "<TD>Record number</TD>" 'just to count the records
'print field names
For j = 0 To .Fields.Count - 1
Print #1, "<TD>" & .Fields(j).Name & "</TD>"
Next
'First row finished
Print #1, "</TR>"
'start looping through the recordset
Do Until .EOF
'evaluate each row of data
Print #1, "<TR>"
Print #1, "<TD>" & i + 1 & "</TD>" '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, "<TD>" & fld.Value & "</TD>"
Next
'finish row
Print #1, "</TR>"
i = i + 1 'record counter
'move to next record
.MoveNext
Loop
'close recordset
.Close
End With
Print #1, "</table>"
Set rst = Nothing
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.