Solved

DBGrid Copy to Clipboard

Posted on 1997-08-09
3
574 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
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 100 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

919 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now