VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This code will generate a report based on a listbox without the use of MS Access reports or a repor

by Chris (9 Submissions)
Category: Files/File Controls/Input/Output
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 20th August 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This code will generate a report based on a listbox without the use of MS Access reports or a report program like Crystal Reports. It creates

API Declarations





Rate This code will generate a report based on a listbox without the use of MS Access reports or a repor



Private Sub cmdPrintList_Click()
    Dim strDir As String
    Dim strOut As String
    Dim intLength As Integer
    Dim strNewOut As String
    Dim iAcnt As Long
    
    'write as html to page

    intCount = 0
    strNewOut = ""
    strDir = "C:\search.html"
    'delete file if exists on system
    FileExists = Not (Dir(strDir) = "")
    If FileExists = True Then
        Kill "c:\search.html"
    End If
    Open strDir For Append As #1
    strOut = "<html><head></head><body>"
    Print #1, strOut
    Do Until intCount > g_listboxcount
        For iAcnt = 1 To Len(Me.List1.List(intCount))
            ' translate spaces to the HTML code of &nbsp; to maintain layout
            If Mid(Me.List1.List(intCount), iAcnt, 1) = " " Then
                strNewOut = strNewOut & "&nbsp;"
            Else
                strNewOut = strNewOut & Mid(Me.List1.List(intCount), iAcnt, 1)
            End If
        Next iAcnt
        'listbox has sublist within like:
        'Car Make
        '   Car Model
        '   Car Model
        'Car Make
        '   Car Model
        '   Car Model
        'below if statement keeps sublist
        If Mid(strNewOut, 1, 1) = "&" Then
            strNewOut = "<font face='courier new' size=-1>" & strNewOut & "</font><br>"
        ElseIf Mid(strNewOut, 1, 1) = "_" Then
            strNewOut = "<hr color=green>"
        Else
            strNewOut = "<h4>" & strNewOut & "</h4>"
        End If
        Print #1, strNewOut
        strNewOut = ""
        intCount = intCount + 1
    Loop
    strOut = "</body></html>"
    Print #1, strOut
    Close #1
    g_print = strDir
    'display frmPrintPreview as a Pseudo print preview screen.
    'place webbrowser control (shdocvw) on frmPrintPreview 
    frmPrintPreview.Show

End Sub


'frmPrintPreview 
'Form load contains:
 WebBrowser1.Navigate (g_print)


'Print Button contains:
'This with either print directly or give printer properties window.
WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER
'WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER




Download this snippet    Add to My Saved Code

This code will generate a report based on a listbox without the use of MS Access reports or a repor Comments

No comments have been posted about This code will generate a report based on a listbox without the use of MS Access reports or a repor. Why not be the first to post a comment about This code will generate a report based on a listbox without the use of MS Access reports or a repor.

Post your comment

Subject:
Message:
0/1000 characters