I have spent the last week working on coding a way to send an e-mail from Access with MS Outlook. I finally got it all figured out and have it running perfect for Outlook 2003. Turns out, the 3 people that will be using the database are running Office 2000 and my code doesn't work on their machines. Any advice on fixing this, here is the code I am using. I was thinking I might have to sit at one of their desks and redo all the programming, and testing.
Private Sub cmdE_mail_Click()
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim rsConnect As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strBody As String
Dim strSQL As String
Dim strSubject As String
Set rsConnect = CurrentProject.Connection
DoCmd.SetWarnings False
'sets the body of the e-mail
Set rs = New ADODB.Recordset
strSQL = "SELECT [phone], [acs type], [order id], [cable pair], [prov type] FROM [Faxination1];"
rs.Open strSQL, rsConnect, adOpenDynamic, adLockOptimistic
rs.MoveFirst
strBody = rs.GetString(adClipString)
'Sets the e-mail subject line
[wire center].SetFocus
strSubject = "Comp" & " " & [wire center].Text & " "
[fax time].SetFocus
strSubject = strSubject & [fax time].Text
'Opens Outlook and creates a new E-mail
Set objOutlook = CreateObject("outlook.application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
Set objOutlookRecip = .Recipients.Add("Local Prov")
objOutlookRecip.Type = olTo
.Subject = strSubject
.Body = strBody
.Importance = olImportanceNormal
'Use .send to send the message right away
'Use .display to edit the message before sending it
.Display
End With
Set objOutlook = Nothing
Set objOutlookMsg = Nothing
Set objOutlookRecip = Nothing
Set rs = Nothing
End Sub
Private Sub cmdE_mail_Click()
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim rsConnect As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strBody As String
Dim strSQL As String
Dim strSubject As String
Set rsConnect = CurrentProject.Connection
DoCmd.SetWarnings False
'sets the body of the e-mail
Set rs = New ADODB.Recordset
strSQL = "SELECT [phone], [acs type], [order id], [cable pair], [prov type] FROM [Faxination1];"
rs.Open strSQL, rsConnect, adOpenDynamic, adLockOptimistic
rs.MoveFirst
strBody = rs.GetString(adClipString)
'Sets the e-mail subject line
[wire center].SetFocus
strSubject = "Comp" & " " & [wire center].Text & " "
[fax time].SetFocus
strSubject = strSubject & [fax time].Text
'Opens Outlook and creates a new E-mail
Set objOutlook = CreateObject("outlook.application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
Set objOutlookRecip = .Recipients.Add("Local Prov")
objOutlookRecip.Type = olTo
.Subject = strSubject
.Body = strBody
.Importance = olImportanceNormal
'Use .send to send the message right away
'Use .display to edit the message before sending it
.Display
End With
Set objOutlook = Nothing
Set objOutlookMsg = Nothing
Set objOutlookRecip = Nothing
Set rs = Nothing
End Sub