• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 87
  • Last Modified:

MS Access: Manipulate the copied text from a control

I need to add some information to a control content when copied.

Say I have a control "MyCtrl" and the user copied the content -say "Abc"- I need then to add -say "123"-, so that when the user paste the information it will be pasted as "Abc123".

I think Access has no an event like on_Copy (That would be awesome), so I need some expert ideas to point me to the best way to do it.
Shadi Saleh
Shadi Saleh
3 Solutions
Pawan KumarDatabase ExpertCommented:
USE & for concatenation

MyCtrl & "123"


John TsioumprisSoftware & Systems EngineerCommented:
Well if understood right you have a textbox and and you want to copy paste the content to another textbox and automatically append something...
While there is no Copy event you could use the clipboard functionality (API...i have some code somewhere but it would be easy to find it by googling it) ...so you copy the content..and when the destination textbox gets the focus (OnFocus) check the content of clipboard ...probably with some validation...and make the pasting...
Shadi SalehAuthor Commented:
Thanks @John Tsioumpris,

Indeed the paste will be done in another application.

I already googled and found this useful page, however, It suggest a way to do copy/paste through vba, but not, tell how to capture the copy event, and this is the most part I need to know about.

I thought of a custom copy button -this, I guess, should work- but what if user used the pop-menu copy.

apparently, I will need also to hide the pop-up menu, but what about ctrl+C?

It does not seem a simple issue that has a magic hidden solution.

I appreciate your suggestion, and I am looking for more expert ideas before I go this way.
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.

This is an abstract issue and there's lots we don't know that might help us to come up with a solution that will always work. For example, if the string should contain these extra characters, why do you not store them?  Is the value you want to concatenate fixed or variable?

I don't think it makes sense to try to prevent people from using the copy and paste ribbon options or shortcut keys.  That just removes functionality that is useful in many situations.  You're going to have to rely on training if you cannot incorporate the extra characters permanently in your copy of the data.

To implement the copy/paste, I would either add a button or the double-click event of the control.  Your code would do the concatenation -- Me.txtMyControl & "123" and then copy it to the clip board.  I don't have the code but someone else may or you should be able to find it.  Then they still have to be relied on to paste into the correct receiving field.
Shadi SalehAuthor Commented:
I think I would use a custom copy button as the only way to copy the content the way the user want, keep the normal copy ways for the normal copy, and instruct the user accordingly.

I just thought that there was something like some webpages that append some stuff to the text you copy from their webpages.

Apparently, there is no such functionality in Access.
John TsioumprisSoftware & Systems EngineerCommented:
I was thinking again about your issue and this my idea of how i would do it...
On the 1 form/application the text that needs to be copied is only available through the DblClick event ...the user double clicks on the text box and the text is copied to the clipboard...for validation i would append in the start something like this : "Valid ToCopy:The Text you want to copy"
On the 2nd form/application the user again DblClicks on the destination textbox...the routine "reads" the clipboard...if the 1st part is  "Valid ToCopy:"...then the remaining text is pasted - manipulated...and clipboard gets cleared
Helen FeddemaCommented:
If the text to be added is constant, you could use an InputMask on the control with the added text pre-filled.
Shadi SalehAuthor Commented:
@Helen Feddema: Thanks, but it is variable.

@John Tsioumpris: Good, but we cannot alter the other application.

As I said before, I have no a problem in the copy process itself using a custom button or double click event.

What I thought, there might be an API function, a reference to another library or a tricky solution to catch the copy event itself regardless of the copy issuer (popup menu command, ribbon command, Ctrl+C or whatever ), then I won't need a custom button.

I tried mouse and keyboard events but they won't help in every case, and they have their implications.

Best Solution yet:

I tried the timer to watch the clipboard changes and to react accordingly.

Private Sub Form_Timer()
    Dim Clipboard_String As String
    Clipboard_String = ReadClipboard()
    If Clipboard_String = Me.Description Then
        CopyToClipboard (Me.Info & " - " & Me.Description)
    End If
End Sub

Open in new window

This was the best I could do yet, but I did not like the idea of the timer. I think something like interrupt would be better. Moreover, this can interfere with the normal copy/past operations.

I will wait some more time hoping to get a better solution, otherwise I would go with this solution if I could mitigate its shortcomings or may be stick to the copy button.

Thanks for all contribution.
Shadi SalehAuthor Commented:
All other comments do not really come up with a solution.

My comment show my efforts to reach what I want to do, and show a code that work the best for my case.

Also, it shows the shortcomings of the all the solutions, and show the alternatives.
John TsioumprisSoftware & Systems EngineerCommented:
Well if you cannot alter the other application then i guess the only solution (a bit "dirty") it would be to use AutoIt...it won't be elegant but we a little effort it should work....
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.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now