Results 1 to 9 of 9
  1. #1
    kdbailey is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    228

    Copy Table (All Rows and Fields) to Clipboard

    Just want to know if there's a way to copy all but the final field of a table's contents to the clipboard (with or without opening the table - preferably without). Title of thread was incorrect.

    Just use "Example1" as the title of the table, I'd like to copy 4/5 fields.

  2. #2
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    I was able to copy the entire contents of a table and paste it into Word.
    Open the table. Press CTRL-A. This should select the entire table.
    Press CTRL-C.

  3. #3
    kdbailey is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    228
    Sorry, I forgot to clarify that I'm looking to do this with vba.

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Where do you intend to paste the clipboard contents? Can you explain what the end goal is for your copy-paste procedure? Maybe there's an alternate solution.

  5. #5
    kdbailey is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    228
    I'm looking to paste the information into a separate statistical distribution software. The 4 columns are the input for running a statistical analysis.

    Yesterday I was experimenting with the following code but could not figure out how to select 4 columns after opening the table.

    Code:
    Private Sub cmdexport_Click()
    Me.Painting = False
    DoCmd.OpenTable "Example1", acViewNormal
    'NEED CODE TO SELECT FIRST 4 COLUMNS
    DoCmd.RunCommand acCmdCopy
    DoCmd.Close acTable, "Example1", acSaveNo
    Me.Painting = True
    End Sub

  6. #6
    AccessPower's Avatar
    AccessPower is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2016
    Posts
    165
    Well have a query called "qryTop4", and have the query be:

    Code:
    SELECT TOP 4 * FROM Example1;
    Then your code can look like:

    Code:
    Me.Painting = False
    DoCmd.OpenQuery "qryTop4"
    DoCmd.RunCommand acCmdSelectAllRecords
    DoCmd.RunCommand acCmdCopy
    DoCmd.Close acQuery, "qryTop4", acSaveNo
    Me.Painting = True

  7. #7
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    I think AccessPower missed the point.
    If you can live with a csv file to import into your statistical software this code will create the file.
    You will need a reference to Microsoft Scripting Runtime.
    Code is tested works with my example table.
    The csv file will be placed in the same folder as the accdb.

    Code:
    '---------------------------------------------------------------------------------------
    ' Method : subGetFields
    ' Author : Davegri
    ' Date   : 2/16/2017
    ' Purpose: Create csv file of from 4 col of file Example1. Adjust column names as needed.
    '---------------------------------------------------------------------------------------
    Public Sub subGetFields()
        Dim sPath As String
        Dim sPath_and_FileName As String
        Dim rst As DAO.Recordset
        Dim fso As New FileSystemObject
        Dim ts As TextStream
        Dim dq As String
        sPath = Application.CurrentProject.Path & "\"
        sPath_and_FileName = sPath & "FirstFour_" & Replace(Date, "/", "-") & ".csv"
        dq = Chr$(34)      'double quote
        Dim db As Database
        Dim sFieldList As String
        Set ts = fso.CreateTextFile(sPath_and_FileName, True)
        Set db = CurrentDb
        Set rst = db.OpenRecordset("Example1")
        rst.MoveLast
        rst.MoveFirst
        'write header row in csv file
        ts.WriteLine (dq & "HeadFirst" & dq & "," & dq & "HeadSecond" & dq & "," & dq & "HeadThird" & dq & "," & dq & "HeadFourth" & dq)
        Do While Not rst.EOF
            sFieldList = _
            dq & rst!FirstField & dq & "," & _
            dq & rst!SecondField & dq & "," & _
            dq & rst!ThirdField & dq & "," & _
            dq & rst!FourthField & dq
            ts.WriteLine sFieldList
            rst.MoveNext
        Loop
        ts.close
        Set rst = Nothing
        Set db = Nothing
        Set ts = Nothing
    End Sub
    Last edited by davegri; 02-16-2017 at 10:54 PM. Reason: bug out

  8. #8
    kdbailey is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    228
    While it wasn't exactly what I needed, I was able to adapt AccessPower's suggestion. I queried for the fields I need and then use DoCmd.RunCommand AcCmdSelectAllRecords then proceed to copy.

    I appreciate the help from all.

  9. #9
    AccessPower's Avatar
    AccessPower is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2016
    Posts
    165
    You're welcome

Please reply to this thread with any new information or opinions.

Similar Threads

  1. btn macro what can copy text to clipboard
    By TriFith in forum Import/Export Data
    Replies: 6
    Last Post: 07-01-2016, 02:45 AM
  2. Copy To Clipboard - Max Length?
    By fredz in forum Access
    Replies: 3
    Last Post: 05-31-2014, 02:03 PM
  3. Replies: 2
    Last Post: 12-05-2012, 09:39 PM
  4. Replies: 1
    Last Post: 10-29-2012, 08:15 AM
  5. Use VBA to copy table contents to the clipboard?
    By Deutz in forum Programming
    Replies: 3
    Last Post: 10-21-2010, 10:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums