I have a bit of code creating a an email message with a couple of attachments from an access 97 db. It has been working OK. Now the runtime error mentioned appears at the following line:
Set objEmail = objOutlook.CreateItem(olMailItem)line.
I have enclosed the code below. Any ideas?
Private Sub cmdSend_Click()
Dim Email As String
'**create variables for Outlook
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Dim Attachments As Attachment
'**gathers information from your form. this sets the string variable to your fields
Email = Me!Email
'***creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
'MsgBox (docpath & Forms![frmProdSpecsDistribution]![frmProdSpecsDistributionNew].Form![DocumentCL]
'***creates and sends email
With objEmail
.To = Email
If Not IsNull([CL]) Then
.Attachments.Add (docpath & Forms![frmProdSpecsDistribution]![frmProdSpecsDistributionNew].Form![CL] & ".doc ") 'add attachment"
'MsgBox Forms![frmProdSpecsDistribution]![frmProdSpecsDistributionNew].Form![CLpdf]
.Attachments.Add (docpathpdf & Forms![frmProdSpecsDistribution]![frmProdSpecsDistributionNew].Form![CLpdf]) 'add attachment"
End If
If Not IsNull([LI]) Then
.Attachments.Add (docpath & Forms![frmProdSpecsDistribution]![frmProdSpecsDistributionNew].Form![LI] & ".doc ") 'add attachment"
End If
If Not IsNull([PI]) Then
.Attachments.Add (docpath & Forms![frmProdSpecsDistribution]![frmProdSpecsDistributionNew].Form![PI] & ".doc ") 'add attachment"
.Attachments.Add (docpathpdf & Forms![frmProdSpecsDistribution]![frmProdSpecsDistributionNew].Form![PIpdf]) 'add attachment"
End If
If Not IsNull([BOT]) Then
.Attachments.Add (docpath & Forms![frmProdSpecsDistribution]![frmProdSpecsDistributionNew].Form![BOT] & ".doc ") 'add attachment"
'MsgBox Forms![frmProdSpecsDistribution]![frmProdSpecsDistributionNew].Form![BOTpdf]
.Attachments.Add (docpathpdf & Forms![frmProdSpecsDistribution]![frmProdSpecsDistributionNew].Form![BOTpdf])
End If
If Not IsNull([FIT]) Then
.Attachments.Add (docpath & Forms![frmProdSpecsDistribution]![frmProdSpecsDistributionNew].Form![FIT] & ".doc ") 'add attachment"
.Attachments.Add (docpathpdf & Forms![frmProdSpecsDistribution]![frmProdSpecsDistributionNew].Form![FITpdf])
End If
.Display
End With
'**closes outlook
'objOutlook.Quit
Set objEmail = Nothing
Exit Sub
End Sub
Set objEmail = objOutlook.CreateItem(olMailItem)line.
I have enclosed the code below. Any ideas?
Private Sub cmdSend_Click()
Dim Email As String
'**create variables for Outlook
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Dim Attachments As Attachment
'**gathers information from your form. this sets the string variable to your fields
Email = Me!Email
'***creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
'MsgBox (docpath & Forms![frmProdSpecsDistribution]![frmProdSpecsDistributionNew].Form![DocumentCL]
'***creates and sends email
With objEmail
.To = Email
If Not IsNull([CL]) Then
.Attachments.Add (docpath & Forms![frmProdSpecsDistribution]![frmProdSpecsDistributionNew].Form![CL] & ".doc ") 'add attachment"
'MsgBox Forms![frmProdSpecsDistribution]![frmProdSpecsDistributionNew].Form![CLpdf]
.Attachments.Add (docpathpdf & Forms![frmProdSpecsDistribution]![frmProdSpecsDistributionNew].Form![CLpdf]) 'add attachment"
End If
If Not IsNull([LI]) Then
.Attachments.Add (docpath & Forms![frmProdSpecsDistribution]![frmProdSpecsDistributionNew].Form![LI] & ".doc ") 'add attachment"
End If
If Not IsNull([PI]) Then
.Attachments.Add (docpath & Forms![frmProdSpecsDistribution]![frmProdSpecsDistributionNew].Form![PI] & ".doc ") 'add attachment"
.Attachments.Add (docpathpdf & Forms![frmProdSpecsDistribution]![frmProdSpecsDistributionNew].Form![PIpdf]) 'add attachment"
End If
If Not IsNull([BOT]) Then
.Attachments.Add (docpath & Forms![frmProdSpecsDistribution]![frmProdSpecsDistributionNew].Form![BOT] & ".doc ") 'add attachment"
'MsgBox Forms![frmProdSpecsDistribution]![frmProdSpecsDistributionNew].Form![BOTpdf]
.Attachments.Add (docpathpdf & Forms![frmProdSpecsDistribution]![frmProdSpecsDistributionNew].Form![BOTpdf])
End If
If Not IsNull([FIT]) Then
.Attachments.Add (docpath & Forms![frmProdSpecsDistribution]![frmProdSpecsDistributionNew].Form![FIT] & ".doc ") 'add attachment"
.Attachments.Add (docpathpdf & Forms![frmProdSpecsDistribution]![frmProdSpecsDistributionNew].Form![FITpdf])
End If
.Display
End With
'**closes outlook
'objOutlook.Quit
Set objEmail = Nothing
Exit Sub
End Sub