Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Append data from text field to a Memo field

Status
Not open for further replies.

dbar10

Programmer
Dec 5, 2008
196
US
I have two forms that I am currently working with. Main form is [POC Form]. 2nd form is Search results form [Orders Search]. In my main form I have a memo field where text is typed in by user and then I need to be able to append the info from the search results form to where my cursor was in the main form. I can do this with a macro or VBA. I want to DblClick on the field in the search form to execute the command. The field in the search form is [OrdersDescription]. I have looked everywhere I can think of and have not been able to come up with an answer.
 
Code:
Private Sub ordersDescription_DblClick(Cancel As Integer)
  Dim strTextbegin As String
  Dim strTextEnd As String
  Dim strTextInsert As String
  Dim pos As Integer
  strTextInsert = Me.ordersDescription
  Dim ctl As Access.TextBox
  Set ctl = Forms("frmNotes").Notes
  ctl.SetFocus
  pos = ctl.SelStart
  strTextbegin = Left(ctl.Text, pos)
  strTextEnd = Mid(ctl.Text, pos + 1)
  ctl.Text = strTextbegin & " " & strTextInsert & " " & strTextEnd
End Sub
 
Thank you MajP. I tried the code and it almost did it. The only thing is that when it inserts the text from the Search form it puts it at the beginning of the Memo field in the main form. Sometimes there will be text in the field and the insert needs to append to the existing text if it's there. Can you help? Here's the way the code looks now:

Private Sub Description_DblClick(Cancel As Integer)
Dim strTextbegin As String
Dim strTextEnd As String
Dim strTextInsert As String
Dim pos As Integer
strTextInsert = Me.Memo
Dim ctl As Access.TextBox
Set ctl = Forms![POC Form].TextOrders
ctl.SetFocus
pos = ctl.SelStart
strTextbegin = Left(ctl.Text, pos)
strTextEnd = Mid(ctl.Text, pos + 1)
ctl.Text = strTextbegin & " " & strTextInsert & " " & strTextEnd

End Sub
 
At first you said this
Code:
I need to be able to append the info from the search results form to where my cursor was in the main form
And that is what the code does. It puts it at wherever you had the cursor; beginning, middle, end.

Now you say
Code:
Sometimes there will be text in the field and the insert needs to append to the existing text if it's there

Do you want it where the cursor was or do you want it at the end? At the end is a lot easier.

Code:
Private Sub ordersDescription_DblClick(Cancel As Integer)
  Dim strTextbegin As String
  Dim strTextInsert As String
  strTextInsert = Me.ordersDescription
  Dim ctl As Access.TextBox
  Set ctl = Forms("frmNotes").Notes
  ctl.SetFocus
  strTextbegin = ctl.Text
  ctl.Text = strTextbegin & " " & strTextInsert
End Sub
 
Thank you MajP. I don't know why the other wasn't working. I tried moving my cursor to different places and it kept putting the insert at the beginning. but the new code works great!! Thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top