HostGator
OptinMonster
PayPal
Chris Farrell Membership
This site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies. Find out more.

How To Send, Copy Information To The Clipboard Using A Button. Access Vba Tutorial

 Posted by  Add comments
 

How To Send, Copy Information To The Clipboard Using A Button. Access Vba Tutorial

Ever wanted to copy the contents of a control, i.e., a text box or similar to the clipboard from a MS Access form so the contents can be pasted into another field or application? Considering how pervasive the clipboard is on Windows computers you would think this is a simple task! Not so.

The usual solution of pressing the key combination, Ctrl-C, could not be used for fear of accidentally changing the text box contents. So I figured the easiest solution would be to use either a double click or button to do the copying. Simple! Not really, until you know the answer that is.

I don’t know about you but I write my own MS Access databases, only smallish programs usually but they get the job done and, like everyone else, I find problems which I’m unable to solve. Solution to the problem! A quick search of the internet.

Well the search went on and on and I was getting rather annoyed that such a simple task was taking so long. After all, with the advent of oops programming the problem should be as simple as writing a function to copying the object to the clipboard:

Sub CopyToClipboard_btn_Click()
On Error GoTo Err_CopyToClipboard_btn_Click
‘Save any edits first.
If Me.Dirty Then
Me.Dirty = False
End If

Clipboard = Me.TheTextBox
Exit_CopyToClipboard_btn_Click:
Exit Sub

Err_CopyToClipboard_btn_Click:
MsgBox Err.Description
Resume Exit_CopyToClipboard_btn_Click
End Sub

Unfortunately, this and many other scenarios did not work.

A move in the right direction was to use the function statement:

DoCmd.RunCommand acCmdCopy

but this also proved a nightmare … at first.

Solution

The problem of using the, DoCmd.RunCommand acCmdCopy, statement is that my default setting for the “Behavior Entering Field” property of the database is set to “Go to start of field” and not “Select entire field”, (Options).

The solution is to select the entire field before trying to copy the data to the clipboard.

me.TheTextBox.SetFocus
me.TheTextBox.SelStart = 0
me.TheTextBox.SelLength = Len(me. TheTextBox)
DoCmd.RunCommand acCmdCopy

Simple, when you know how.

This solution was provided by, Dale.

Conclusion

Well, I hope you found something useful and enjoyed this session, please don’t forget to let me have your thoughts or even a better solution. See you soon.

 


KingSolutions.org.uk is hosted on JustHost

  One Response to “How To Send, Copy Information To The Clipboard Using A Button. Access Vba Tutorial”

  1. Hello Philip

    This was very helpful and replaced an unreliable method using SendKeys!

    I have in addition found a way of including spaces at the end of a text string.

    My question now is: Is there a way of inserting the contents of the Clipboard into the “Enter Parameter Value” box? For me this is to substitute a user variable in a Filter string.

    I am currently using a SendKeys method for this, which has so far been reliable.

    I hope this gets to you and I will be very interested to read your comments.

    Martin

 Leave a Reply

(required)

(required)

186 queries in 1.069 seconds (Child).