Hi,
I have a db that creates an email from templates (the template changes depending on a selection). Each template contains key words that are replaced by data input by a user through the db using an InputBox. It generally works fine but I want to avoid using specific InputBoxes where not required (ie when there is no corresponding key word in the specific template). Here's relevant parts of my code:
Code Tags Added by UG
Please use Code Tags when posting VBA Code
Please feel free to Remove this Comment
Although the email is raised OK, it still doesn't work as I need. In the above extract, the InputBox is called up when it shouldn't. I'm guessing there's something wrong with how I'm calling the .Find propert. Any help would be very welcome.
PS, I'm not a 'real' programmer, so please be gentle
Andy
I have a db that creates an email from templates (the template changes depending on a selection). Each template contains key words that are replaced by data input by a user through the db using an InputBox. It generally works fine but I want to avoid using specific InputBoxes where not required (ie when there is no corresponding key word in the specific template). Here's relevant parts of my code:
Code Tags Added by UG
Please use Code Tags when posting VBA Code
Please feel free to Remove this Comment
Please use Code Tags when posting VBA Code
To make your code easier to read, please use the Code tag around your code, this will ensure that any code you copy and paste from your DB retains it's formatting making it easier to read and follow; Firstly click on the Code button, that's the button at the top of the posting window with the...
www.access-programmers.co.uk
Code:
Dim strFind As String
Dim strNew As String
Dim strInput As String
Dim strMsg As String
Dim sbjtCoy As String
Set MyMail = myOutlook.CreateItemFromTemplate(TmplFile("template") & "\telephone call.oft") 'this is just one of the templates called- only one shown for simplicity
With MyMail
With .Content.Find
strFind = "company"
.Text = "company"
.Execute 'FindText:=strFind, Format:=False, Forward:=False
If .Found = True Then
strMsg = "Enter caller's company."
strInput = InputBox(Prompt:=strMsg, Title:="Leave blank if not known/relevant")
sbjtCoy = strInput 'used later in the module
strInput = "from " & strInput
End If
End With
.HTMLBody = Replace(MyMail.HTMLBody, strFind, strInput)
Although the email is raised OK, it still doesn't work as I need. In the above extract, the InputBox is called up when it shouldn't. I'm guessing there's something wrong with how I'm calling the .Find propert. Any help would be very welcome.
PS, I'm not a 'real' programmer, so please be gentle
Andy
Last edited by a moderator: