append text to end of multi-line textbox

M

Mark Andrews

Access2007:
If I have a multiline textbox (txtSample) on a form with text of "123456789"
and then I enter 3 carriage returns at the end, if I capture
txtSample.SelStart position in the txtSample_KeyUp event at the end of
everything it is 15 (9 characters plus 6 for the 3 CRs (assuming that's
CHR(10) and Chr(13)).

However if focus leaves the field it strips out the ending carriage returns.

Anyway to get Access2007 to stop stripping out the carriage returns?

I want to append some other text to the text "123456789" and 3 carriage
returns.

I could write logic to add back in CRs based on the 6 (in this example) but
would rather not.

Thanks in advance,
Mark
 
L

Lynn Trapp

Mark,
Why not concatenate everything you need to add to the end of the field in
the BeforeUpdate event of the field?
 
M

Mark Andrews

I am building an email template system where the user clicks on another
combobox to pick a merge field to be added to the body of the email text.
So the user needs to move focus over to the combobox so they can determine
which field to add. I capture the latest SelStart so I know where to add
the merge text into the text.

However if the user adds CR(s) to the end they are stripped off and the
SelStart position is no longer valid.

I bit the bullet and built my code so it adds CRs (if it has to to the end).

Just wondering why Access strips off the CRs?

You can see this behavior on any multiline text box (enter a bunch of CRS
after the text, and move to another field, when you move back they are
gone).

Thanks for trying,
Mark

Mark
 
K

kate

Mark Andrews said:
I am building an email template system where the user clicks on another
combobox to pick a merge field to be added to the body of the email text.
So the user needs to move focus over to the combobox so they can determine
which field to add. I capture the latest SelStart so I know where to add
the merge text into the text.

However if the user adds CR(s) to the end they are stripped off and the
SelStart position is no longer valid.

I bit the bullet and built my code so it adds CRs (if it has to to the
end).

Just wondering why Access strips off the CRs?

You can see this behavior on any multiline text box (enter a bunch of CRS
after the text, and move to another field, when you move back they are
gone).

Thanks for trying,
Mark

Mark
 
K

kate

Mark Andrews said:
I am building an email template system where the user clicks on another
combobox to pick a merge field to be added to the body of the email text.
So the user needs to move focus over to the combobox so they can determine
which field to add. I capture the latest SelStart so I know where to add
the merge text into the text.

However if the user adds CR(s) to the end they are stripped off and the
SelStart position is no longer valid.

I bit the bullet and built my code so it adds CRs (if it has to to the
end).

Just wondering why Access strips off the CRs?

You can see this behavior on any multiline text box (enter a bunch of CRS
after the text, and move to another field, when you move back they are
gone).

Thanks for trying,
Mark

Mark
 
H

Hans Up

Mark said:
However if the user adds CR(s) to the end they are stripped off and the
SelStart position is no longer valid.

I bit the bullet and built my code so it adds CRs (if it has to to the end).

Just wondering why Access strips off the CRs?

You can see this behavior on any multiline text box (enter a bunch of CRS
after the text, and move to another field, when you move back they are
gone).

Sorry, I don't know what the rationale is for the behavior which is
causing your grief. But it sounds to me like you're saying trailing CRs
are handled the same as trailing spaces. Maybe if you can find out why
trailing spaces are discarded, you'll find the same answer applies to
trailing CRs.
 
M

Mark Andrews

No grief anymore I just wrote logic that adds back the CRs if needed. I
assume Access is doing a trim
type operation on the data. I assume that is by design? However it would
be better if they just left the data in the multiline textbox stay the same.
Of course now that you mention trailing spaces my fix is not exactly right
but I think I can live with it, not sure how to tell what was trimmed off
(spaces or CRs).

I did find a few articles on trailing spaces and it sounds like it is by
design that Access saves data and removes the extra spaces and CRs. It just
makes life a little more difficult when building an email template creation
system (where the user moves the focus over to a combobox to pick the
mergefield they want to add into the template). The are lots of times they
would add a few returns and then want to add a new merge field, or even a
space or two.

If any Microsoft people read this post perhaps think about changing this
behavior. I'm sure it has pros and cons each way.

Thanks,
Mark
 
H

Hans Up

Mark said:
I did find a few articles on trailing spaces and it sounds like it is by
design that Access saves data and removes the extra spaces and CRs. It just
makes life a little more difficult when building an email template creation
system (where the user moves the focus over to a combobox to pick the
mergefield they want to add into the template). The are lots of times they
would add a few returns and then want to add a new merge field, or even a
space or two.

Could the control's before update event append a special character (or
sequence) to the value to preserve trailing spaces and linefeeds? Then,
when your code needs to use it, strip off the special character (if
present).

Honestly, I have no idea whether that would work. And if it would, if
it would be practical. But, other than that, I got nuthin' :-(
If any Microsoft people read this post perhaps think about changing this
behavior. I'm sure it has pros and cons each way.

Interesting. What about applications built assuming the current behavior?

Regards,
Hans
 
M

Mark Andrews

Something like that might work. I already made it so it just adds CRs if
the last SelStart position is longer than the length of the field. For my
purposes I think that will work out ok. If they had some extra spaces they
will get CRs instead (one for every two spaces they added).

I'm fine with millions of other applications crashing just to fit my needs
(LOL). Might even drum up more business for me.

Thanks for trying,
Mark
 
H

Hans Up

Mark said:
I'm fine with millions of other applications crashing just to fit my needs
(LOL). Might even drum up more business for me.

Thanks, Mark! That one made me laugh out load.

I gotta respect your honesty! :-0

Cheers,
Hans
 

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