Solved

Printing DataGrid Results

Posted on 2004-04-19
7
317 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
 
LVL 18

Expert Comment

by:Sethi
ID: 10861019
0
 

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 125 total points
ID: 10864779
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now