UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Code won't run from subform    
 
   
PortyAL
post Aug 16 2007, 03:42 AM
Post#1



Posts: 33
Joined: 14-September 06



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.
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
Go to the top of the page
 
thenelson
post Aug 16 2007, 04:24 AM
Post#2



Posts: 470
Joined: 25-July 05
From: Flagstaff AZ, USA


You can change all the OLE code to the one line:
DoCmd.SendObject(ObjectType, ObjectName, OutputFormat, To, Cc, Bcc, Subject, MessageText, EditMessage, TemplateFile)
lso change
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
to
DoCmd.Save acForm, "YourFormName"
or
RunCommand acCmdSaveRecord
All of the acMenuVer70 commands have newer counterparts.
Go to the top of the page
 
freakazeud
post Aug 16 2007, 08:14 AM
Post#3


UtterAccess VIP
Posts: 31,413
Joined: 23-September 04
From: NC, USA


Hi,
Oassume you are using automation for a reason e.g. (wanting to send properly formatted HTML emails).
I've run a small test with my own procedure and it worked as expected. Can attach a small sample app (zip it and keep it under 500kb). Have you tried to run Compact and Repair? Have you tried to import all db objects into a blank new application? BTW...you might want to set the email format first and then assign the body appropriately e.g.:

...
.BodyFormat = olFormatHTML
.HTMLBody = "<HTML><BODY>" & YourContent & "</BODY></HTML>"
...

HTH
Good luck
Go to the top of the page
 
PortyAL
post Aug 17 2007, 05:55 AM
Post#4



Posts: 33
Joined: 14-September 06



Thanks for your advice.
tried the code in another sub form and it worked OK.
Othen recreated the original subform and everything now works fine.
Not sure what the problem was.
AL
Go to the top of the page
 
freakazeud
post Aug 17 2007, 08:56 AM
Post#5


UtterAccess VIP
Posts: 31,413
Joined: 23-September 04
From: NC, USA


You're welcome.
Glad you got it sorted out.
Good luck on future projects!
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    24th June 2019 - 05:15 PM