how to print msflexgird and the data in this flexgrid

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2008
Posts: 28
Reputation: nor_d83 is an unknown quantity at this point 
Solved Threads: 0
nor_d83 nor_d83 is offline Offline
Light Poster

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

 
0
  #11
Mar 29th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 28
Reputation: nor_d83 is an unknown quantity at this point 
Solved Threads: 0
nor_d83 nor_d83 is offline Offline
Light Poster

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

 
0
  #12
Mar 29th, 2009
Ops..forgot to mention.. Grd is the name for that MSFlexGrid..
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC