Solved

Printing DataGrid Results

Posted on 2004-04-19
7
316 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
Comment Utility
0
 

Author Comment

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

Expert Comment

by:DANNYMAC
Comment Utility
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
Comment Utility
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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 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…
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…

743 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