How to Export an Access Database to HTML file
Posted on January 5, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | 'Database - How to Export an Access Database to HTML file 'Add a Command Button and two Text Boxes to your form. 'Add reference to Microsoft DAO 3.6 Object Library Option Explicit Private Sub Command1_Click() Dim fnum As Integer, num_fields As Integer, I As Integer, num_processed As Integer Dim db As Database Dim rs As Recordset On Error GoTo MiscError fnum = FreeFile Open Text2.Text For Output As fnum Print #fnum, "<HTML>" Print #fnum, "<HEAD>" Print #fnum, "<TITLE>My title</TITLE>" Print #fnum, "</HEAD>" Print #fnum, "" Print #fnum, "<BODY>" Print #fnum, "<H1>My Title</H1>" Print #fnum, "<TABLE WIDTH=100% CELLPADDING=2 CELLSPACING=2 BGCOLOR=#00C0FF BORDER=1>" Set db = OpenDatabase(Text1.Text) Set rs = db.OpenRecordset("SELECT * FROM Table1 ORDER BY ID") Print #fnum, " <TR>" 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>" Do While Not rs.EOF num_processed = num_processed + 1 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 Print #fnum, "</TABLE>" Print #fnum, "<P>" Print #fnum, "<H3>" & Format$(num_processed) & " records displayed.</H3>" Print #fnum, "</BODY>" Print #fnum, "</HTML>" 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() Text1.Text = "C:\Temp\Test.mdb" Text2.Text = "C:\Temp\Test.htm" End Sub |