Community discussion forum

Printing to 1/2 size of short bond paper (continous form)

  • 2 years ago

    Hi there! I already have a code for printing and it's working fine.The code will print in one whole sheet of bond paper.

    I would like to use a continous form (8 1/2 x 5 1/2)  which is half of 8 1/2 x 11. I would like also that after printing, even if the printout is just one line of text, the printer should  eject the paper up to the perforation area only.

     

    below is my code for printing:

    Private Sub cmdPrintRpt_Click() 'Add a textbox(hidden) and set it Multiline=true (but no scrollbar) Dim i As Long Dim j As Long Dim strTmpDescArray() As String Dim pagenum As Long, pagecount As Long If lstRecords.ListItems.Count = 0 Then MsgBox "There's nothing to Print", vbInformation, ProgName Exit Sub End If CommonDialog1.CancelError = True ' Do this first On Error GoTo ErrHandler ' Only need one error handler Do If Not pagenum = 0 Then pagecount = pagenum pagenum = 1 'CommonDialog1.ShowPrinter Printer.FontName = "Arial" Printer.FontSize = 20 Printer.Orientation = vbPRORPortrait Printer.CurrentY = 720 'Top Margin of .5" Printer.CurrentX = 620 'Left Margin of .5" Printer.Print "Sales Report" Printer.FontName = "Courier New" Printer.FontSize = 11 Printer.Print Tab(60); "Date Printed: "; Date Printer.Print Tab(60); "Page " & pagenum & " of " & pagecount 'format as required ' pagenum = pagenum + 1 ' new page not till end of page Printer.Print: Printer.Print Dim Pagelength%, BottomMargin%, TopMargin%, ThreeLines% Pagelength = 11 * 1440 BottomMargin = 1 * 1440 TopMargin = 0.5 * 1440 ThreeLines = 0.5 * 1440 'Print column headers Printer.CurrentX = 220 Printer.Print LeftAlignText(lstRecords.ColumnHeaders(1).Text, MAX_WIDTH_COL1) & _ LeftAlignText(lstRecords.ColumnHeaders(2).Text, MAX_WIDTH_COL2) & _ RightAlignText(lstRecords.ColumnHeaders(3).Text, MAX_WIDTH_COL3) & _ RightAlignText(lstRecords.ColumnHeaders(4).Text, MAX_WIDTH_COL4) & _ RightAlignText(lstRecords.ColumnHeaders(5).Text, MAX_WIDTH_COL5) & _ RightAlignText(lstRecords.ColumnHeaders(6).Text, MAX_WIDTH_COL6) & _ RightAlignText(lstRecords.ColumnHeaders(7).Text, MAX_WIDTH_COL7) & " " & _ RightAlignText(lstRecords.ColumnHeaders(8).Text, MAX_WIDTH_COL8) Printer.Print String(MAX_WIDTH_COL1 + MAX_WIDTH_COL2 + MAX_WIDTH_COL3 + MAX_WIDTH_COL4 + MAX_WIDTH_COL5 + MAX_WIDTH_COL6 + MAX_WIDTH_COL7 + MAX_WIDTH_COL8 + 1, "-") ' total 1 spaces in a line 'Print Data For i = 1 To lstRecords.ListItems.Count strTmpDescArray = FormatDescription(lstRecords.ListItems(i).ListSubItems(1).Text) For j = 0 To UBound(strTmpDescArray) ' print each line of desc in separate line If j = 0 Then 'print each text If Printer.CurrentY > Pagelength - BottomMargin Then '**** Printer.NewPage Printer.CurrentY = TopMargin pagenum = pagenum + 1 '**** need to do before printing 'Repeat the Heading every page Printer.CurrentX = 620 'Left Margin of .5" Printer.FontName = "Arial" Printer.FontSize = 20 Printer.Print "Sales Report" Printer.FontName = "Courier New" Printer.FontSize = 11 Printer.Print Tab(60); "Date Printed: "; Date Printer.Print Tab(60); "Page " & pagenum & " of " & pagecount 'format as required ' or put after new page if you want at top of page Printer.Print: Printer.Print 'Print Column Headers at every page Printer.CurrentX = 220 Printer.Print LeftAlignText(lstRecords.ColumnHeaders(1).Text, MAX_WIDTH_COL1) & _ LeftAlignText(lstRecords.ColumnHeaders(2).Text, MAX_WIDTH_COL2) & _ RightAlignText(lstRecords.ColumnHeaders(3).Text, MAX_WIDTH_COL3) & _ RightAlignText(lstRecords.ColumnHeaders(4).Text, MAX_WIDTH_COL4) & _ RightAlignText(lstRecords.ColumnHeaders(5).Text, MAX_WIDTH_COL5) & _ RightAlignText(lstRecords.ColumnHeaders(6).Text, MAX_WIDTH_COL6) & _ RightAlignText(lstRecords.ColumnHeaders(7).Text, MAX_WIDTH_COL7) & " " & _ RightAlignText(lstRecords.ColumnHeaders(8).Text, MAX_WIDTH_COL8) Printer.Print String(MAX_WIDTH_COL1 + MAX_WIDTH_COL2 + MAX_WIDTH_COL3 + MAX_WIDTH_COL4 + MAX_WIDTH_COL5 + MAX_WIDTH_COL6 + MAX_WIDTH_COL7 + MAX_WIDTH_COL8 + 1, "-") ' total 1 spaces in a line End If Printer.CurrentX = 220 Printer.Print LeftAlignText(lstRecords.ListItems(i).Text, MAX_WIDTH_COL1) & _ LeftAlignText(strTmpDescArray(j), MAX_WIDTH_COL2) & _ RightAlignText(lstRecords.ListItems(i).ListSubItems(2).Text, MAX_WIDTH_COL3) & _ RightAlignText(lstRecords.ListItems(i).ListSubItems(3).Text, MAX_WIDTH_COL4) & _ RightAlignText(lstRecords.ListItems(i).ListSubItems(4).Text, MAX_WIDTH_COL5) & _ RightAlignText(lstRecords.ListItems(i).ListSubItems(5).Text, MAX_WIDTH_COL6) & _ RightAlignText(lstRecords.ListItems(i).ListSubItems(6).Text, MAX_WIDTH_COL7) & " " & _ RightAlignText(lstRecords.ListItems(i).ListSubItems(7).Text, MAX_WIDTH_COL8) Else ' print spaces and corresponding line from strArryTmp Printer.CurrentX = 220 Printer.Print LeftAlignText("", MAX_WIDTH_COL1) & _ LeftAlignText(strTmpDescArray(j), MAX_WIDTH_COL2) & _ LeftAlignText("", MAX_WIDTH_COL3) & _ RightAlignText("", MAX_WIDTH_COL4) & _ RightAlignText("", MAX_WIDTH_COL5) & _ RightAlignText("", MAX_WIDTH_COL6) & _ RightAlignText("", MAX_WIDTH_COL7) & _ RightAlignText("", MAX_WIDTH_COL8) End If Next j Next i ' here is where to check if there is enough space for the 3 lines for the total ' then to print a new header if needed If Printer.CurrentY > Pagelength - BottomMargin - ThreeLines Then '**** Printer.NewPage pagenum = pagenum + 1 Printer.CurrentY = TopMargin Printer.Print Tab(60); "Date Printed: "; Date Printer.Print Tab(60); "Page " & pagenum & " of " & pagecount 'format as required ' or put after new page if you want at top of page Printer.Print: Printer.Print End If Printer.Print Tab(62); "--------- ---------" Printer.Print Tab(50); "Total "; RightAlignText(lblTotalSales, 15); RightAlignText(lblNetSales, 10) Printer.Print Tab(62); "========= =========" 'Printer.EndDoc 'if you want page number on last page, you will need to add the code for it here, 'set the currentY to position at the bottom of page If pagecount = 0 Then Printer.KillDoc 'MsgBox "killdoc" '**** Else Printer.EndDoc 'MsgBox "print" '**** End If Loop While pagecount = 0 ' lstRecords.ListItems.Clear 'Clear first the listview if it contains transaction ' Call ClearFunction(frmSales, "TextBox") cmdClear.SetFocus ' cmdPrint.Visible = False Exit Sub ErrHandler: If Err = 32755 Then 'Cancel was selected Exit Sub ' Else ' MsgBox "Please check Printer if properly connected or turned on", _ ' vbInformation, ProgName ' Call msgError(Err) End If End Sub
    __________________



  • 2 years ago
    anyone here has a solution to my question? i need help please.
  • 2 years ago
    Anyone here who can answer my question?
  • 2 years ago

    set the printer to 1/2 size. goto to settings then select printer. In File menu select Server Properties. In Forms tab checked the Create a New Form the set the printer margin. that's what I make to print a 1/2 size of short bond paper.

  • 2 years ago
    i already tried that but its not working...

Post a reply

Enter your message below

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback