VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Print Data Without Using Crystal Reports - It's Important For Direct Printing

by Gehan Fernando (47 Submissions)
Category: Miscellaneous
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Fri 18th August 2006
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Print Data Without Using Crystal Reports - It's Important For Direct Printing

API Declarations



Rem Add MSFlexGrid Control To Your Form
Rem Then Add 5 Coloums

Rem Go through my codes and get the idea
Rem after that write it your own way.

Rate Print Data Without Using Crystal Reports - It's Important For Direct Printing




On Error GoTo Error_H
    Printer.PaperSize = vbPRPSA4
    Printer.PrintQuality = vbPRPQDraft  ' vbPRPQHigh / vbPRPQLow / vbPRPQMedium
    Printer.Orientation = vbPRORPortrait
    Printer.ScaleMode = vbInches
    Printer.Font.Name = "Tahoma"
    Exit Sub
    
Error_H:
    MsgBox Err.Description, vbCritical + vbOKOnly, "Error In Printing"
    
End Sub

Private Sub PrintHeaders()

On Error GoTo Error_H
    Printer.CurrentX = 0.5
    Printer.CurrentY = 0.25
    Printer.Font.Bold = True
    Printer.Font.Size = 15
            
        Printer.Print "THIS IS PRINTER HEADER"
        
    Printer.Font.Bold = False
    Printer.Font.Size = 7
        
        Printer.CurrentX = 0.5
        Printer.CurrentY = Format(Printer.CurrentY, "0.00") + 0.02
            
            Printer.Print "THIS IS PRINTER SUB HEADER - 01"
            
        Printer.CurrentX = 0.5
        Printer.CurrentY = Format(Printer.CurrentY, "0.00") + 0.02
                
            Printer.Print "THIS IS PRINTER SUB HEADER - 02"
            
        Printer.CurrentX = 0.5
        Printer.CurrentY = Format(Printer.CurrentY, "0.00") + 0.02
                
            Printer.Print String((Printer.Width - 10), "-")
    Exit Sub
    
Error_H:
    MsgBox Err.Description, vbCritical + vbOKOnly, "Error In Printing"
    
End Sub

Private Sub PrintColoumnHeaders()

On Error GoTo Error_H
    Dim DblY            As Double
    Printer.CurrentY = Format(Printer.CurrentY, "0.00") + 0.05
    DblY = Format(Printer.CurrentY, "0.00")
    
    Printer.Font.Size = 12
    
    Printer.CurrentX = 0.5
    Printer.CurrentY = DblY
        Printer.Print "Item Code."
    
    Printer.CurrentX = 1.75
    Printer.CurrentY = DblY
        Printer.Print "Description."
    
    Printer.CurrentX = 5
    Printer.CurrentY = DblY
        Printer.Print "Sales Price."
    
    Printer.CurrentX = 6.25
    Printer.CurrentY = DblY
        Printer.Print "Quantity."
    
    Printer.CurrentY = DblY
    Printer.Font.Size = 9
    
    Printer.CurrentX = Format(Printer.CurrentY, "0.00") + 0.05
    Printer.CurrentY = Format(Printer.CurrentY, "0.00") + 0.02
    Exit Sub
    
Error_H:
    MsgBox Err.Description, vbCritical + vbOKOnly, "Error In Printing"
    
End Sub

Private Sub PrintData()

On Error GoTo Error_H
    Screen.MousePointer = vbHourglass
    Call SetPrinterSettings
    Call PrintHeaders
    Call PrintColoumnHeaders
    
    Printer.CurrentY = Format(Printer.CurrentY, "0.00") + 0.2
    For GridLoop = 1 To FlexStock.Rows - 1
        DoEvents
        If (GridLoop Mod 60) = 0 Then
            DoEvents
            Printer.NewPage
            Call PrintHeaders
            Call PrintColoumnHeaders
            Printer.CurrentY = Format(Printer.CurrentY, "0.00") + 0.2
        End If
        
        With FlexStock
            .Row = GridLoop
            .col = 1
            If .CellForeColor <> vbRed And .Text <> "" Then
                DoEvents
                Dim DblY        As Double
                Printer.CurrentY = Format(Printer.CurrentY, "0.00") + 0.02
                DblY = Printer.CurrentY
                
                Printer.CurrentX = 0.5
                Printer.CurrentY = DblY
                    Printer.Print FlexStock.TextMatrix(GridLoop, 1)
                
                Printer.CurrentX = 1.75
                Printer.CurrentY = DblY
                    Printer.Print FlexStock.TextMatrix(GridLoop, 2)
                
                Printer.CurrentX = 5.1
                Printer.CurrentY = DblY
                    Printer.Print Format(FlexStock.TextMatrix(GridLoop, 3), "#,##0.00")
                
                Printer.CurrentX = 6.41
                Printer.CurrentY = DblY
                    Printer.Print Format(FlexStock.TextMatrix(GridLoop, 4), "#,##0.00")
                Label4.Caption = "Printing On Progress  :- " & FlexStock.TextMatrix(GridLoop, 2)
            End If
        End With
        
        With FlexStock
            If GridLoop > 3 Then
                .Row = GridLoop
                .col = 1
                If .CellForeColor = vbRed Then Printer.Print ""
            End If
        End With
        Sleep 100
    Next GridLoop
    
    Printer.EndDoc
    Printer.KillDoc
    Screen.MousePointer = vbDefault
    MsgBox "Print Completed.", vbInformation + vbOKOnly, "Printing"
    Exit Sub
    
Error_H:
    MsgBox Err.Description, vbCritical + vbOKOnly, "Error In Printing"
    
End Sub

Download this snippet    Add to My Saved Code

Print Data Without Using Crystal Reports - It's Important For Direct Printing Comments

No comments have been posted about Print Data Without Using Crystal Reports - It's Important For Direct Printing. Why not be the first to post a comment about Print Data Without Using Crystal Reports - It's Important For Direct Printing.

Post your comment

Subject:
Message:
0/1000 characters