473,320 Members | 1,953 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,320 software developers and data experts.

using command button to copy a record in a field

Hi.
I am using Access 2010,

I have a table like below.
In a form, I have a combo box linked with the NAME field and have a buttonm, COPY next to it.

ID NAME NUMBER
1 BACH 1-1212
2 MOZART 2-2323
3 BEETHOVEN 3-4343
4 VIVALDI 4-5656



I would like to make the COPY button functioning copy the NUMBER when I choose a NAME from the combo box. I will paste the number somewhere else as clipboard.
Of course the NAME and the NUMBER should be the same record.
I couldn't find any COPY command in macro but does not matter VB command.

Thanks~
Mar 14 '21 #1

✓ answered by cactusdata

Create a textbox and name it Column2.
It can have a width of zero and be placed anywhere on the form.

Set its ControlSource to: =[NameOfYourCombobox].[Column](2)

Create an AfterUpdate event of the combobox:

Expand|Select|Wrap|Line Numbers
  1. Private Sub NameOfYourCombobox_Click()
  2.  
  3.     Me!Column2.SetFocus
  4.     DoCmd.RunCommand acCmdCopy
  5.     Me!NameOfYourCombobox.SetFocus
  6.  
  7. End Sub
Select a name, and you can paste the value of column2 where you like.

2 4501
isladogs
455 Expert Mod 256MB
First of all both Name and Number are reserved words in Access. Both should be changed or they will cause issues later.

Saving to the clipboard requires the use of an API which cannot be done using a macro.
Whilst it is possible in code, it really isn't necessary in this situation
Instead add code to your combo after update event similar to this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub YourComboName_AfterUpdate()
  2. Dim strText As String
  3. StrText = Me.YourComboName.Column(2) 'this is the third column as numbering starts at 0"
  4. End Sub
  5.  
You can then reuse that strText variable elsewhere. However to prevent it going out of scope outside this procedure/form, you should either define it in the form declarations area or as a public variable in a standard module
Mar 14 '21 #2
cactusdata
214 Expert 128KB
Create a textbox and name it Column2.
It can have a width of zero and be placed anywhere on the form.

Set its ControlSource to: =[NameOfYourCombobox].[Column](2)

Create an AfterUpdate event of the combobox:

Expand|Select|Wrap|Line Numbers
  1. Private Sub NameOfYourCombobox_Click()
  2.  
  3.     Me!Column2.SetFocus
  4.     DoCmd.RunCommand acCmdCopy
  5.     Me!NameOfYourCombobox.SetFocus
  6.  
  7. End Sub
Select a name, and you can paste the value of column2 where you like.
Mar 15 '21 #3

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

Similar topics

9
by: rdade22 | last post by:
Hi, I'm new so try to bare with me. I'm using access 2000 and I created a database where the user is prompted to click on a command button and the info that was put on the form is sent to a table....
5
by: dgrabuloff | last post by:
i am inputting records using a form. how do i put a command button on the form that will copy the record i just input----sometimes i have the same record that needs to be put in 3 or 4 times and i...
4
by: sirimanna | last post by:
hi, Is any one can help me to open files in my computer(for an example: some word document)using command button... i want to open file's using my vb programme..but i can't do it...can any one...
0
by: mesadobes | last post by:
I am very new to visual basic. Actually, I have no clue what I'm doing! But I know what I want to do. I am trying to learn as I go... How do I create a command button that when clicked will...
4
beacon
by: beacon | last post by:
Hi everybody, I have a main form, frmDeficiency, that has a tab control, deficiencyTabControl, that has a subform, fsubEpisodeDetail, on page 2 of the tab control. I also have a command button...
1
by: Palaniappan | last post by:
how to add an item into the textbox by using command button in ms access in the form from the table?
2
by: aanand1 | last post by:
Hi, I am unable to delete a selected record on listbox using command button. I am new to Access and have made VB code using internet help. Here is my code. Private Sub...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.