Hi
I have a form "frm Recs Tracked Jobs" in which there is a subform "tbl Additional Files subform" in datasheet format. I wish to run a routine (see below) to create an e-mail using info in the chosen record in the subform by clicking on a field in the subform.
When I assign this code to the "Click" event on the field in the subform, I get the following error message when I try to run it:
"A problem occured while Microsoft Access was communicating with the OLE server or ActiveX Control. Close the OLE server and restart it outside of Microsoft Access. Then try the original operation again in Microsoft Access."
The code does work if I run it manually from the VBA Module window after choosing the relevant record in the subform.
Any advice would be greatly appreciated.
Thanks
AL
I have a form "frm Recs Tracked Jobs" in which there is a subform "tbl Additional Files subform" in datasheet format. I wish to run a routine (see below) to create an e-mail using info in the chosen record in the subform by clicking on a field in the subform.
Code:
Private Sub Miscemail()
On Error GoTo nofiles
Dim appOutlook As Outlook.Application
Dim ItmNewEmail As Outlook.MailItem
Dim TemplateName As String
Dim strBody As String
Dim attname As String
Dim attnameAP As String
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70 'save record before proceeding
TemplateName = "i:\ia manual\e-mail templates\drtemp1.oft"
attname = Forms![frm recs tracked jobs]![tbl additional files subform]![FullName]
Set appOutlook = New Outlook.Application
Rem Set ItmNewEmail = appOutlook.CreateItem(olMailItem)
Set ItmNewEmail = appOutlook.CreateItemFromTemplate(TemplateName)
strBody = strBody & Chr(13) & Chr(10)
strBody = strBody & Forms![frm recs tracked jobs]![HOSFirstName] & Chr(13) & Chr(13)
strBody = strBody & "Regards"
With ItmNewEmail
.To = Forms("frm recs tracked jobs").Controls("empname").Value
.CC = Forms("frm recs tracked jobs").Controls("Contact").Value & ";Brona Slevin"
.Subject = Forms("frm recs tracked jobs").Controls("job").Value & " IA Inspection - Final Report"
.Body = strBody
.BodyFormat = olFormatHTML
.Attachments.Add attname
Rem .Attachments.Add attnameAP
.ReadReceiptRequested = True
.Display
End With
exit_01:
Exit Sub
nofiles:
MsgBox "Final Report and/or Signed Action Plan is not present", vbInformation, "Cannot create e-mail"
GoTo exit_01
End Sub
When I assign this code to the "Click" event on the field in the subform, I get the following error message when I try to run it:
"A problem occured while Microsoft Access was communicating with the OLE server or ActiveX Control. Close the OLE server and restart it outside of Microsoft Access. Then try the original operation again in Microsoft Access."
The code does work if I run it manually from the VBA Module window after choosing the relevant record in the subform.
Any advice would be greatly appreciated.
Thanks
AL