Sending email from a form (1 Viewer)

thudson

Old Programmer
Local time
Today, 01:23
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.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 19:23
Joined
Feb 28, 2001
Messages
27,147
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.
 

RogerCooper

Registered User.
Local time
Yesterday, 17:23
Joined
Jul 30, 2014
Messages
284
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

Top Bottom