How do I put a field into text edit mode on a Access form using VBA?

Posted on 2012-08-29
Medium Priority
Last Modified: 2012-08-29
I'm actually trying to allow a button press to copy a text from the textbox on that line and paste it into the txtPaste textbox in the header of the form. I have managed to get that working but I want to be able to paste many different things and have them fill up the txtPaste textbox as they keep clicking different buttons.

My thought was to put the textbox into text edit mode by pressing the F2 key so I added a sendkeys line to my vba but it didn't work for some reason. It just keeps pasting over the existing text in the txtPaste box.

Here is my current code;

Private Sub cmdCopy_Click()

DoCmd.GoToControl "KeyPress"

DoCmd.RunCommand acCmdCopy

DoCmd.GoToControl "txtPasteCell"

SendKeys "{F2}"

DoCmd.RunCommand acCmdPaste

End Sub

Thanks for the help!
Question by:SeyerIT
LVL 61

Accepted Solution

mbizup earned 2000 total points
ID: 38344986
Try this to position the cursor at the end of the text before pasting the data:

            me.txtPasteCell.SelStart = len(Me.txtPasteCell & "")
            Me.txtPasteCell.SelLength = 0

Open in new window


Author Closing Comment

ID: 38344992
Perfect, Thanks!

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question