Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Printing a dbgrid

Posted on 1999-07-12
Medium Priority
Last Modified: 2008-03-03
I would like to know the easiest way to print the contents of a dbgrid.
Question by:markg1
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
1 Comment
LVL 13

Accepted Solution

Mirkwood earned 100 total points
ID: 1523934


Set your Crystal Report Control Datasource property to your data control. Then add the following code to your print button.

    CR.ReportSource = crptDataControl
    CR.Action = 1

If you are using a bound DBGrid this will print what is in the grid


Public Sub GridExport(GridToExport _
   As Object, FileName As String, Optional _
   Delimiter As Variant, Optional _
   EncloseStrings As Variant)
   Dim iNumRows As Integer
   Dim iNumCols As Integer
   Dim iFileNumber As Integer
   If IsMissing(Delimiter) Then
      Delimiter = vbTab
   End If
   If IsMissing(EncloseStrings) Then
      EncloseStirngs = "" 
   End If
   iFileNumber = FreeFile
   Open FileName For Output As #iFileNumber
   For iNumRows = 0 To _
      GridToExport.rows - 1
      GridToExport.Row = iNumRows
      For iNumCols = 0 To _
         GridToExport.Cols - 1
         GridToExport.col = iNumCols
         'if it isn't the first column,
         'put a delimiter before the value
         If iNumCols > 0 Then
            Print #iFileNumber, Delimiter;
         End If
         Print #iFileNumber, EncloseStrings & _
            GridToExport.Text & EncloseStrings;
      Next iNumCols
      Print #iFileNumber, "" 
   Next iNumRows
   Close #iFileNmuber
End Sub

Private Sub cmdExport_Click()
   Call GridExport(MSFlexGrid1, "c:/test.csv", ",", Chr$(34))
End Sub

Private Sub Form_Load()
   MSFlexGrid1.AddItem "Sam Huggill"
   MSFlexGrid1.AddItem "VB Square"
End Sub


Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

670 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