PDA

View Full Version : Solved: Email subject line automatically inserted



junglej815
12-23-2008, 11:03 AM
Hello, Looking for some info/help. I am going to try and be as clear as I can with what I'm looking for.

What I currently have:
I have a word document with text boxes, checkboxes, and what not. A command button that acts as a "submit" button that when clicked on opens a new mail message in outlook with the word document attached. The "To" email address and "Subject" line are filled in automatically as well. The code for that is as follows:


Public Sub commandbutton1_click()
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
Set Doc = ActiveDocument
Doc.Save
With EmailItem
.Subject = "Content Conference Room Request"
.Body = "" & vbCrLf & _
"" & vbCrLf & _
""
.To = "facilitiesservicescenter@blank.com"
.Importance = olImportanceNormal 'Or olImprotanceHigh Or olImprotanceLow
.Attachments.Add Doc.FullName
.Display
End With
Application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
End Sub

What I'm looking to do if possible:
Is there a way to have the text that is entered in Textbox3 on the document be inserted into the subject line as well automatically when the "Submit button is clicked on? And how if so.

Thanks for any help.

Edit Lucas: VBA tags added to code.

fumei
12-23-2008, 11:27 AM
.Subject = ThisDocument.Textbox3.Text

if the textbox is an ActiveX textbox.

junglej815
12-23-2008, 12:26 PM
Ah, I knew I was gonna leave something out...yeah its an activeX textbox.

Thanks a lot Gerry. That did exactly what I was hoping for.

lucas
12-23-2008, 12:44 PM
Be sure to mark your thread solved using the thread tools at the top of the page.

junglej815
12-23-2008, 01:07 PM
Is it possible to do the same type of thing with a text form field? ( the grey shaded box)

lucas
12-23-2008, 02:13 PM
Right click on the textform when it is unprotected and select propterties. Look for the Bookmark name....ie Text1

.Subject = ThisDocument.FormFields("Text1").Result

fumei
12-23-2008, 02:18 PM
Of course. .Subject takes a string, so ANYTHING that passes it a string is valid.

.Subject = ActiveDocument.Formfields("name or index number").Result - IF the formfield is a text formfield.

A checkbox formfield .Result will = 0 or 1 (not True or False, or Checked Unchecked).

A dropdown .Result will return the string of the selected item.

In other words, if you had a dropdown formfield with "gerry", "bob", "yoda" as items, and "yoda" was selected, "yoda" would go into .Subject.

fumei
12-23-2008, 02:25 PM
Just as added possibility, you could use logic to extract longer text to put into .Subject from a dropdown.

Say you have a dropdown formfield (named "Names") with:

Gerry
Steve
Curly
Moe

Say Curly is selected.
Select Case ActiveDocument.Formfields("Names").Result
Case "Gerry"
.Subject = "Ho Hum, whatever"
Case "Steve"
.Subject = "smart...very smart"
Case "Curly"
.Subject = "get a haircut"
Case "Moe"
.Subject = "Vote for me!!!"
End Select

"get a haircut" would go into .Subject.

This of course could also be done for .To - for example.

lucas
12-23-2008, 03:14 PM
Great explaination as usual Gerry.

junglej815
01-06-2009, 09:08 AM
would it be possible to have the document emailed once the command button is clicked instead of having the mail message open first? or is that not possible?

or even when the command button is clicked and whether it emails the document right away or the person clicks "send" in the new mail message, that person recieves an email saying something like " its been recieved..." or is that a type of thing that would need to be done in outlook?

lucas
01-06-2009, 09:16 AM
Change this line:

.Display

to
.send

for the message just add this just above end sub


msgbox "The message has been sent"

junglej815
01-06-2009, 09:36 AM
Thanks...that works. Is that popup message box the only option for something like this in word in this situation?

lucas
01-06-2009, 09:55 AM
If you are looking for a return receipt I would scan the outlook forum.

junglej815
01-06-2009, 10:00 AM
yeah, thats what it is....and thats what I figured. thanks a lot for your help.