Paste labels value into active field

My plan is for the user to place the cursor in the field of a subform and click the label located in the detail section of the main form to paste its value into the field. Ive never coded for the paste function.
LVL 1
atreidiesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mbizupCommented:
Are you trying to place a label's caption into a textbox?

Thi code in the label's click event would be:
        Me.MyTextbox = Me.MyLabel.Caption

Open in new window


(You don't need code to 'copy/paste')

Also, this has to be done with a standalone label.  Labels that are associated/attached to other controls don't have their own click events.


0
atreidiesAuthor Commented:
Each label will be stand alone...that should work but how do i reference the active textbox as the destination as the cursor could be located in any number of fields?
0
Jeffrey CoachmanMIS LiasonCommented:
Not sure, but depending of how your forms are set up, you may lose focus on the subform control/field when you click in the main form Detail section.
(you may be able to store the value though...)

I am also curious as to why you need to "Paste" a value from a subform into a main form.

Can you explain a bit more about what you are trying to ultimately accomplish here?

JeffCoachman
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

atreidiesAuthor Commented:
On the subform the user will place the cursor into a field then click a label to be pasted into the field.  I say paste becuase they may wish to put multiple values into the destination field. Mbizups comment would work if I could reference the field that either has the focus or just lost.  if it does lose the focus perhaps the code could go into the lost focus function to grab the active labels value.
0
mbizupCommented:
So you want the user to click a textbox, then click a label and have the label's caption go into the previously clicked textbox?

You could do something like this -

Define a module level variable, right under "Option Explicit" in your forms code:

Dim mTargetControl as string

Open in new window


In the click event of any textbox you want this functionality for, 'remember' the control name like this:

mTargetControl =Me.ActiveControl.Name

Open in new window


Then in the click event of labels you want this functionality for:

Me.Controls(mTargetControl) = me.ActiveControl.Caption

Open in new window

0
mbizupCommented:
Actually, scrap my last post completely.  That won't work.

The textbox remains the "Active Control" when a label is clicked, so you just need this in the label's click event:


Me.ActiveControl = Me.MyLabel.Caption

Open in new window


(You can refer to the textbox generically as the 'active control', but I thingk you have to specify the label by name)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jeffrey CoachmanMIS LiasonCommented:
I was still curious as to why you need to Paste a value from a subform into a main form...

In any event, I will bow out now to avoid any confusion.

Jeff
0
atreidiesAuthor Commented:
i tried your code as well as using a variable for the caption and same error

"Obejct doesnt support this propery or method"

Dim PasteData As String
PasteData = Me.Label5.Caption
Me.ActiveControl = PasteData

Open in new window

0
atreidiesAuthor Commented:
Success: with this

Dim PasteData As String
PasteData = Me.Label5.Caption
Screen.ActiveControl.Value = PasteData
0
atreidiesAuthor Commented:
Thanks Much...
0
mbizupCommented:
Glad to help out. The issue was that I didnt take your subform into account, I think.

You should also add some form of error handling to that, in case the sequence of user clicks is not what you are expecting.
0
atreidiesAuthor Commented:
Naturally...thanks again
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Applications

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.