Never mind. I got it. Here is the code.
Field to have item inserted into (txtMessage)
Private Sub fText_LostFocus()
LLastPosition = Me.fText.SelStart
End Sub
Code on command button (cmdInsert)
Private Sub cmdInsert_Click()
Me.cboReferences.SetFocus
DoCmd.RunCommand acCmdCopy
Me.txtMessage.SetFocus
Me.txtMessage.SelStart = lLastPosition
DoCmd.RunCommand acCmdPaste
Me.Form.Dirty = False
Nd
-----Original Message-----
From: Jay [mailto:
[email protected]]
Posted At: Saturday, March 20, 2010 6:27 PM
Posted To: microsoft.public.access.modulesdaovba
Conversation: cut and paste from a combo box into a memo field
Subject: Re: cut and paste from a combo box into a memo field
Hi John,
I need a little more help with this. Got the SelStart part just fine.
Even tried using the Mid function to parse the text box into two
sections (one before the SelStart and one after) and then insert my
combo box data. The problem is that the source for the text box is a
memo field and is formatted as rich text. When I parse the text using
MID into a variable I get the <div> html text included which throws off
the character count (the SelStart doesn't count the HTML code when
calculating the cursor position in the text box).
Therefore, I wonder if there is a way to Copy the combo box selection
and then Paste it at the SelStart position of the text box. VBA help
says there is a .Copy command but I cannot get it to work.
Thanks.
-----Original Message-----
From: John Spencer [mailto:
[email protected]] Posted At: Saturday, March
20, 2010 12:54 PM Posted To: microsoft.public.access.modulesdaovba
Conversation: cut and paste from a combo box into a memo field
Subject: Re: cut and paste from a combo box into a memo field
In this example I used the Lost Focus event of the memo control.
Private Sub fText_LostFocus()
LLastPosition = Me.fText.SelStart
End Sub
John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
Thanks. "A" makes the most sense to me because I am using a Runtime
app and using forms for navigation not menus. Can you post the code to
record the cursor position in the memo field. Then, would it be better
to put this code in the BeforeUpdate or use a different event of the
memo field.
-----Original Message-----
From: John Spencer [mailto:
[email protected]] Posted At: Saturday,
March 20, 2010 7:12 AM Posted To:
microsoft.public.access.modulesdaovba
Conversation: cut and paste from a combo box into a memo field
Subject: Re: Clarification: the copy should be the bound column not
the displayed column in the combo box.Re: cut and paste from a combo
box into a memo field
It can be done in two ways that I can think of.
A) A form level variable that records the position of the cursor in
the memo field. Then you can set focus to the control and paste the
information into that point.
B) Have a menu-level button so that the focus is not lost by the
control on the form.
I have not attempted to code either solution, but I don't foresee any
major problem with either solution.
I do have something similar that I use to findNext and highlight a
string repeatedly in a text box. I just threw this together quickly
one day. I'm sure it could be cleaner, but it is not in any of my
production databases - personal use only.
John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County