PDA

View Full Version : Solved: Email To Dropdown Bookmark



belly0fdesir
04-13-2007, 02:10 PM
I don't know why this isn't working... does anyone? the bolded part is where the problem is... "Dropdown7" is a dropdown on a form that the user is going to use to determine the recipient of the email. Am I totally off?



Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
Dim STRbookmark As Object
Set STRbookmark = ActiveDocument.Bookmarks("Dropdown7").Range '<---------- PROBLEM
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olmailitem)
Set Doc = ActiveDocument
'Doc.Save
With EmailItem
.Subject = "Document Request"
.Body = "Attached you will find my Document Request." & vbCrLf & _
"Please let me know if you have any questions at all" & vbCrLf & _
"Thank you"
.To = STRbookmark '<---------- PROBLEM
.Importance = olImportanceHigh
.Attachments.Add Doc.FullName
.Send
End With

Application.ScreenUpdating = True

Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing

mdmackillop
04-13-2007, 03:11 PM
Try
Dim STRbookmark As String
STRbookmark = ActiveDocument.Bookmarks("Dropdown7").Range

belly0fdesir
04-13-2007, 04:01 PM
Try
Dim STRbookmark As String
STRbookmark = ActiveDocument.Bookmarks("Dropdown7").Range

Yeah, it still gives the same error:

Run-time error '-2147467259 (80004005)':
Outlook does not recognize one or more names.

I think it has something to do with it being a dropdown, because if define another bookmark that is NOT a dropdown, it will send to the reciepient, but not from the dropdown. Does that make sense? And when I debug, it shows "[]" when I scroll over STRbookmark.

mdmackillop
04-13-2007, 04:20 PM
Can you post your document (suitably sanitised)

belly0fdesir
04-13-2007, 04:38 PM
Okay, I think I've upped it right. The names in dropdown are names on our exchange server here at work.

mdmackillop
04-13-2007, 05:04 PM
Dim STRbookmark As String
Dim ffDrop

Set ffDrop = ActiveDocument.FormFields("DropDown7").DropDown
STRbookmark = ffDrop.ListEntries(ffDrop.Value).Name

belly0fdesir
04-13-2007, 05:17 PM
Works like a charm. Thank you so much! I'll be sure to use this method in my future projects :)

Again, thank you so much!

fumei
04-13-2007, 10:27 PM
Um...there is a difference between a string and a range.

I must also comment that you have the statement:

"You must choose a destination"...but you have nothing to back that up.

CommandButton1_Click will happily put: With EmailItem
.Subject = "Document Request"
.Body = "Attached you will find my Document Request." & vbCrLf & _
"Please let me know if you have any questions at all." & vbCrLf & _
"Thank you!"
.To = STRbookmark
.Importance = olImportanceHighwith STRBookmark = to.....

"You must choose a destination"

STRbookmark = ffDrop.ListEntries(ffDrop.Value).Name can be "You must chose a destination".

There is no error trapping to actually make sure that .Name is one of the other two items.

Further, "DropDown7" is not good naming practice. Without looking at the code...do YOU know what DropDown7 is for?

Finally, you do not have to use Bookmark at all. It is a formfield. Yes, formfields are also bookmarks, but they have their own collection, and it is better to use it directly. With EmailItem
.Subject = "Document Request"
.Body = "Attached you will find my Document Request." & vbCrLf & _
"Please let me know if you have any questions at all." & vbCrLf & _
"Thank you!"
.To = ActiveDocument.Formfields("Dropdown7").Result
.Importance = olImportanceHigh
.Attachments.Add Doc.FullName
.Send
End With

Formfield.Result will get the text. You don't really need a variable, but if you insist:Dim STRbookmark As String
STRbookmark = ActiveDocument.Formfields("Dropdown7").Result

mdmackillop
04-14-2007, 01:48 AM
So much for *#*% Word Help.

:bow:

fumei
04-14-2007, 05:43 PM
Now, now.

Ok folks. That's it. I am outta here for a week. Darn though. It looks like I will be hiking in the rain. Oh well. I have the gear for it. Bummer though, I have borrowed a fairly decent size telescope, and I wanted some dark (clear!) skies.

belly0fdesir
04-16-2007, 05:06 PM
@fumei: thank you very much for that! :D I'll be sure to use result in the future. And you're right, I am a bit too lazy in my naming. This particular form has 100 fields, but I should have at least better named the ones relevant to the code. Thank you for that tip. And the result thing. And thanks for taking the time to explain all of that. It's greatly appreciated. I looked at your art. Very nice stuff... I like to draw too (http://belly0fdesire.deviantart.com/gallery/)...