Hi guys
How do I print the contents of a datagrid? Failing that, output the results to Excel?
Cheers
Printable View
Hi guys
How do I print the contents of a datagrid? Failing that, output the results to Excel?
Cheers
VB Code:
Picture1.Picture = Grid.Picture
that line loads the grid in a picturebox so you can just print from there.
Sorry, you've lost me (not difficult)
opps, sorry I was thinking of MSFlexGrid.
Thanks anyway. Anyone any other ideas?
I've decided it would be better to squirt it out to excel anyway, that way the people who want the data can format it and muck around with it how they see fit.
I've got this so far:
VB Code:
Private Sub Command3_Click() Dim oExcel As Excel.Application Dim oWB As Excel.Workbook Dim oWS As Excel.Worksheet Set oExcel = New Excel.Application oExcel.Visible = True Dim oRng1 As Excel.Range Set oWB = oExcel.Workbooks.Add Set oWS = oWB.Worksheets("Sheet1") Set oRng1 = oWS.Range("A1:G" & Label2.Caption) 'label2.caption is the record count oRng1.Value = ' shove the record set into the above range 'if I use oRng1.Value = "Monkey" then it writes "monkey" in 'every cell in the range End Sub
I just need to know how to fill the range with the recordset.
Sorted it in the end. May not be the best way, but it does what I need. In case anyone else is looking to do the same thing and was as stuck as I was, here goes:
VB Code:
Private Sub Command3_Click() Dim oExcel As Excel.Application Dim oWB As Excel.Workbook Dim oWS As Excel.Worksheet Dim oRng1 As Excel.Range Dim oRng2 As Excel.Range Dim oRng3 As Excel.Range Dim oRng4 As Excel.Range Dim oRng5 As Excel.Range Dim oRng6 As Excel.Range Dim oRng7 As Excel.Range Dim x As Integer, y As Integer Set oExcel = New Excel.Application oExcel.Visible = True Set oWB = oExcel.Workbooks.Add Set oWS = oWB.Worksheets("Sheet1") x = 1 Do While Not rsdata.EOF Set oRng1 = oWS.Range("A" & x) Set oRng2 = oWS.Range("B" & x) Set oRng3 = oWS.Range("C" & x) Set oRng4 = oWS.Range("D" & x) Set oRng5 = oWS.Range("E" & x) Set oRng6 = oWS.Range("F" & x) Set oRng7 = oWS.Range("G" & x) oRng1.Value = rsdata(0) oRng2.Value = rsdata(1) oRng3.Value = rsdata(2) oRng4.Value = rsdata(3) oRng5.Value = rsdata(4) oRng6.Value = rsdata(5) oRng7.Value = rsdata(6) rsdata.MoveNext x = x + 1 Loop 'Cleanup: ' On Error Resume Next ' oExcel.DisplayAlerts = False ' ' Call oWB.Close(SaveChanges:=False) ' <-- ** or True ** ' Set oWB = Nothing ' ' oExcel.Quit ' Set oExcel = Nothing End Sub
Hope this helps someone!