?
Solved

Paste Append data from clipboard to table

Posted on 2011-09-26
7
Medium Priority
?
3,018 Views
Last Modified: 2012-05-12
I have a command button and am looking for a macro action or vba to trigger data to be copied from the clipboard onto a table.  Any idea's?
0
Comment
Question by:JSSenior
[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
7 Comments
 
LVL 7

Expert Comment

by:BusyMama
ID: 36599336
I think we need more information ... is the command button on a form in Access, or on an Excel sheet?  How does the data get on the clipboard?  I am assuming the table is in Access already.
0
 

Author Comment

by:JSSenior
ID: 36599488
Copied from Excel.  Command button is on Access form and table is already in Access.

Thanks
0
 
LVL 7

Accepted Solution

by:
BusyMama earned 1000 total points
ID: 36599702
Excel and Access play so nicely together that there are a couple of different ways I would do this, it depends on how firm you are on wanting to copy & paste.

You can turn your Excel document into a type of "submission" form, with a button in Excel that will send the data to the correct table in Access instead of copying then going to Access & pasting.  A brief, generic code sample is attached at the end of this message.

Or, you could also link the Excel document to Access via a linked table.  If you did that, you could create an Append query in Access and use your existing button on your existing for to just run the Append query.

But, I think if you want to just paste, something like this on the existing button should work:

DoCmd.GoToRecord , , acNewRec

DoCmd.DoMenuItem acFormBar, acEditMenu, acPaste, , acMenuVer70

'This is sample code for if you want to insert FROM Excel instead of in Access
Private Sub CommandButton1_Click()

   Dim db As Database, rs As Recordset, r As Long
   Set db = OpenDatabase("DriveLetter:\DirectoryName\DirectoryName\DatabaseName.mdb")
     'open the database
    Set rs = db.OpenRecordset("TABLENAME", dbOpenTable)
        With rs
           .AddNew ' create a new record
             'add values to each field in the record
            .Fields("TableFieldName1") = Range("B" & 4).Value
            .Fields("TableFieldName2") = Range("B" & 5).Value
            .Fields("TableFieldName3") = Range("B" & 6).Value
            .Fields("TableFieldName4") = Range("B" & 7).Value
            .Fields("TableFieldName5") = Range("B" & 8).Value
            .Fields("TableFieldName6") = Range("B" & 9).Value
            .Fields("TableFieldName7") = Range("B" & 10).Value
            .Update ' stores the new record
        End With
    rs.Close
    Set rs = Nothing
    db.Close
    Set db = Nothing
    
End Sub

Open in new window

0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 1000 total points
ID: 36600215

re: DoCmd.DoMenuItem acFormBar, acEditMenu, acPaste, , acMenuVer70
I might just note the Microsoft deprecated the DoMenuItem commands more than 10 years ago.

It's better to use the DoCmd.RunCommand equivalent which is

Docmd.RunCommand acCmdPaste

because there is no guarantee the Microsoft will continue to provide backward compatibility for those commands in the future.

mx


0
 
LVL 7

Expert Comment

by:BusyMama
ID: 36600516
Good to know ... since I'm still using it the other way!  Thanks, mx!
0
 
LVL 75
ID: 36600617
Hey ... you are welcome.

mx
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36627860
Also note that there are more structured ways to do this that are built into Access.
Using the clipboard can cause issues if other programs (that you may not be aware of) are also accessing it.

Can you explain a bit more about this "data"?
Where is it from?
How are you selecting/copying it?
Are these ad hoc imports or, fairly repetitive?
...etc

Typically you can transfer data to Access in any number of ways that will allow you to "Paste" the data.
TransferText
TranferSpreadsheet
...etc

JeffCoachman
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Suggested Courses

752 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