' Create the HTML table representation.
Private Sub Command1_Click()
Dim fnum As Integer
Dim db As Database
Dim rs As Recordset
Dim num_fields As Integer
Dim i As Integer
Dim num_processed As Integer
On Error GoTo MiscError
' Open the output file.
fnum = FreeFile
Open txtHTMLFile.Text For Output As fnum
' Write the HTML header information.
Print #fnum, "<HTML>"
Print #fnum, "<HEAD>"
Print #fnum, "<TITLE>This is the title</TITLE>"
Print #fnum, "</HEAD>"
Print #fnum, ""
Print #fnum, "<BODY TEXT=#000000 BGCOLOR=#CCCCCC>"
Print #fnum, "<H1>Book Data</H1>"
' Start the HTML table.
Print #fnum, "<TABLE WIDTH=100% CELLPADDING=2 " & _
"CELLSPACING=2 BGCOLOR=#00C0FF BORDER=1>"
' Open the database.
Set db = OpenDatabase(txtDatabase.Text)
' Open the recordset.
Set rs = db.OpenRecordset( _
"SELECT * FROM Books ORDER BY Title")
' Use the field names as table column headers.
Print #fnum, " <TR>" ' Start a row.
num_fields = rs.Fields.Count
For i = 0 To num_fields - 1
Print #fnum, " <TH>";
Print #fnum, rs.Fields(i).Name;
Print #fnum, "</TH>"
Next i
Print #fnum, " </TR>"
' Process the records.
Do While Not rs.EOF
num_processed = num_processed + 1
' Start a new row for this record.
Print #fnum, " <TR>";
For i = 0 To num_fields - 1
Print #fnum, " <TD>";
Print #fnum, rs.Fields(i).Value;
Print #fnum, "</TD>"
Next i
Print #fnum, "</TR>";
rs.MoveNext
Loop
' Finish the table.
Print #fnum, "</TABLE>"
Print #fnum, "<P>"
Print #fnum, "<H3>" & _
Format$(num_processed) & _
" records displayed.</H3>"
Print #fnum, "<HR COLOR=C000C0>"
Print #fnum, "Thanks to <A " & _
"HREF=http://www.vb-helper.com>VB Helper</A>."
Print #fnum, "</BODY>"
Print #fnum, "</HTML>"
' Close the file and database.
rs.Close
db.Close
Close fnum
MsgBox "Processed " & _
Format$(num_processed) & " records."
Exit Sub
MiscError:
MsgBox "Error " & Err.Number & _
vbCrLf & Err.Description
End Sub
|