Insert (Append) text into a memo field

R

Richard..

Is there a way to insert, that is add to the text already in a memo field?

I can't seem to find any code technique that would allow me to insert
(append) programmed comments into a memo field. The only things I have been
able to find overwrote what was already there. I don't want to do that.

I have a memo field that is used for making special comments in regard to
the current project. There is only one memo field that is used.

I DO NOT want to create a new record each time I insert a programmend
comment into the memo field.

The users are free to insert text into the memo field and that is how it is
done most of the time. However, when the circumstances arise I want to have
the program insert a comment into that same memo field.

The preferred method would be to insert text at the top of the memo field.
But if I must append to the bottom, I can live with that as well.

I need the ability to insert carriage returns as well, even if they are the
ASCII code.

Thanks
 
S

Stefan Hoffmann

hi Richard,
Is there a way to insert, that is add to the text already in a memo field?
INSERT INTO [yourTable]
SET [yourMemo] = "newText" & Chr(13) & Chr(10) & [yourMemo]



mfG
--> stefan <--
 
R

Richard..

How does this work in VBA code?

All I get is a compile error telling me that it was expecting the end of
statement.

Cannot find any VBA code named "INSERT". I find "InsertText Method" and
"InsertLines Method", but no "Insert".

Stefan Hoffmann said:
hi Richard,
Is there a way to insert, that is add to the text already in a memo field?
INSERT INTO [yourTable]
SET [yourMemo] = "newText" & Chr(13) & Chr(10) & [yourMemo]



mfG
--> stefan <--
 
S

Stefan Hoffmann

hi Richard,
How does this work in VBA code?
This is not VBA, it is a SQL statment for a query, as you didn't have
said where you want to modify your memo and of what kind your memo is.

If you like to append text before existing text in a TextBox on a form,
then you may use:

txtMemo.Value = "yourNewText" & vbCrLf & txtMemo.Value


mfG
--> stefan <--
 
R

Richard..

Okay, Thanks

But I must be missing something here.

First this insert is occuring in a subform from an action taking place in
the main form. I created the following string in my VBA code:

Me.Loan_Comments.Value = "Test" & vbCrLf & Me.Loan_Comments.Value

When I try to execute it I get the compile error: Method or data member not
found.

I don't see the ".Value" in the list of valid values for this field.
 
J

Jim Burke in Novi

I do something similar in my application. I have a memo field, which on my
form is represented by a textbox (call it TB1). I also have another textbox
where I can type new information that will be inserted into the existing memo
field (call it TB2). I have it set up so that I type in the new text in TB2,
then click in TB1 to show where I want it inserted, then click a button to
tell it to copy the new text at that position. When I click on TB1 showng
where I want it inserted, I have an On_Click event proc that has one
statement:

cursorPos = txtComment.SelStart

where cursorPos is a Private variable defined at the form level. This keeps
track of the position of the cursor, so I know where to insert.

When I click on the button to tell it to insert I then run the buttons
OnCLick evenr proc, which has this code:

Dim commentLength As Integer
Dim rightData as string, leftData As String

If Nz(Len(TB2), 0) = 0 Then 'No new text was entered
Exit Sub
End If

commentLength = Nz(Len(TB1), 0)
If commentLength = 0 Then ' The memo field is blank
TB1 = TB2
Exit Sub
End If

Select Case cursorPos
Case 0 'Insert at the beginning
TB1 = TB2 & TB1
Case commentLength ' Insert at the end
TB1 = TB1 & TB2
Case Else ' Insert in the middle at position 'cursorpos'
leftData = Left(TB1, cursorPos)
rightData = Mid(TB1, cursorPos + 1, TB1 - cursorPos)
TB1 = leftData & TB2 & rightData
End Select
 
S

Stefan Hoffmann

hi Richard,
But I must be missing something here.
Me too.
First this insert is occuring in a subform from an action taking place in
the main form. I created the following string in my VBA code:
Please, describe this a little bit more precisely.


mfG
--> stefan <--
 
J

John Spencer

Well in that case you need to refer to the subform and not to Me which would
be the main form.
The reference would be something like:

ME.NameOfSubformControl.Form.NameOfControlOnSubform

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
R

Richard..

The form as a whole is in one window.

The main form (Name = Loans) is a multi-record display showing one line for
each records. Basic information. IE. Loan #, Status of research, Origin
Date, State.

The subform (Name = Loan_Comments) is at the bottom of the window. It has
the details for each record listed above. As the user selects from the list
of records above the details for that selected record appears below. The
subform has things like various types of dates when certain events occured,
identification tags, and the memo field named "Comments" where I put special
comments.

What I want to do is when a certain "Status" in the main form is set, I want
to insert a text line into the "Comments" memo field in the subform.

Thank you for your assistance.

Richard..
 
S

Stefan Hoffmann

hi Richard,
What I want to do is when a certain "Status" in the main form is set, I want
to insert a text line into the "Comments" memo field in the subform.
Ok. Then the hint from John is the right one.

If Me![Status] = "bla" Then
Loan_Comments.Form![Comments] = "yourText" & vbCrLf & _
Loan_Comments.Form![Comments]
End If

If Comments is a control replace it with .ControlName.Value instead of
![Comments].

mfG
--> stefan <--
 
R

Richard..

That worked great, thank you.

Now that I can insert the text where I want it, I am now thinking it would
be nice to set the cursor at the end of the inserted line so I could add
additional notes myself.

Is that possible?

Thank you,

Richard..
 
S

Stefan Hoffmann

hi Richard,
Now that I can insert the text where I want it, I am now thinking it would
be nice to set the cursor at the end of the inserted line so I could add
additional notes myself.
Is that possible?
Yes, use the .SelStart and .SelLength property of the textbox control.


mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top