Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Printing DBGRID contents

Posted on 1998-09-03
Medium Priority
Last Modified: 2010-04-30

I am working with a large DBGRID and I want to print out all the contents

I want it to span across several pages, because there are many columns.  I want to print out based on if the column is visible or not and I want it to print out the number of columns that fit on a page, so lets say 5 columns fit on a page, and there are 10 columns, on the first few pages I want the first five columns and the balance on the next pages.  And I also want to repeat the column headings.  

And how do I go about a print preview?

Thanks a lot for any help.

Mark Anders
Question by:MarkA
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

CarlosJac earned 200 total points
ID: 1432903
I use VSVIEW 3.0 from Videosoft.  This is an Activex Control to replace the printer object.
LVL 14

Expert Comment

ID: 1432904
Here are two solutions :

First : Use my Print Preview OCX (shareware). It is great. You can find it on my web site :
  Web Site : http://www.geocities.com/ResearchTriangle/6311/ 

With the PrintPreview OCX, you can replace your printer object in
all your code with this object. You will be able to :
    - You can preview your printed text on the screen
    - You can have many pages as you want
    - You can zoom/unzoom the pages (like in the Word)
    - You can preview two pages at one time
    - You can print the text
    - You can save the text in a structured file
    - You can reload saved printed text
    - You can save the text in an ASCII format
    - You can have the interface in multiple language
    - When you double clik on the page number,
      you can go directly to a specified page
    - You can search strings in all previewed pages
    - Load, preview and print bitmaps at any position
    - Make report based on data provided by you through APIs
    - You can use the Print Preview in Spanish
    - You can use the Print Preview in German
    - Toolbar with bitmap if desired
    - Possibility to use styles to format the text
    - Automatic alignment to left, center, right
    - Help file added
    - You can use Print Preview in Office (Excel, Outlook, Access...)
    - You can create a report based on a database and a query
    - New graphics possibilities : CheckBox, RadioButton
    - Word Wrap capabilities for long lines
    - Works with Chinese, Arab... character set
    - You can use the Print Preview in Dutch
    - You can use the Print Preview in Italian
    - New improved interface with some new features
    - You can set the zoom directly in your application
    - You can now setup all the user interface to interact with your user
    - You can save output to bitmap
    - You can add text with any angle you want
    - Win98 Interface with gradient title bar
    - You can configure all the user text in the Print Preview
    - Added all the API in HTML format
    - ... Many other features

LVL 14

Expert Comment

ID: 1432905
Second : Use this function wich print a traditional Grid. You could modify it. (if you modify it, please send me the code, it could be useful for me) :

Sub GridPrint(Grid As Control, szTitle As String, bLines As Integer)
   ' *** Print a grid control ***
   Dim nRow          As Long
   Dim nCol          As Long
   Dim sCurrentX     As Single
   Dim sCurrentY     As Single
   Dim sMaxLine      As Single
   Dim nPage         As Integer
   Dim szPage        As String
   Dim sOldY         As Single
   Dim sPageWidth    As Single
   Dim sBeginLeft    As Single
   Dim sBeginGrid    As Single
   If (Grid.Rows = 0) Then Exit Sub
   ' *** We look for the maximum size for the fontsize ***
   sMaxLine = 99999999

   ' *** By default, we set the fontsize of the grid ***
   Printer.FontSize = Grid.FontSize

   ' *** Here is the maximum width of the page
   sPageWidth = Printer.Width * 0.94 - 200
   ' *** We calculate the maximum possible fontsize ***
   Do While (sMaxLine > sPageWidth) And (Printer.FontSize > 0)
      sMaxLine = 0
      For nCol = 0 To Grid.Cols - 1
    sMaxLine = sMaxLine + (Printer.FontSize / Grid.FontSize) * Grid.ColWidth(nCol)

      ' *** We change the fontsiz if needed ***
      If (sMaxLine > sPageWidth) Then Printer.FontSize = Printer.FontSize - 1

   ' *** We begin on page 1 ***
   nPage = 1

   ' *** We put The title ***
   ' *** and the headers of each column ***
   For nRow = 1 To Grid.Rows - 1
      If (bLines = True) Then Printer.Line (sBeginLeft, sCurrentY)-(sMaxLine, sCurrentY)
      ' *** We print on a new page if needed ***
      If (sCurrentY >= Printer.Height * 0.93 - Printer.TextHeight("A")) Then
    If (bLines = True) Then
       ' *** Bottom line
       Printer.Line (sBeginLeft, sCurrentY - 4 * Printer.TwipsPerPixelY)-(sMaxLine, sCurrentY - 4 * Printer.TwipsPerPixelY)
       ' *** Left line ***
       Printer.Line (sBeginLeft, sBeginGrid)-(sBeginLeft, sCurrentY - 4 * Printer.TwipsPerPixelY)
       ' *** Right line ***
       Printer.Line (sMaxLine, sBeginGrid)-(sMaxLine, sCurrentY - 4 * Printer.TwipsPerPixelY)
    End If
    nPage = nPage + 1
    ' *** We put The title ***
    ' *** and the headers of each column ***
      End If

      sCurrentX = 4 * Printer.TwipsPerPixelX
      For nCol = 0 To Grid.Cols - 1
    If (nCol > 0) Then
       sCurrentX = sCurrentX + (Printer.FontSize / Grid.FontSize) * Grid.ColWidth(nCol - 1)
       If bLines = True Then Printer.Line (sCurrentX - 4 * Printer.TwipsPerPixelX, sBeginGrid)-(sCurrentX - 4 * Printer.TwipsPerPixelX, Printer.CurrentY + (Printer.TextHeight("A") / 2) - 4 * Printer.TwipsPerPixelY)
    End If
    ' *** Print cell text ***
    Grid.Col = nCol
    Grid.Row = nRow
    Printer.CurrentX = sCurrentX
    Printer.CurrentY = sCurrentY + (Printer.TextHeight("A") / 2)
    Printer.Print Grid.Text
      sCurrentY = sCurrentY + (Printer.TextHeight("A") * 2)
   If (bLines = True) Then
      ' *** Bottom line
      Printer.Line (sBeginLeft, sCurrentY - 4 * Printer.TwipsPerPixelY)-(sMaxLine, sCurrentY - 4 * Printer.TwipsPerPixelY)
      ' *** Left line ***
      Printer.Line (sBeginLeft, sBeginGrid)-(sBeginLeft, sCurrentY - 4 * Printer.TwipsPerPixelY)
      ' *** Right line ***
      Printer.Line (sMaxLine, sBeginGrid)-(sMaxLine, sCurrentY - 4 * Printer.TwipsPerPixelY)
   End If

   Exit Sub
   ' *** We print the title ***
   sCurrentY = Printer.CurrentY
   Printer.FontBold = True
   Printer.Print szTitle
   Printer.FontBold = False
   Printer.Print ""

   ' *** We print the page number on the first line ***
   sOldY = Printer.CurrentY
   szPage = "Page " & CStr(nPage)
   Printer.FontItalic = True
   Printer.CurrentX = sPageWidth - Printer.TextWidth(szPage)
   Printer.CurrentY = sCurrentY
   Printer.Print szPage
   Printer.FontItalic = False
   Printer.CurrentY = sOldY
   ' *** We print the grid ***
   Printer.CurrentY = Printer.CurrentY + (Printer.TextHeight("A"))
   sCurrentY = Printer.CurrentY
   sBeginGrid = sCurrentY
   sBeginLeft = 0
   sCurrentX = 4 * Printer.TwipsPerPixelX
   ' *** We print the header of each column ***
   If (bLines = True) Then Printer.Line (sBeginLeft, sCurrentY)-(sMaxLine, sCurrentY)
   sCurrentY = Printer.CurrentY + (Printer.TextHeight("A") / 2)
   For nCol = 0 To Grid.Cols - 1
      If (nCol > 0) Then sCurrentX = sCurrentX + (Printer.FontSize / Grid.FontSize) * Grid.ColWidth(nCol - 1)
      ' *** Print cell text ***
      Grid.Col = nCol
      Grid.Row = 0
      Printer.CurrentX = sCurrentX
      Printer.CurrentY = sCurrentY
      Printer.Print Grid.Text
   sCurrentY = sCurrentY + (Printer.TextHeight("A") * 1.5)
   If (bLines = True) Then Printer.Line (sBeginLeft, sCurrentY)-(sMaxLine, sCurrentY)

End Sub


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question