Results 1 to 6 of 6

Thread: printing contents of datagrid [resolved]

  1. #1

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358

    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

  2. #2
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196
    VB Code:
    1. Picture1.Picture = Grid.Picture

    that line loads the grid in a picturebox so you can just print from there.

  3. #3

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358
    Sorry, you've lost me (not difficult)
    The Bloke
    www.blokeinthekitchen.com
    making cooking cool for blokes

  4. #4
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196
    opps, sorry I was thinking of MSFlexGrid.

  5. #5

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358
    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:
    1. Private Sub Command3_Click()
    2.     Dim oExcel As Excel.Application
    3.     Dim oWB As Excel.Workbook
    4.     Dim oWS As Excel.Worksheet
    5.    
    6.     Set oExcel = New Excel.Application
    7.     oExcel.Visible = True
    8.    
    9.     Dim oRng1 As Excel.Range
    10.  
    11.     Set oWB = oExcel.Workbooks.Add
    12.     Set oWS = oWB.Worksheets("Sheet1")
    13.    
    14.     Set oRng1 = oWS.Range("A1:G" & Label2.Caption)
    15.     'label2.caption is the record count
    16.  
    17.      oRng1.Value = '    shove the record set into the above range
    18.     'if I use oRng1.Value = "Monkey" then it writes "monkey" in
    19.     'every cell in the range
    20.  
    21. 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

  6. #6

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358
    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:
    1. Private Sub Command3_Click()
    2.     Dim oExcel As Excel.Application
    3.     Dim oWB As Excel.Workbook
    4.     Dim oWS As Excel.Worksheet
    5.     Dim oRng1 As Excel.Range
    6.     Dim oRng2 As Excel.Range
    7.     Dim oRng3 As Excel.Range
    8.     Dim oRng4 As Excel.Range
    9.     Dim oRng5 As Excel.Range
    10.     Dim oRng6 As Excel.Range
    11.     Dim oRng7 As Excel.Range
    12.    
    13.     Dim x As Integer, y As Integer
    14.    
    15.     Set oExcel = New Excel.Application
    16.     oExcel.Visible = True
    17.    
    18.     Set oWB = oExcel.Workbooks.Add
    19.     Set oWS = oWB.Worksheets("Sheet1")
    20.    
    21.     x = 1
    22.    
    23.     Do While Not rsdata.EOF
    24.    
    25.         Set oRng1 = oWS.Range("A" & x)
    26.         Set oRng2 = oWS.Range("B" & x)
    27.         Set oRng3 = oWS.Range("C" & x)
    28.         Set oRng4 = oWS.Range("D" & x)
    29.         Set oRng5 = oWS.Range("E" & x)
    30.         Set oRng6 = oWS.Range("F" & x)
    31.         Set oRng7 = oWS.Range("G" & x)
    32.        
    33.         oRng1.Value = rsdata(0)
    34.         oRng2.Value = rsdata(1)
    35.         oRng3.Value = rsdata(2)
    36.         oRng4.Value = rsdata(3)
    37.         oRng5.Value = rsdata(4)
    38.         oRng6.Value = rsdata(5)
    39.         oRng7.Value = rsdata(6)
    40.    
    41.         rsdata.MoveNext
    42.             x = x + 1
    43.     Loop
    44.    
    45. 'Cleanup:
    46. '    On Error Resume Next
    47. '    oExcel.DisplayAlerts = False
    48. '
    49. '    Call oWB.Close(SaveChanges:=False)  ' <-- ** or True **
    50. '    Set oWB = Nothing
    51. '
    52. '    oExcel.Quit
    53. '    Set oExcel = Nothing
    54. 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
  •  



Click Here to Expand Forum to Full Width