Replace () truncates a string (1 Viewer)

Dumferling

Member
Local time
Today, 14:44
Joined
Apr 28, 2020
Messages
102
I am using the Replace() function to replace a placeholder in the body of an html email. The function works absolutely fine except that it is truncating the string. The string is a text based URL to a file location on a network folder and the string picks up the URL fine but when the Replace function is used, the string truncates. Is there any limitation on the Replace() function?
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 12:44
Joined
Sep 12, 2006
Messages
15,613
You must be using it wrongly.

replace replaces a substring with another string, extending or reducing the string size as appropriate.
This is to do with the emails, isn't it?

The best way of seeing what it does is to run some test code to get used to how to manipulate the strings, and to check that the substitution works correctly.

Maybe you somehow are using a fixed length string.

Either
newstring = replace(oldstring, "searchfor", "replacewith") OR
oldstring = replace(oldstring, "searchfor", "replacewith")

should replace a string of 9 characters with a string of 10 characters, and the result should be one character longer.
Obviously you will use variables not actual strings in your code.

For instance, I use xxxXXXxxxXXX in some labels to allow for an email address of any length and then use this to adjust the label. Note the upper case/lower case is not significant, It was just an easy way for me to count how many characters I had.

mylabel,caption = replace(mylabel.caption,"xxxXXXxxxXXX",emailaddress)
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 07:44
Joined
Feb 28, 2001
Messages
26,996
If this is in the body of an HTML-based mail message and you experience truncation, I have to ask: how long is that file-body?

If you are treating the body as a single string, Access has a hard limit of 65,535 characters in a string. However, if there is a field from a table that is somehow involved, that can have a much lower limit (255 characters).
 

Isaac

Lifelong Learner
Local time
Today, 05:44
Joined
Mar 14, 2017
Messages
8,738
Show your code so we can see what the problem is

The String data type can store fixed-length strings ranging in length from 0 to approximately 63K characters and dynamic strings ranging in length from 0 to approximately 2 billion characters
(VBE Glossary | Microsoft Docs)
 

missinglinq

AWF VIP
Local time
Today, 08:44
Joined
Jun 20, 2003
Messages
6,423
As said, we really need to see all of your code in the problematic event! There are a number of things in Access that will cause truncation of a field...but using Replace() isn't one of them.

It's possible that something other than Replace() is actually causing the problem.

Linq ;0)>
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 07:44
Joined
Feb 28, 2001
Messages
26,996
Linq is absolutely correct. When you say "truncate" ... can you count or at least make an estimate of how many characters remain after truncation?
 

Users who are viewing this thread

Top Bottom