|
-
Feb 3rd, 2004, 08:26 AM
#1
Thread Starter
Hyperactive Member
printing contents of datagrid [resolved]
Hi guys
How do I print the contents of a datagrid? Failing that, output the results to Excel?
Cheers
Last edited by thebloke; Feb 3rd, 2004 at 11:59 AM.
The Bloke
www.blokeinthekitchen.com
making cooking cool for blokes
-
Feb 3rd, 2004, 08:49 AM
#2
VB Code:
Picture1.Picture = Grid.Picture
that line loads the grid in a picturebox so you can just print from there.
-
Feb 3rd, 2004, 08:55 AM
#3
Thread Starter
Hyperactive Member
Sorry, you've lost me (not difficult)
The Bloke
www.blokeinthekitchen.com
making cooking cool for blokes
-
Feb 3rd, 2004, 09:05 AM
#4
opps, sorry I was thinking of MSFlexGrid.
-
Feb 3rd, 2004, 10:27 AM
#5
Thread Starter
Hyperactive Member
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.
The Bloke
www.blokeinthekitchen.com
making cooking cool for blokes
-
Feb 3rd, 2004, 12:01 PM
#6
Thread Starter
Hyperactive Member
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!
The Bloke
www.blokeinthekitchen.com
making cooking cool for blokes
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|