Outlook.mailitem - How to assign to body a memo field with 255 characters and more (1 Viewer)

informer

Registered User.
Local time
Today, 18:59
Joined
May 25, 2016
Messages
75
Outlook.mailitem - How to assign to body a memo field with 255 characters & more

Hi

In a VBA function, I assign to the body of Outlook object a memo field with more than 255 characters

Code:
.Body = recSet!eMailComment
But the memo field content is cut off after 255 characters.

How to circumvent this restriction?

Thanks by advance for your help
 
Last edited:

Minty

AWF VIP
Local time
Today, 17:59
Joined
Jul 26, 2013
Messages
10,374
Try storing the body into a string variable first.
Code:
strBody = recSet!eMailComment
With Outlook.mailitem
.Body = strBody

If that doesn't work is your recordset using any grouping? - see http://allenbrowne.com/ser-63.html for more info.
 

informer

Registered User.
Local time
Today, 18:59
Joined
May 25, 2016
Messages
75
Hy Minty

Thanks for your help but still doesn't work and even after declaring my variable as below

Dim sBody As String * 1024

I used the function below to check sBody content and same result, only 255 charaters were saved in SQL.txt

Code:
Function writeInFile(sSQL As String)
    sPath = "D:\SQL.txt"
    NumFic = FreeFile
    Open sPath For Output As #NumFic
    Print #NumFic, sSQL
    Close #NumFic
End Function
 

Minty

AWF VIP
Local time
Today, 17:59
Joined
Jul 26, 2013
Messages
10,374
So is the recordset using any aggregation at all?
What is the recordset SQL?
That is the most common cause for truncation.
 

informer

Registered User.
Local time
Today, 18:59
Joined
May 25, 2016
Messages
75
Hi Minty

In my vba code I wrote
Code:
 sSQL = "SELECT * FROM qryPayeurPourEdition"
 Set recSet = CurrentDb.OpenRecordset(sSQL)
And qryPayeurPourEdition SQL is

Code:
SELECT DISTINCT tblPayeur.Afficher, tblPayeur.eMailComment, tblPayeur.eMail, tblPayeur.PaiementImediat, UCase([tblPayeur].[civilite] & " " & [tblPayeur].[Prenom] & " " & [tblPayeur].[Nom]) AS PayeurLong, UCase([tblPayeur].[zip] & " " & [tblPayeur].[ville]) AS PayeurLocalite, tblEleve.idPayeur, tblPayeur.civilite AS PayeurCivilite, tblPayeur.Prenom AS PayeurPrenom, tblPayeur.Nom AS PayeurNom, [tblPayeur].[Prenom] & " " & [tblPayeur].[Nom] AS Payeur, UCase([tblPayeur].[Adresse]) AS PayeurAdresse, tblPayeur.ville AS PayeurVille, tblPayeur.zip AS PayeurZip
FROM (tblEleve INNER JOIN tblPayeur ON tblEleve.idPayeur = tblPayeur.idPayeur) INNER JOIN tblAEditer ON tblEleve.idEleve = tblAEditer.idELeve
WHERE (((tblEleve.aEditer)=True));
 

Attachments

  • query.jpg
    query.jpg
    47.6 KB · Views: 73

Minty

AWF VIP
Local time
Today, 17:59
Joined
Jul 26, 2013
Messages
10,374
Remove the DISTINCT.
See the explanation in Allen Browne's list on Uniqueness.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:59
Joined
May 7, 2009
Messages
19,246
To get all the text from memo, make the memo field the first column in your query.
This is also mr.browne's suggestion and mostly work.
 

informer

Registered User.
Local time
Today, 18:59
Joined
May 25, 2016
Messages
75
Thanks a lot for your help and advices. I’ll implement your solution today.
 

informer

Registered User.
Local time
Today, 18:59
Joined
May 25, 2016
Messages
75
Hi All

It works great now

I applied recommendations provided by Allen’s Browne :
  1. Move on first position the memo field
  2. remove DISTINCT SQL command and change my query to select only one record by using SELECT memoField,.... FROM tblX WHERE tblX.id IN ( SELECT DISTINCT tblX.id FROM....).
Thanks a lot again

PS: what does it happen if there is more than one memo field?
 

Minty

AWF VIP
Local time
Today, 17:59
Joined
Jul 26, 2013
Messages
10,374
There won't (shouldn't) be as your Sub query is selecting a Distinct record.
 

informer

Registered User.
Local time
Today, 18:59
Joined
May 25, 2016
Messages
75
Hi Minty,

Using DISTINCT SQL command in subquery doesn’t cause truncation of memo field if it is selected in the principal request. For my case, it works perfectly:)
 

Minty

AWF VIP
Local time
Today, 17:59
Joined
Jul 26, 2013
Messages
10,374
What I meant was you using Distinct in the sub query will only return one record. Which won't affect your memo as it isn't in the Sub Query.
 

informer

Registered User.
Local time
Today, 18:59
Joined
May 25, 2016
Messages
75
Thanks a lot again for your help.

I precise :
A payer (tblPayeur) can pay for several students (tblEleve).
Even if I trangress rules for modelling a db scheme, I store in an table (tblAEditer), students who have courses for a period MM/YYYY entered dynamically in a form which displays the list of these students.
Then, I flag (aEditer=true) in this form, students for which an invoice will be printed (report) and sent by email.

So my final request is :

SELECT tblPayeur.eMailComment AS MemoField, tblPayeur.eMail, tblPayeur.PaiementImediat, UCase([tblPayeur].[civilite] & " " & [tblPayeur].[Prenom] & " " & [tblPayeur].[Nom]) AS PayeurLong, UCase([tblPayeur].[zip] & " " & [tblPayeur].[ville]) AS PayeurLocalite, tblPayeur.civilite AS PayeurCivilite, tblPayeur.Prenom AS PayeurPrenom, tblPayeur.Nom AS PayeurNom, [tblPayeur].[Prenom] & " " & [tblPayeur].[Nom] AS Payeur, UCase([tblPayeur].[Adresse]) AS PayeurAdresse, tblPayeur.ville AS PayeurVille, tblPayeur.zip AS PayeurZip
FROM tblPayeur WHERE idPayeur
IN (SELECT DISTINCT tblPayeur.idPayeur
FROM (tblEleve INNER JOIN tblPayeur ON tblEleve.idPayeur = tblPayeur.idPayeur) INNER JOIN tblAEditer ON tblEleve.idEleve = tblAEditer.idELeve
WHERE tblEleve.aEditer=True)
 
Last edited:

Users who are viewing this thread

Top Bottom