View Full Version : Form to open outlook create email
QuietRiot
10-13-2007, 09:19 AM
Ok, so im using this code that I've used in the past only for excel. I think it works but i cant test it cause im at home and outlook message saying server cant be found. So thats a good sign that the code works. What i want is on the form I have a button you click it it then takes the items on the form and creates an email and exits the db. now in front of you have the email which you can further edit before sending.
The part Im having trouble with is getting form items into the email. Example my form contains a subject textbox, an issue description textbox and i have a drop down with clients.
how do i get it so subject = subject in email, issue description = body of email and also client should be in the beginning of body.
heres the code:
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = bla
.CC = blabla
.subject = subject
.Body = bodytext
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
Have a look at this simple emailing database.
QuietRiot
10-13-2007, 03:17 PM
Thats great, but will this automatically send it or pop up the outlook screen so the user can add more stuff to the email if they wanted.
heres the code:
Dim subject As String, Body As String
Subject = [Text0]
Body = [Text1] & chr$(13) & [Text2]
DoCmd.SendObject , , , Me.EmailAddress, , , subject, Body, False
End sub
To have it open the email for amendment remove the False (or change it to True) from the end of the Docmd statement.
QuietRiot
10-15-2007, 06:13 AM
when it opens it comes up has a plain txt outlook. this doesn't allow me to paste screen shots or anything.
how can I turn the format of the outlook window to HTML.
I tried this and it doesn't seem to work:
DoCmd.SendObject , , acFormatHTML, emailaddy, , , Subject, Body, True
DarkSprout
10-25-2007, 06:41 AM
Code Mudule:
Option Explicit
Option Compare Database
' Place Type into PublicVariables Module
Public Type NewEmail
To As String
CC As String
Subject As String
Body As String
Email_as_HTML As Boolean
High_Importance As Boolean
View_Before_Send As Boolean
Attachment1_File As String
Attachment2_File As String
Attachment3_File As String
Attachment4_File As String
Attachment5_File As String
From As String
End Type
'---------------------------------------------------------------------------------------'
' Procedure : Create_Email '
' DateTime : 24/10/2007 '
' Author : Darryl S. Drury '
' Purpose : Global Function to Send Email from the System '
' Ref : Requires Outlook 10+ Reference '
'---------------------------------------------------------------------------------------'
Public Function Create_Email(GenEmail As NewEmail) As Boolean
' TOUSE:
' boolTest = Create_Email(GenEmail) ' Will return a boolean value / True - if no error
' or Call Create_Email(GenEmail) ' no value returned
Dim MailApplication As Outlook.Application
Dim Email As Outlook.MailItem
Const DBLINE = vbCrLf & vbCrLf
On Error GoTo Create_Email_Error
Set MailApplication = New Outlook.Application
Set Email = MailApplication.CreateItem(olMailItem)
Email.To = GenEmail.To 'Set the To box on the email
Email.CC = GenEmail.CC 'Set the CC box on the email
Email.SentOnBehalfOfName = Nz(GenEmail.From, "")
'Process Email Attachments
If GenEmail.Attachment1_File <> "" Then
Email.Attachments.Add (GenEmail.Attachment1_File)
End If
If GenEmail.Attachment2_File <> "" Then
Email.Attachments.Add (GenEmail.Attachment2_File)
End If
If GenEmail.Attachment3_File <> "" Then
Email.Attachments.Add (GenEmail.Attachment3_File)
End If
If GenEmail.Attachment4_File <> "" Then
Email.Attachments.Add (GenEmail.Attachment4_File)
End If
If GenEmail.Attachment5_File <> "" Then
Email.Attachments.Add (GenEmail.Attachment5_File)
End If
Email.Subject = GenEmail.Subject 'Set the Subject
If GenEmail.High_Importance = False Then 'Start Set the importance of the email
Email.Importance = olImportanceNormal
Else
Email.Importance = olImportanceHigh
End If 'End Set the Importance of the email
If GenEmail.Email_as_HTML = True Then 'Start Email Body Preference
Email.BodyFormat = olFormatHTML
Email.HTMLBody = GenEmail.Body
Else
Email.BodyFormat = olFormatRichText
Email.Body = GenEmail.Body
End If 'End Email Body Preference
'Display / Send the generated email.
If GenEmail.View_Before_Send = True Then
Email.Display
Else
On Error Resume Next
Email.Send
If Err.Number = 287 Then
Err.Clear
Call MsgBox("Please Allow Email To Me Sent!" & DBLINE & "Inportant Email", vbExclamation, "Allow Email")
Email.Send
If Err.Number = 287 Then
Err.Clear
Call MsgBox("Please Allow Email To Me Sent!" & DBLINE & "Inportant Email", vbExclamation, "Allow Email")
Email.Send
If Err.Number = 287 Then
Call MsgBox("Email Not Sent!" & DBLINE & "This Was An Inportant Email", vbExclamation, "Email Error...")
Exit Function
End If
End If
End If
End If
'All done
Create_Email = (Err.Number = 0)
On Error GoTo 0
Exit Function
Create_Email_Error:
MsgBox Err.Description, 64, "Email Creation ~ Error#" & Err.Number
Create_Email = False
End Function
Public Sub TestSub ()
Dim GenEmail As NewEmail
GenEmail.To = "DarkSprout@abc.com"
GenEmail.From = ""
GenEmail.Body = "This will be your body text ~ you can use <b>HTML</b> should you wish."
GenEmail.Email_as_HTML = True ' False = Plain Text
GenEmail.Subject = "Test"
GenEmail.View_Before_Send = True
Select Case Create_Email(GenEmail) ' Will return True if Done
Case True
MsgBox "Email Created", 64, ""
Case Else
MsgBox "Email Creation Failed", 16, ""
End Select
End Sub
Put the above in a new Module mdl_CORE_Email
Use The TestSub to see now it works, delete TestSub when you're at one with it.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.