Source code for Issue Number 128

Copyright 1997-2000 by C&D Programming Corp. All Rights Reserved. Source code may not be reproduced except for use in a compiled executable. All rights reserved. If you would like to reprint any or all of this code please email us at info@codeoftheweek.com

Code of the Week Home


Source Code

Create a new class module and paste this code into it. Call the class module cADOtoHTML.

If you have any questions, email us at help@codeoftheweek.com

'----------------------------------------------------------------------
'
'   Module Name:    cADOtoHTML
'   Written By:     C&D Programming Corp.
'   Create Date:    6/2000
'   Copyright:      Copyright 2000 by C&D Programming Corp.  Source
'                   code may not be reproduced except for use in a
'                   compiled executable.  All rights reserved.  If
'                   you would like to reprint any or all of this
'                   code please email us at info@codeoftheweek.com
'
'----------------------------------------------------------------------

Option Explicit

Private mRS As ADODB.Recordset      ' holder for the recordset to display
Private msTitle As String           ' name of the HTML page to generate

Public TableBorderWidth As Integer  ' width of the table border
Public BackgroundGraphic As String  ' a background graphic if desired

Public Property Set Recordset(RS As ADODB.Recordset)
    Set mRS = RS
End Property

Public Property Let PageTitle(sTitle As String)
    msTitle = sTitle
End Property

Public Property Get PageTitle() As String
    PageTitle = msTitle
End Property

Private Property Get HTMLHeader() As String
    ' build the standard header that should be on every html page
    ' generated.
    HTMLHeader = "" & PageTitle & "" & _
                " "", " background=""" & BackgroundGraphic & """", "") & ">"
End Property

Private Property Get HTMLFooter() As String
    HTMLFooter = ""
End Property

Private Property Get TableTag() As String
    ' build the opening table tag with a few properties.  There are many more
    ' properties available that can be used to enhance this.
    TableTag = ""
End Property

Private Property Get TableHeader() As String
    Dim fld As Field
    Dim x As Long
    Dim sTableHeader As String

    ' build the header of the table by cycling through each field and
    ' specifying each field as a column.
    mRS.MoveFirst
    For x = 0 To mRS.Fields.Count - 1
        sTableHeader = sTableHeader & ""
    Next
    TableHeader = TableTag & "" & sTableHeader & ""
End Property

Private Property Get TableFooter() As String
    TableFooter = "
" & mRS.Fields(x).Name & "
" End Property Public Property Get HTML() As String Dim sRow As String Dim fld As Field Dim x As Long ' build the html table by running through each record ' to build the columns and then skipping to the next ' record and repeating the process. mRS.MoveFirst sRow = "" While Not mRS.EOF sRow = sRow & "" For x = 0 To mRS.Fields.Count - 1 sRow = sRow & "" & mRS.Fields(x).Value & "" Next sRow = sRow & "" mRS.MoveNext Wend HTML = HTMLHeader & TableHeader & sRow & TableFooter & HTMLFooter End Property Private Sub Class_Initialize() BackgroundGraphic = "" TableBorderWidth = 1 End Sub