Sending email from a form

thudson

Old Programmer
Local time
Today, 16:49
Joined
Apr 29, 2011
Messages
68
I am trying to design a form to send an email, which I based on a Helpdesk database code I found on the web.
I am not at all confident at writing code, so I may need some help.
This is the code so far:
Code:
Private Sub Command12_Click()

Dim stWhere As String
Dim varTo As Variant
Dim stText As String
Dim Sent As Variant
Dim stSubject As String
Dim stWho As String
Dim strSQL As String
Dim errLoop As Error

stWho = Me.cboFullName
stWhere = "tblBT_Emails.strEmail =" & "" & stWho & ""
varTo = DLookup("[EMail]", "tblBT_Emails", stWhere)
stSubject = DLookup("[Subject]", "BT_Emails", "[Subject]" = "&""Forms!BT_Emails!Subject")
Sent = Me.txtDateSent
stText = Me.txtMessage

DoCmd.SendObject , , acFormatTXT, varTo, , , stSubject, stText, -1

End Sub
The error checking stops with the Me.cboFullName line.
The table called Emails has the following fields:
EID, Email, FullName, Subject, Merssage, DateSent, fkName

another table.
The forms record source is the Emails table.


What I want to acheive is to choose the email address and the fullname, I think you should be able to link these fields, but I don't know how, then fill in the rest of the fields and send the email using SendObject.


Can anyone assist me in sorting this out?


Ultimately I would like to send emails to all users, but first things first, I ned to get this working.
 
You might find more control over what you are doing if you look into CDO (Collaboration Data Objects).

https://msdn.microsoft.com/en-us/library/ms978636.aspx

The above link sends you to the top of documentation tree for CDO operation. I have used it in the past.

You can also use Outlook if you have such a setup in your system.

https://support.microsoft.com/en-us...send-a-microsoft-outlook-message-using-access

This link would get you started down that particular path.

Either way, you would have some programming in VBA to consider but you would also have incredible flexibility in what you sent.
 
Your code for sending the e-mail is fine, the problem is that you are not getting the data correctly from the form. There is no need to use a CDO object.
 

Users who are viewing this thread

Back
Top Bottom