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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send email button in form does not work 1

Status
Not open for further replies.

shaunacol

Programmer
Jan 29, 2001
226
GB
I have used this info to write some code behind a button on a form which sends an email. However, my set up is slightly different as I am using frm_Email with a subform Frm_EmailCOntent. This is the only way I can think to do this as I need to get access to the email address from tbl_client and want to save the email info into tbl_comms. So from my Frm_Client I open up Frm_email and I can see it is pulling in fields ClientID and Email1 from tbl_client nicely and the subform from tbl_comms is set to data entry waiting for the new information. Once I enter some comms info I run the code below behind my button which resides in Frm_EmailCOntent but it has a problem identifying the Email1 - I think this is because it is in Frm_Email. Have I referenced it incorrectly?

Private Sub SendEmail_Click()

Dim strEmail, strsubject, 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

[highlight #FCE94F]strEmail = [frm_email]![Email1][/highlight]strsubject = Me.Summary
strBody = Me.Notes

'***creates and sends email
With objEmail
.To = strEmail
.subject = strsubject
.Body = strBody
.Send
End With


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

Exit Sub

End Sub
 
Perhaps this ?
strEmail = Forms!frm_Email!Email1

or this ?
strEmail = Me.Parent.Form!Email1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The first one works - many thanks. However, now I am getting this error "runtime error 2147467259 (80004005)Outlook does not recognise one or more names" and it highlights .Send

Anyone got any ideas?
 
Thanks for info, I think it is because my outlook is based on my hotmail account (for testing). I will try the code on the users machines next week as thier outlook is set up prperly and hopefully it will work. Tnanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top