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

x
?
Solved

Printing DataGrid Results

Posted on 2004-04-19
7
Medium Priority
?
326 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
[X]
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
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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

722 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