Hi
Im using “sendmessage” in a module to send an e-mail with an attachment.
The code Im using is copied from HERE
The code in full
I have 2 problems that need solving.
Firstly.
Where the code calls for the recipients name ie
Set objOutlookRecip = .Recipients.Add("Nancy Davolio")
I want it to look at a combo box on a form that has the full email address in it.
How would that be written? I'v tried a number of diferrent ways, all failed
Also for the AttachmentPath
I have a button on the form, in the on click event to run the code in the module it has
=sbSendMessage()This will send a email without an attachment, if I put the path in the () ie
=sbSendMessage(C:\Documents and Settings\Desktop\This is an Automation test with Microsoft Outlook.msg) It will attach the file and send, but I need the path to be got from a text box on the form as this has a browse function to add a path to it, (can't have users editing the properties to add emails.)
Thanks in advance
B
Im using “sendmessage” in a module to send an e-mail with an attachment.
The code Im using is copied from HERE
The code in full
Code:
[FONT=Courier New][FONT=Courier New]Sub sbSendMessage(Optional AttachmentPath)[/FONT]
[FONT=Courier New] Dim objOutlook As Outlook.Application[/FONT]
[FONT=Courier New] Dim objOutlookMsg As Outlook.MailItem[/FONT]
[FONT=Courier New] Dim objOutlookRecip As Outlook.Recipient[/FONT]
[FONT=Courier New] Dim objOutlookAttach As Outlook.Attachment[/FONT]
[FONT=Courier New] On Error GoTo ErrorMsgs[/FONT]
[FONT=Courier New] ' Create the Outlook session.[/FONT]
[FONT=Courier New] Set objOutlook = CreateObject("Outlook.Application")[/FONT]
[FONT=Courier New] ' Create the message.[/FONT]
[FONT=Courier New] Set objOutlookMsg = objOutlook.CreateItem(olMailItem)[/FONT]
[FONT=Courier New] With objOutlookMsg[/FONT]
[FONT=Courier New] ' Add the To recipient(s) to the message. Substitute[/FONT]
[FONT=Courier New] ' your names here.[/FONT]
[FONT=Courier New] Set objOutlookRecip = .Recipients.Add("Nancy Davolio")[/FONT]
[FONT=Courier New] objOutlookRecip.Type = olTo[/FONT]
[FONT=Courier New] ' Add the CC recipient(s) to the message.[/FONT]
[FONT=Courier New] Set objOutlookRecip = .Recipients.Add("Andrew Fuller")[/FONT]
[FONT=Courier New] objOutlookRecip.Type = olCC[/FONT]
[FONT=Courier New] ' Set the Subject, Body, and Importance of the message.[/FONT]
[FONT=Courier New] .Subject = "This is an Automation test with Microsoft Outlook"[/FONT]
[FONT=Courier New] .Body = "Last test." & vbCrLf & vbCrLf[/FONT]
[FONT=Courier New] .Importance = olImportanceHigh 'High importance[/FONT]
[FONT=Courier New] ' Add attachments to the message.[/FONT]
[FONT=Courier New] If Not IsMissing(AttachmentPath) Then[/FONT]
[FONT=Courier New] Set objOutlookAttach = .Attachments.Add(AttachmentPath)[/FONT]
[FONT=Courier New] End If[/FONT]
[FONT=Courier New] ' Resolve each Recipient's name.[/FONT]
[FONT=Courier New] For Each objOutlookRecip In .Recipients[/FONT]
[FONT=Courier New] If Not objOutlookRecip.Resolve Then[/FONT]
[FONT=Courier New] objOutlookMsg.Display[/FONT]
[FONT=Courier New] End If[/FONT]
[FONT=Courier New] Next[/FONT]
[FONT=Courier New] .Send[/FONT]
[FONT=Courier New] End With[/FONT]
[FONT=Courier New] Set objOutlookMsg = Nothing[/FONT]
[FONT=Courier New] Set objOutlook = Nothing[/FONT]
[FONT=Courier New] Set objOutlookRecip = Nothing[/FONT]
[FONT=Courier New] Set objOutlookAttach = Nothing[/FONT]
[FONT=Courier New]ErrorMsgs:[/FONT]
[FONT=Courier New] If Err.Number = "287" Then[/FONT]
[FONT=Courier New] MsgBox "You clicked No to the Outlook security warning. " & _[/FONT]
[FONT=Courier New] "Rerun the procedure and click Yes to access e-mail" & _[/FONT]
[FONT=Courier New] "addresses to send your message. For more information" & _[/FONT]
[FONT=Courier New] "see the document at http://www.microsoft.com/office" & _[/FONT]
[FONT=Courier New] "/previous/outlook/downloads/security.asp. " "[/FONT]
[FONT=Courier New] Else[/FONT]
[FONT=Courier New] Msgbox Err.Number, Err.Description[/FONT]
[FONT=Courier New] End If[/FONT]
[FONT=Courier New]End Sub[/FONT]
[/FONT]
I have 2 problems that need solving.
Firstly.
Where the code calls for the recipients name ie
Set objOutlookRecip = .Recipients.Add("Nancy Davolio")
I want it to look at a combo box on a form that has the full email address in it.
How would that be written? I'v tried a number of diferrent ways, all failed

Also for the AttachmentPath
I have a button on the form, in the on click event to run the code in the module it has
=sbSendMessage()This will send a email without an attachment, if I put the path in the () ie
=sbSendMessage(C:\Documents and Settings\Desktop\This is an Automation test with Microsoft Outlook.msg) It will attach the file and send, but I need the path to be got from a text box on the form as this has a browse function to add a path to it, (can't have users editing the properties to add emails.)
Thanks in advance
B