Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending automatic emails - Error message

Status
Not open for further replies.

dbar10

Programmer
Dec 5, 2008
196
US
thread702-396121

I am wanting to send automatic emails from Access 2003 when I cancel a schedule.

I have found the above thread to be very helpful in creation of the code. But, I am having an error and I am afraid that I my be off base with it. I have been working on this a long time and need help.

When I run this I am getting the following error:
Run-time error '438':
Project doesn't support this property or method.

This is my code:

Option Compare Database

Private Sub CommandClose_Click()

Dim strEmail, strBody As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem

'**creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

'**************************************************************
'*create string with email address

strEmail = Forms![SchedSearchList]![UserLoginsfrm].textemail

strBody = txtTDate & Chr(13) & Chr(13)
strBody = strBody & "Staff" & "," & Chr(13) & Chr(13)
strBody = strBody & "The following schedule has been cancelled:" & Chr(13) & Chr(13) & Chr(13)
strBody = strBody & "Client: " & " " & Forms!SchedSearchList![SchedClientTable Qry subform].FullName & Chr(13)
strBody = strBody & "Date: " & Forms!SchedSearchList!ScheduleClientfrm.TextDate & Chr(13)
strBody = strBody & "Time: " & " " & SchedSearchList!ScheduleClientfrm.TextStart & " " & SchedSearchList!ScheduleClientfrm.TextEnd & Chr(13)
strBody = strBody & "Worker: " & Forms!SchedSearchList!ScheduleClientfrm.Workername & Chr(13) & Chr(13)
strBody = strBody & "Reason: " & CancelReasonfrm.CancelReas & Chr(13)
strBody = strBody & "Notes: " & [CancelNotes Querysfrm].Notes & Chr(13) & Chr(13)
strBody = strBody & "Thank you," & Chr(13) & Chr(13)
strBody = strBody & "CareEase"

'***creates and sends email
With objEmail
.To = strEmail
.Subject = "Schedule Cancellation"
.Body = strBody
.Send
End With


Set objEmail = Nothing
'****closes Outlook. remove if you do not want to close Outlook
objOutlook.Quit

Exit Sub

DoCmd.Close acForm, CancelReasonfrm, acSaveYes
DoCmd.Close acForm, [CancelNotes Queryfrm], acSaveYes


End Sub

Debug is highlighting this line:

strEmail = Forms![SchedSearchList]![UserLoginsfrm].textemail

Can anyone help put me on track? Thanks

 
How are ya dbar10 . . .

Which line is highlited by the debugger?

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thanks TheAceman1,
The following line is highlighted, but I suspect that I have bigger problems because now when I run this my application is locking up and won't even let me close without going to task manager and ending task.

strEmail = Forms![SchedSearchList]![UserLoginsfrm].textemail

What do you think?
 
dbar10 . . .

The 1st thing I see is incorrect subform referencing!
Code:
[blue]   strEmail = Forms!SchedSearchList!UserLoginsfrm[purple][b].Form[/b][/purple].textemail[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
AceMan1, Thanks once again for your help once I worked throught te syntax errors, it works great. I only have one more question.

If Outlook isn't open when this runs I get this message:

Run-time error '287':
Application-defined or object defined error.

Debug is Highlighting:

.Send ( at the end)

Can this be fixed so that if Outlook isn't opened it will open it?

And the my DoCmd.Close statements at the end are not working. What's up with that.

Here is my code as it is know:

Option Compare Database

Private Sub CommandClose_Click()

Dim strEmail, strBody As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem

'**creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

'**************************************************************
'*create string with email address

strEmail = Forms![SchedSearchList]![UserLoginsfrm].Form.ToEmail

strBody = txtTDate & Chr(13) & Chr(13)
strBody = strBody & "Staff" & "," & Chr(13) & Chr(13)
strBody = strBody & "The following schedule has been cancelled:" & Chr(13) & Chr(13) & Chr(13)
strBody = strBody & "Client: " & " " & Forms!SchedSearchList![SchedClientTable Qry subform].Form.FullName & Chr(13)
strBody = strBody & "Date: " & Forms!SchedSearchList!ScheduleClientfrm.Form.TextDate & Chr(13)
strBody = strBody & "Time: " & " " & Forms!SchedSearchList!ScheduleClientfrm.Form.TextStart & " " & Forms!SchedSearchList!ScheduleClientfrm.Form.TextEnd & Chr(13)
strBody = strBody & "Worker: " & Forms!SchedSearchList!ScheduleClientfrm.Form.Workername & Chr(13) & Chr(13)
strBody = strBody & "Reason: " & Forms!CancelReasonfrm.Form.CancelReas & Chr(13)
strBody = strBody & "Notes: " & Forms![CancelNotes Querysfrm].Form.Notes & Chr(13) & Chr(13) & Chr(13) & Chr(13) & Chr(13) & Chr(13)
strBody = strBody & "Thank you," & Chr(13) & Chr(13)
strBody = strBody & "CareEase" & Chr(13) & Chr(13)
strBody = strBody & "THIS IS AN AUTOMATED E-MAIL"
'***creates and sends email
With objEmail
.To = strEmail
.Subject = "Schedule Cancellation"
.Body = strBody
.Send
End With


Set objEmail = Nothing
'****closes Outlook. remove if you do not want to close Outlook
'objOutlook.Quit

Exit Sub

DoCmd.Close acForm, Forms!CancelReasonfrm, acSaveYes
DoCmd.Close acForm, Forms![CancelNotes Queryfrm], acSaveYes


End Sub

Thank you very much
 
You meant this ?
DoCmd.Close acForm, "CancelReasonfrm", acSaveYes
DoCmd.Close acForm, "CancelNotes Queryfrm", acSaveYes

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yes, duh. Thanks. What about opening Outlook if it isn't already opened when this runs?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top