?
Solved

DBGrid Copy to Clipboard

Posted on 1997-08-09
3
Medium Priority
?
581 Views
Last Modified: 2008-03-17
I have a DBGrid that is populated by an SQL and I would like to be able to copy all of the data to the clipboard in a format that can be pasted to Excel/Access etc....
0
Comment
Question by:jcorbin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 9

Expert Comment

by:cymbolic
ID: 1430126
Your problem is that the Grid control is really a large collection of separate controls.  In order to get all the data, you will have to interate through all the cells, collect the data, and format it for inclusion.  I recommend that if you are going to all this trouble anyway, that you dump the clipboard idea, and use the import features in Excel and Access.  You can save your data in a comma delimited format that can be read by either system.  It's simple, it's safe, and if the import doesn't get there, or your system honks in the middle, the file(s) are still there for later import.
0
 

Author Comment

by:jcorbin
ID: 1430127
I understanf all of those concerns, but I need to see the code to iterate thru the grid and copy it to the clipboard, from there I can print, export to excel etc....



0
 
LVL 5

Accepted Solution

by:
volking earned 400 total points
ID: 1430128
Here's a code snippet I use in one of my apps. It copies the entire contents of a DBgrid (bound to a data control) to the clipboard.  Excel and Word will allow paste.

Private Sub btnCopyForPaste_click()
    Dim Bulk$, Row&, Col%
    For Row& = 1 To (dcRaw.Recordset.RecordCount - 1)
        DBGrid1.Row = Row&
        For Col% = 0 To (DBGrid1.Columns.Count - 1)
            DBGrid1.Col = Col%
            Bulk$ = Bulk$ + DBGrid1.Text + vbTab
        Next
        Mid$(Bulk$, Len(Bulk$)) = Chr$(13)
    Next
    Clipboard.Clear
    Clipboard.SetText Bulk$, vbCFText
End Sub


Enjoy
===================> Frederick
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

801 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