Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DBGrid Copy to Clipboard

Posted on 1997-08-09
3
Medium Priority
?
582 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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

610 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