MaRs79
asked on
Printing DataGrid Results
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?
ASKER
I am using the MSDatagrid control. The flexgrid control does not work for me.
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.Pat h + "\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
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.Pat
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.vb-helper.com/howto_print_flexgrid.html
http://www.xtremevbtalk.com/showthread.php?s=&threadid=35110