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

Emailing from Access

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
What I want to do is the following:

I have a form with a bunch of fields however, there are two important ones which I will discuss in regard to my question. One of the fields is called 'assignedto' and the other is named 'subject'. The 'assignedto' field is a combobox where the user has the option of selecting, among other names, 'RYAN'. When selected, the form automatically tabs over to the next field 'subject' and gives the user the option of entering something...

What I want Access to do is automatically send an email to "***" when 'RYAN' is selected from the assignedto field. In this email I want Access to copy the contents of what was writen in the 'subject' field.

Is this possible? If so how?

Thanks,
Ryan.
 
Its easily possible. Just to clarify though do you want the e-mail to be sent to whomever is selected in the assignedto field or only when it is RYAN. And do you want it to automatically send the e-mail after the subject field is updated or do you want a command button that can be clicked to send the e-mail.
The following code is using the assumptions I made about your post.
1. E-Mail whomever is selected in the assignedto box.
2. Automatically send the e-mail after the subject field is updated.

Private Sub Subject_AfterUpdate()

Dim strTo As String
Dim strSubject As String

strTo = Forms("[Enter Your Form Name]")!assignedto
strSubject = Forms("[Enter Your Form Name]")!subject

DoCmd.SendObject acSendNoObject, , , strTo, , , "[Enter The Subject Of The E-Mail]", strSubject, False

End Sub

Make sure you fill in your form name, and the subject of the e-mail if you want one- if not delete out the subject I put in there.
Let me know how it goes. Good luck!
 
Thanks a lot. I appreaciate that.

There's 2 issues though.

a) I only want the email to send if RYAN is selected.

b) I don't see a place within the code that you created where I can write the email address that you are sending the mail to?

Thanks again,
Ryan.
 
This is where the E-Mail address is generated from...
strTo = Forms("[Enter Your Form Name]")!assignedto
I was assuming that "RYAN" was an example and that you would either use an SMTP address or an address that your MAPI service could source to an SMTP address.
To code so that it is only sent if RYAN is selected...

Private Sub Subject_AfterUpdate()

Dim strTo As String
Dim strSubject As String

strTo = Forms("[Enter Your Form Name]")!assignedto
strSubject = Forms("[Enter Your Form Name]")!subject

If strTo = "RYAN" Then
DoCmd.SendObject acSendNoObject, , , strTo, , , "[Enter The Subject Of The E-Mail]", strSubject, False
End If

End Sub
 
I tried that but the email still wouldn't send...here's the code that I'm using...what I am doing wrong?

Private Sub assignedto_AfterUpdate()
'sends an email to 8rd2@qlink.queensu.ca when RYAN is selected from the assingnedto field
Dim strTo As String
Dim strSubject As Subject

strTo = Forms("8rd2@qlink.queensu.ca")!AssignedTo
strSubject = Forms("8rd2@qlink.queensu.ca")!Subject

If Me!AssignedTo = RYAN Then
DoCmd.SendObject acSendNoObject, , , strTo, , , "You Have A New Task", strSubject, False
End If

End Sub
 
You had a couple of synax errors..

Private Sub assignedto_AfterUpdate()
'sends an email to 8rd2@qlink.queensu.ca when RYAN is selected from the assingnedto field
Dim strTo As String
Dim strSubject As Subject

strTo = "8rd2@qlink.queensu.ca"
strSubject = Forms("[Your Form Name]")!Subject

If Me!AssignedTo = "RYAN" Then
DoCmd.SendObject acSendNoObject, , , strTo, , , "You Have A New Task", strSubject, False
End If

End Sub

This is assuming that the actual name of your text boxes are Subject and AssignedTo.
 
I have just set up a database which when entering an e-mail address into the text field wanted to send. The way it works is you just click once on the email address and a message comes up (with the e-mail address in the TO: part of the e-mail message

if you try this then see what it does

DoCmd.SendObject acSendNoObject, , , txtemail

is you want a template for subject the try this

DoCmd.SendObject acSendNoObject, , , txtemail, , , "enter your text here"

make sure you use the comms. try this and see what happens.

to automatically send it i think you add either false or true. As i am not sure check the questions i have posted yesterday (only three have funny titles look for HRG)

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top