473,233 Members | 1,603 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,233 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 4453
isladogs
452 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
213 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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
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...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.