This code will export the table you list to a HTML file.
Start a new
project and add 2 text boxes and a command
button. Then cut and paste the
code below. Remember
that the HTML tags has a space between the
brackets
that must be
removed!
=========================================================
Option
Explicit
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 Text2.Text For Output As
fnum
' Write the HTML header information.
Print #fnum, "<
HTML>"
Print #fnum, "< HEAD>"
' replace "This is the title" with
the title of HTML File that will appear
' in the upper blue title
bar.
Print #fnum, "< TITLE>This is the title< /TITLE>"
Print
#fnum, "< /HEAD>"
Print #fnum, ""
Print #fnum, "< BODY
TEXT=#000000 BGCOLOR=#CCCCCC>"
'Replace "My Title" with your desirableHTML
filetitle
Print #fnum, "< H1>My Title< /H1>"
' Start the
HTML table.
Print #fnum, "< TABLE WIDTH=100% CELLPADDING=2 CELLSPACING=2
BGCOLOR=#00C0FF BORDER=1>"
' Open the database.
Set db =
OpenDatabase(Text1.Text)
' Open the recordset.
' replace "Table1" with
the name of your DataBase Table
' and "ID" with the name of the field you
want to sort
' the table by it. If you don't want to sort the table, you
can
' remove the "ORDER BY ID"
Set rs = db.OpenRecordset("SELECT * FROM
Authors")
' 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, "< /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
Private Sub Form_Load()
'put your
database file name in Text1 and the
'HTML file name you want to create in
Text2
'Replace the database and htm files name with yours
Text1.Text =
App.Path & "\Biblio.mdb"
Text2.Text = App.Path &
"\newBiblio.htm"
End Sub