Results 1 to 7 of 7
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    email body from txt file

    In using DoCmd.SendObj to send emails, I'm accustom to simply supplying a text string as the body text. Are there any methods available where one can specify a text (txt) file instead of a string?

    I could simply read a text file line-by-line and build a string with line breaks (vbnewline) inserted so as to retain the simple formtting, but I thought perhaps I'd just missed something in my search.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Bill,

    I have not done similar for years.
    I suggest you look at TextStream and ReadAll method.

  3. #3
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    If you could have a file to read from you could just as easily use a table field for body texts?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    The online documentation doesn't indicate if the resulting text string retains the simple line formatting. I.e., if one were to ReadAll and then Write the string to a file whether the resulting txt file would retain the same line-by-line formatting.

    My need is to ReadAll, Replace(InString, "LINK:", MyURL) and then use the InString and the body text of an email. Where the input txt file is a user email prototype.

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Yes, that was my initial thought. However, the user in the current case will fair better using a simple prototype text file (Notepad) where they place the "LINK:" keyword among the text and the app will replace that with a URL taken from the app's driving form.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Bill,
    I just tried this:
    Code:
    Sub GetTextInTXT()
          Dim oFSO As FileSystemObject
          Dim tsin As TextStream, RequiredText As String
          Const ForReading = 1, ForWriting = 2, ForAppending = 3
    10    Set oFSO = CreateObject("Scripting.FileSystemObject")
    20     Set tsin = oFSO.OpenTextFile("C:\Users\jp\Documents\Documents_Lenovo\Documents\BillBenson_OnActivate.txt", ForReading)
          Dim X As String
    
    30    X = tsin.ReadAll
    40    RequiredText = X 
    50    Debug.Print RequiredText
    End Sub
    Format retained on the attached file.
    Attached Files Attached Files

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    I mimicked your test with total success.
    Thanks,
    Bill

Please reply to this thread with any new information or opinions.

Similar Threads

  1. email a form in the body of an email?
    By rudyebiii in forum Forms
    Replies: 2
    Last Post: 10-08-2016, 07:58 AM
  2. Replies: 3
    Last Post: 05-18-2015, 11:24 AM
  3. Email report as body of email (RTF)
    By TheDeceived in forum Programming
    Replies: 4
    Last Post: 07-23-2012, 06:39 AM
  4. Email report as body of email
    By chrish20202 in forum Programming
    Replies: 6
    Last Post: 01-15-2012, 07:23 PM
  5. Email from report to Email body
    By Ehmke66 in forum Programming
    Replies: 4
    Last Post: 01-03-2011, 01:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums