Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Printing DataGrid Results

Posted on 2004-04-19
7
Medium Priority
?
327 Views
Last Modified: 2007-12-19
I have created an SQL query using ADO that retrieves some data from a database, then I use a datagrid to output the results for the user.  I am trying to give the user the option of printing those results.  How can I do this?
0
Comment
Question by:MaRs79
  • 2
7 Comments
 

Author Comment

by:MaRs79
ID: 10861577
I am using the MSDatagrid control.  The flexgrid control does not work for me.
0
 
LVL 2

Expert Comment

by:DANNYMAC
ID: 10861600
The easyest was is to print the recordset.  
be sure to update your recordset with any changes in the data grid the client might make then simple print your recordset.
Here is a a simple routine that will print out any recordset.
Private Sub Command1_Click()

    Dim FSo As New FileSystemObject
    Dim F, J
   
    Set F = FSo.CreateTextFile(App.Path + "\test.csv", True)
    With Adodc1.Recordset
        .MoveFirst
        While Not .EOF
            For J = 0 To .Fields.Count - 1
                F.Write .Fields(J) & IIf(J = .Fields.Count, "", ",")
                Next
            F.WriteLine
            .MoveNext
            Wend
        End With
    F.Close

End Sub
This assumes that the data is in an ADODC Data control.  But simply change the With Reference to your recordset or Contol name.  Also this will put out a comma separated ftext file, again simply change the field separator to what you wish to use.

There is no easy or simple way that I know of to list row by row data in a datagrid.  It is easy to goto a row or cell if you know where it is, like the cursor is on it, but if the number of columns and rows are unknown then I do not know of a way to loop thru the datagrid.

Hope this helps.
D
0
 
LVL 18

Accepted Solution

by:
Sethi earned 500 total points
ID: 10864779
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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

916 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