943,824 Members | Top Members by Rank

Ad:
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Mar 29th, 2009
0

Re: how to print msflexgird and the data in this flexgrid

Let's try this code.. I've been using it and it works excellent!!

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub cmdPrint_Click()
  2. 'Print the grid with the top row as a title row
  3. FlexGridPrint Me.Grd, , , , , 1
  4. End Sub

And also this..

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1.  
  2. Function FlexGridPrint(Grd As MSFlexGrid, Optional lOrientation As Long = vbPRORPortrait, Optional ByVal lMaxRowsPerPage As Long = -1, Optional lTopBorder As Long = 1000, Optional lLeftBorder As Long = 1000, Optional lRowsToRepeat As Long = 0) As Boolean
  3. Dim lRowsPrinted As Long, lRowsPerPage As Long
  4. Dim lThisRow As Long, lNumRows As Long, lImageHeight As Long, lLastImageTop As Long
  5. Dim lPrinterPageHeight As Long, lPagesPrinted As Long, lHeadingHeight As Long
  6.  
  7. On Error GoTo ErrFailed
  8. Grd.TopRow = 1
  9. lNumRows = Grd.Rows - 1
  10. lPrinterPageHeight = Printer.Height
  11. lRowsPerPage = lMaxRowsPerPage
  12. lRowsPrinted = lRowsToRepeat
  13.  
  14. If lRowsToRepeat Then
  15. 'Calculate the height of the heading row
  16. For lThisRow = 1 To lRowsToRepeat
  17. lHeadingHeight = lHeadingHeight + Grd.RowHeight(lThisRow)
  18. Next
  19. End If
  20.  
  21. Do
  22. 'Calculate the number of rows for this page
  23. lImageHeight = 0
  24. lRowsPerPage = 0
  25. 'Setup printer
  26. Printer.Orientation = lOrientation
  27.  
  28. For lThisRow = lRowsPrinted To lNumRows
  29. lImageHeight = lImageHeight + Grd.RowHeight(lThisRow)
  30. If lRowsPerPage > lMaxRowsPerPage And lMaxRowsPerPage <> -1 Then
  31. 'Image has required number of rows, subtract height of current row
  32. lImageHeight = lImageHeight - Grd.RowHeight(lThisRow)
  33. Exit For
  34. ElseIf lImageHeight + lTopBorder * 2 + lHeadingHeight > lPrinterPageHeight Then 'Allow the same border at the bottom and top
  35. 'Image is larger than page, subtract height of current row
  36. lImageHeight = lImageHeight - Grd.RowHeight(lThisRow)
  37. Exit For
  38. End If
  39. lRowsPerPage = lRowsPerPage + 1
  40. Next
  41.  
  42. 'Print this page
  43. lPagesPrinted = lPagesPrinted + 1
  44. If lRowsToRepeat Then
  45. 'Print heading rows
  46. Printer.PaintPicture Grd.Picture, lLeftBorder, lTopBorder, , lHeadingHeight, , 0, , lHeadingHeight
  47. 'Print data rows
  48. Printer.PaintPicture Grd.Picture, lLeftBorder, lTopBorder + lHeadingHeight, , lImageHeight + lHeadingHeight, , lLastImageTop + lHeadingHeight, , lImageHeight + lHeadingHeight
  49. Else
  50. 'Print data rows
  51. Printer.PaintPicture Grd.Picture, lLeftBorder, lTopBorder, , lImageHeight, , lLastImageTop, , lImageHeight
  52. End If
  53.  
  54. Printer.EndDoc
  55.  
  56. 'Store printer position
  57. lRowsPrinted = lRowsPrinted + lRowsPerPage
  58. lLastImageTop = lLastImageTop + lImageHeight + lHeadingHeight
  59.  
  60. Loop While lRowsPrinted < lNumRows
  61.  
  62. FlexGridPrint = True
  63.  
  64. Exit Function
  65.  
  66. ErrFailed:
  67. 'Failed to print grid
  68. FlexGridPrint = False
  69. Debug.Print "Error in FlexGridPrint: " & Err.Description
  70.  
  71. End Function
Reputation Points: 10
Solved Threads: 0
Light Poster
nor_d83 is offline Offline
28 posts
since Aug 2008
Mar 29th, 2009
0

Re: how to print msflexgird and the data in this flexgrid

Ops..forgot to mention.. Grd is the name for that MSFlexGrid..
Reputation Points: 10
Solved Threads: 0
Light Poster
nor_d83 is offline Offline
28 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Point Of Sales Peripherals Connection..... can u help me plzzZz......
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: how to use the keypress function is visual basic 6





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC