473,387 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

VBA- Copy in Access

I have been asked to create a copy button in an access form to copy the Data in the fields that users enter so they can paste it in an internal system. I crated button and created VBA code "on the click:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command6_Click()
  2.  On Error GoTo Err_cmdDuplicate_Click
  3.    DoCmd.RunCommand acCmdSelectRecord
  4.     DoCmd.RunCommand acCmdCopy
  5.  
  6. Exit_cmdDuplicate_Click:
  7.     Exit Sub
  8.  
  9. Err_cmdDuplicate_Click:
  10.      MsgBox Err.Description
  11.     Resume Exit_cmdDuplicate_Click
  12.  
  13. End Sub
I am having 2 problems:
it copies all the data with the headers but and it paste it vertically other than horizontally . which I guess it needs to be formatted but I am not sure how since I am not VBA SAVVY. I have to add since the code was grabbing everything in the form even the information that I didn't want to and it looked like a chaos ,I created a query then a report based on the query then made copy button with the code behind it.
I appreciate your help in advance.

Attached Images
File Type: jpg PIC2.jpg (24.4 KB, 416 views)
File Type: jpg PIC3.jpg (42.1 KB, 430 views)
File Type: jpg PIC1.jpg (16.6 KB, 394 views)
Jul 13 '18 #1
5 2429
twinnyfo
3,653 Expert Mod 2GB
If it is only certain fields that you need to copy, then you will ave to write the VBA to select those particular fields and save them separately. The code you posted simply copies the entire record.
Jul 14 '18 #2
zmbd
5,501 Expert Mod 4TB
the fields that users enter so they can paste it in an internal system
Looks like you are using a word document, is this correct?
If so, take a look at:
home > topics > microsoft access / vba > insights > application automation
The two examples are for Outlook and Excel; however, simple step to do this same thing with Word. Before we can help you do that we would need a bit more information about what you are doing with the information... may be easier to create a report in Access or to link the Word document to the database using the mail-merge if the access-report can't handle something (although, since Access2003 I've been moving more and more of my stuff from external Word merges to internal reports).
Jul 14 '18 #3
no I was just trying to show where its pasted
Jul 24 '18 #4
I found the code
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdCopy_Click()
  2. On Error GoTo Err_cmdDuplicate_Click
  3.  
  4.  
  5.  
  6. 'Copies values from agent entered data fields into
  7. 'required format and copies to
  8. 'system clipboard.
  9.  
  10. 'control name and type are as follows:
  11. 'CboTeam
  12. 'CboTax
  13. 'TboCallBack
  14. 'TboCaller
  15. 'TboBusName
  16. 'CboAuthType
  17. 'TboAuthID
  18. 'CboContact
  19. 'TboDetail
  20. 'TboBal
  21. 'TboDelqs
  22.  
  23.  
  24. Application.Echo False
  25. Me.PasteBox.Visible = True
  26.  
  27. Me!PasteBox.Value = _
  28. "Team:  " & Me!CboTeam & vbNewLine & _
  29. "Tax Type: " & Me!CboTax & vbNewLine & _
  30. "Phone:  " & Me!TboCallBack & vbNewLine & _
  31. "Caller:  " & Me!TboCaller & vbNewLine & _
  32. "Business Name:  " & Me!TboBusnAME & vbNewLine & _
  33. "Authentication Method:  " & Me!CboAuthType & vbNewLine & _
  34. "Authentication ID:  " & Me!TboAuthID & vbNewLine & _
  35. "Contact Reason:  " & Me!CboContact & vbNewLine _
  36.     & vbNewLine & _
  37. "Call Detail:" & vbNewLine & _
  38. Me!TboDetail & vbNewLine _
  39.     & vbNewLine & _
  40. "Balance:  " & Me!TboBal & vbNewLine & _
  41. "Delinquent Periods:  " & Me!TboDelqs
  42.  
  43.  
  44.  
  45. Me.PasteBox.SetFocus
  46. DoCmd.RunCommand acCmdCopy
  47.  
  48. Me.cmdcopy.SetFocus
  49.  
  50.  
  51. Me.PasteBox.Visible = False
  52. Application.Echo True
  53.  
  54.  
  55. Exit_cmdDuplicate_Click:
  56.     Exit Sub
  57. Application.Echo True
  58.  
  59. Err_cmdDuplicate_Click:
  60.      MsgBox Err.Description
  61. Application.Echo True
  62.     Resume Exit_cmdDuplicate_Click
  63. Application.Echo True
  64. End Sub
Jul 24 '18 #5
zmbd
5,501 Expert Mod 4TB
So is this the code that you are using now... or is this Code that you found somewhere online?

You also haven't answered if you've tried to do this by creating report in Access based on your query or a mail-merge document in Word based on your query. Both methods can yield some very sophisticated reports and are my first goto methods verses VBA.
Jul 25 '18 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: svdh2 | last post by:
Dear All, I have lately strugled more and more with Access, what started as a simple database has brought me to the fundaments of Access. I need to transfer fields from various tables to a...
2
by: Mindy | last post by:
Does anyone have a book to recommend for programming in ACCESS. I want to find a book which is for enter level VBA programmer, but not Dummy one. I hope the book is focusing on syntax of VBA, and...
1
by: axs221 | last post by:
My company I work for uses VBA for Access to program one of our projects. We just now set up the Subversion version control system for our various projects. It works great for our VB6 and .NET...
0
by: Skywalker | last post by:
Hi. Can you please help me? I have problem;-) I am copying from one computer to another 50 MB large text file. For now is everything working. My question is, if I can in VBA for MS ACCESS show to...
4
by: muhes | last post by:
Hello Everyone, I am trying to teach myself a little more about VBA for Access, can anyone recommend a good book for this. (At this point I've read Access VBA Programming for dummies, but I didn't...
14
by: Flo100 | last post by:
Hi All, I have a simple query that I want to execute in VBA in Access. My form has a button and the following code exists in the click event of the button: Dim db As DAO.Database Dim strSQL As...
1
by: christianlott1 | last post by:
I want to copy an Access pivot table into word with vba. I'm guessing I'd need to Select All, copy to the clipboard, and paste special into word at a bookmark. I know how to address the...
1
by: igurov | last post by:
Hi, I want to copy access tables to oracle database. Till now I have opened the connections to both of them. Can anyone explain me what are the next steps? Here is the code that I wrote till now:...
2
by: Grizzlie | last post by:
Hi everyone, I'm a VBA (MS Access) coder. Sorry if I post this in the wrong forum - please direct me if it's. I would like to know how to write a script to send a filename (e.g. "c:\My...
3
by: ptaleski | last post by:
Hello Everybody, Long time since my last log here. My question is how to extract data from HTML file, which is on my computer, using vba. This all is done in Access. One very important thing is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.