Solved Using CDO, selecting the text file template via a textbox on a form (1 Viewer)

mousemat

Completely Self Taught
Local time
Today, 16:34
Joined
Nov 25, 2002
Messages
233
Hi

I have been using the CDO method to send emails to people using text templates and placeholders, which work really well.

What I'd like to do is determine at the time of sending the emails, which template to use. Currently the text template is written within the module itself.

Code:
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
'Open the file for reading
Set f = fso.OpenTextFile("c:\AccessTextFiles\letterTest.txt", ForReading)

'The ReadAll method reads the entire file into the variable BodyText
BodyText = f.ReadAll
'Close the file

Is it possible to use a textbox from the form that creates the recordset to set the Text Template
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:34
Joined
Oct 29, 2018
Messages
21,478
You could try using a variable. For example:
Code:
Set f = fso.OpenTextFile(TextFilePath, ForReading)
 

mousemat

Completely Self Taught
Local time
Today, 16:34
Joined
Nov 25, 2002
Messages
233
Hi DBGuy

How would I reference the textbox from the form?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:34
Joined
Oct 29, 2018
Messages
21,478
Hi DBGuy

How would I reference the textbox from the form?
You could use a Form reference. For example:
Code:
Dim TextFilePath As String
TextFilePath = Forms!FormName.TextboxName
Hope that helps...
 

mousemat

Completely Self Taught
Local time
Today, 16:34
Joined
Nov 25, 2002
Messages
233
Excellent. It's been a long Christmas period. All working as required.
 

Users who are viewing this thread

Top Bottom