R
Robert Gillard
(Using Access 2003 and Outlook 2003)
I need to email some data from a form to be sent via Outlook. I have found a
module on the Microsoft site that does this ok. However part of the
information i need to email is in the form of a hyperlink. (I have sent up a
separate hyperlink field in the relating access table and given it a "Text
To Display" short name as opposed to the actual full http address)
On the Access form the hyperlink behaves as expected i.e. you see just the
Text To Display short name (in blue) and when you click on it takes you to
the correct web page.
However when you open Outlook and the data is moved over, the hyperlink
reverts to its full http address. Does anyone know how to get just the short
name to appear in the email. I detail below the module I use for the above
process (apart from the above irritation the rest works very well.)
Also when I open up Outlook mail it automatically puts my "signature" at the
bottom, at the moment when Access opens Outlook and moves the data over no
signature is on the email, has anybody else got the same issue. (although I
appreciate you can still add it manually before you send the email.)
If anybody can help with either of the above issues I would be most grateful
Bob
Option Explicit
Sub sbSendMessage(Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
On Error GoTo ErrorMsgs
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message. Substitute your names here
' your names here.
Set objOutlookRecip = .Recipients.Add([Forms]![BAU
Reports]![subreports]![Recipiant])
objOutlookRecip.Type = olTo
' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add([Forms]![BAU
Reports]![subreports]![Copy reply to])
' [Forms]![BAU Reports]![subreports]![Copy reply to] & "", "",
Forms![BAU Reports]![subreports]![Report name], Forms![BAU Reports]![em
header] & vbCrLf & vbCrLf & Forms![BAU Reports]![subreports]![Report Main
body] & vbCrLf & Forms![BAU Reports]![subreports]![Report body 2] & vbCrLf &
Forms![BAU Reports]![em footer] & vbCrLf & vbCrLf & vbCrLf & Forms![BAU
Reports]![signature], True, ""
objOutlookRecip.Type = olCC
' Set the Subject, Body, and Importance of the message.
.Subject = Forms![BAU Reports]![subreports]![Report name]
.Body = ([Forms]![BAU Reports]![em header] & vbCrLf & vbCrLf &
Forms![BAU Reports]![subreports]![Report Main body] & vbCrLf & Forms![BAU
Reports]![subreports]![Hlink] & vbCrLf & Forms![BAU Reports]![em footer] &
vbCrLf & vbCrLf & vbCrLf & Forms![BAU Reports]![signature] & vbCrLf &
vbCrLf)
.Importance = olImportanceHigh 'High importance
' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Display
'.Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
Set objOutlookRecip = Nothing
Set objOutlookAttach = Nothing
Exit Sub
ErrorMsgs:
If Err.Number = "287" Then
MsgBox "You clicked No to the Outlook security warning. " & _
"Rerun the procedure and click Yes to access e-mail " & _
"addresses to send your message. For more information, " & _
"see the document at http://www.microsoft.com/office" & _
"/previous/outlook/downloads/security.asp. "
Else
MsgBox Err.Number & " " & Err.Description
End If
End Sub
I need to email some data from a form to be sent via Outlook. I have found a
module on the Microsoft site that does this ok. However part of the
information i need to email is in the form of a hyperlink. (I have sent up a
separate hyperlink field in the relating access table and given it a "Text
To Display" short name as opposed to the actual full http address)
On the Access form the hyperlink behaves as expected i.e. you see just the
Text To Display short name (in blue) and when you click on it takes you to
the correct web page.
However when you open Outlook and the data is moved over, the hyperlink
reverts to its full http address. Does anyone know how to get just the short
name to appear in the email. I detail below the module I use for the above
process (apart from the above irritation the rest works very well.)
Also when I open up Outlook mail it automatically puts my "signature" at the
bottom, at the moment when Access opens Outlook and moves the data over no
signature is on the email, has anybody else got the same issue. (although I
appreciate you can still add it manually before you send the email.)
If anybody can help with either of the above issues I would be most grateful
Bob
Option Explicit
Sub sbSendMessage(Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
On Error GoTo ErrorMsgs
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message. Substitute your names here
' your names here.
Set objOutlookRecip = .Recipients.Add([Forms]![BAU
Reports]![subreports]![Recipiant])
objOutlookRecip.Type = olTo
' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add([Forms]![BAU
Reports]![subreports]![Copy reply to])
' [Forms]![BAU Reports]![subreports]![Copy reply to] & "", "",
Forms![BAU Reports]![subreports]![Report name], Forms![BAU Reports]![em
header] & vbCrLf & vbCrLf & Forms![BAU Reports]![subreports]![Report Main
body] & vbCrLf & Forms![BAU Reports]![subreports]![Report body 2] & vbCrLf &
Forms![BAU Reports]![em footer] & vbCrLf & vbCrLf & vbCrLf & Forms![BAU
Reports]![signature], True, ""
objOutlookRecip.Type = olCC
' Set the Subject, Body, and Importance of the message.
.Subject = Forms![BAU Reports]![subreports]![Report name]
.Body = ([Forms]![BAU Reports]![em header] & vbCrLf & vbCrLf &
Forms![BAU Reports]![subreports]![Report Main body] & vbCrLf & Forms![BAU
Reports]![subreports]![Hlink] & vbCrLf & Forms![BAU Reports]![em footer] &
vbCrLf & vbCrLf & vbCrLf & Forms![BAU Reports]![signature] & vbCrLf &
vbCrLf)
.Importance = olImportanceHigh 'High importance
' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Display
'.Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
Set objOutlookRecip = Nothing
Set objOutlookAttach = Nothing
Exit Sub
ErrorMsgs:
If Err.Number = "287" Then
MsgBox "You clicked No to the Outlook security warning. " & _
"Rerun the procedure and click Yes to access e-mail " & _
"addresses to send your message. For more information, " & _
"see the document at http://www.microsoft.com/office" & _
"/previous/outlook/downloads/security.asp. "
Else
MsgBox Err.Number & " " & Err.Description
End If
End Sub