I have been using the code below in access 2003 for around 18 months to send an e-mail I am now testing this using 2010 and I am getting an
"application defined or object defined error" at the line highlighted in red
could someone tell me where I am going wrong please
Regards
Paul
"application defined or object defined error" at the line highlighted in red
Code:
Public Function cmdPrint_Click(view As Integer)
'On Error GoTo cmdPrint_Click_Error
Dim wnd As Long
Dim uClickYes As Long
Dim Res As Long
Dim strFilename As String
Dim strNewName As String
Dim strHead As String
Dim strSub As String
Dim DDate As String
Dim strfrp As String
Dim strContact As String
strFilename = "Some Company"
strSub = " "
strOrderID = Forms![frmOrdersMain]![txtOrderNo]
strOrderBy = Forms![frmOrdersMain]![txtOrderedBy]
D = Format(Now, "dd")
m = Format(Now, "mm")
Y = Format(Now, "yy")
DDate = D & "-" & m & "-" & Y
strHead = strFilename & " Order No_" & strOrderID & " Dated " & DDate
strNewName = DLookup("[Path]", _
"tblFilePaths", "[Type] = 'E-Mail'") & strFilename & "_Order No_" & strOrderID & "_" & DDate & ".pdf"
Forms![frmOrdersMain]![txtFileName] = strFilename & "_Order No_" & strOrderID & "_" & DDate & ".pdf"
Call SaveReportAsPDF("rptOrderB", strNewName)
Dim patha, pathT, pathC, pathH, pathS, CustMail, KamMail As String
SuppMail1 = Forms!frmOrdersMain!txtEMail
SuppMail2 = Forms!frmOrdersMain!txtEMail2
patha = strNewName
strSub = "Dear Sir/Madam " & _
vbCrLf & vbCrLf & _
"Please find attached a PDF document relating to our Order No " & strOrderID & _
vbCrLf & vbCrLf & _
"Kind regards" & _
vbCrLf & vbCrLf & _
strOrderBy
pathT = SuppMail1
pathC = SuppMail2
'pathC = DLookup("[E-mail]", "tblreps", _
"repid = " & Forms!frmPriceInputScreen!ExternalRep)
If IsNull(pathT) And IsNull(pathC) = True Then
MsgBox "You Must Select A Supplier Contact To EMail The Order To", vbInformation, "Email"
Exit Function
End If
pathH = strHead
pathS = strSub
Dim result As Integer
Dim displaymessage As Boolean
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment ' Create the Outlook session.
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message.
If Len(Nz(pathT)) > 0 Then
[b][red]Set objOutlookRecip = .Recipients.Add(pathT)[/red][/b]
objOutlookRecip.Type = olTo
End If
' Add the CC recipient(s) to the message.
If Len(Nz(pathC)) > 0 Then
'If pathC <> "" Then
Set objOutlookRecip = .Recipients.Add(pathC)
objOutlookRecip.Type = olCC
End If
' Set the "From" field
objOutlookMsg.SentOnBehalfOfName = ""
' Set the Subject, Body, and Importance of the message.
.Subject = (pathH)
.Body = (pathS)
.Importance = olImportanceHigh 'High importance
' Add attachments to the message.
'If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(patha)
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
.Display
End With
Set objOutlook = Nothing
On Error GoTo 0
Exit Function
cmdPrint_Click_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdPrint_Click of Module Email"
End Function
could someone tell me where I am going wrong please
Regards
Paul