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

E-mail from addresses within a table

Status
Not open for further replies.

RichyT

Technical User
Jun 11, 2002
20
GB
Is there a way that I can set up an e-mail that will pick out addresses from a table, (all or a selection)?

Cheers

Rich
 
Rich, if you're using Lotus Notes, I have this module:

Code:
Sub EMailUsingLotusNotes(strSubject As String, strFile As String, _
    strAddress As String, Optional strCopyTo As String, Optional strBody As String)
On Error GoTo Err_EMailUsingLotusNotes

    ' Sends simple email using Lotus Notes
    ' Does NOT Require Reference to Lotus Notes Object Library
    ' does not save to users sent box
    
    Dim LotusSes As Object  ' Lotus Notes Session
    Dim LotusDbs As Object ' Lotus Notes Database
    Dim LotusDoc As Object ' Lotus Notes Document
    Dim LotusItem As Object ' Lotus Notes RichTextFile
    Dim AttachedFile As Object ' Attachment
    
    Set LotusSes = CreateObject("Notes.NotesSession")
    Set LotusDbs = LotusSes.GETDATABASE("", "")
    LotusDbs.OPENMAIL
    Set LotusDoc = LotusDbs.CREATEDOCUMENT()
    Set LotusItem = LotusDoc.CREATERICHTEXTITEM("Attachment")
    Set AttachedFile = LotusItem.EMBEDOBJECT(1454, "", strFile, "Attachment")
    LotusDoc.CREATERICHTEXTITEM ("Attachment")
    With LotusDoc
        .Subject = strSubject
        .Body = strBody
        .SendTo = strAddress
        .CopyTo = strCopyTo
        .SAVEMESSAGEONSEND = True
        .Send False
    End With
    
ExitHere:
    Set LotusSes = Nothing
    Set LotusDbs = Nothing
    Set LotusDoc = Nothing
    Exit Sub
    
Err_EMailUsingLotusNotes:
    MsgBox "Error: Email was not sent to " & strAddress, _
        vbOKOnly, "Error Sending Email!"
    Resume ExitHere
    
End Sub

When I use this sub, I usually open a recordset containing the values I want to email, including the email address and then set up a string like this:

strAddress = rst!Email

Call EmailUsingLotusNotes(strSubject,strFile,strAddress)

I hope this is of some use to you!
Kelly
 
Unfortunately I'm using outlook, but thanks anyway.
 
This is a code string I came up with to extract e-mail addresses and information from a table then send that information as html to the required recipient.... I use Outlook at work as well with an Access 97 Application on an NT 4.0 intranet system.


Private Sub btnCommitOrders_Click()
On Error GoTo Err_btnCommitOrders_Click

' txtMessageOutPut displays system status and errors for the user at the bottom of the form.
txtMessageOutPut.Visible = True
txtMessageOutPut = "YOU HAVE STARTED THE PRINT AND MAIL FUNCTIONS FOR TAD ORDERS. STANDBY FOR FURTHER INSTRUCTIONS..."

' First I test the Field tblPrintBuffer.mbrFullName for a valid entry. If it is Null (empty) then it displays an _
error message, other wise it will run the commands below the Else statement...
If IsNull(mbrFullName) Then
txtMessageOutPut.Visible = True
txtMessageOutPut = "THERE ARE NO ORDERS TO BE SENT IN THE BUFFER AT THIS TIME. HAVE A GREAT NAVY DAY!"
Else

' APPEND ALL ORDERS TO ARCHIVE TABLE
stDocName = "qryUpdateArchiveFiles"
DoCmd.OpenQuery stDocName, acNormal, acEdit

' PRINT COMMAND(S)
stDocName = "FILE COPY"
DoCmd.OpenReport stDocName, acNormal

stDocName = "ORIGINAL"
DoCmd.OpenReport stDocName, acNormal

' NOTIFY MRMS OF RECENT ORDERS CREATED _
This is the first of the E-Mail commands that I use, below this entire code string I _
will step through the process for you...

stDocName = "TAD No Cost Orders Listing"
DoCmd.SendObject acSendReport, stDocName, acFormatHTML, _
"someone@sima.navy.mil", , , "NO COST TAD ORDERS FOR MRMS", _
"Here are the latest orders created. Thank You SIMA Training Department.", _
False, True

Do
' BEGIN EMAIL NOTIFICATIONS TO THE RESPECTIVE TPO'S
DoCmd.SendObject , acSendNoObject, acFormatHTML, tpoShopEmail, , , _
"NO COST TAD ORDERS FOR " & mbrRate & " " & mbrFullName, _
"THE NO COST TAD ORDERS FOR SERVICE MEMBER " & mbrRate & " " & mbrFullName & _
" WILL BE READY FOR PICK UP BY C.O.B. THE FOLLOWING BUSINESS DAY. ANY QUESTIONS PLEASE CONTACT THE DUTY PERSON AT 6-2907 OR 6-2910. THANK YOU, FROM THE SIMA TRAINING DEPARTMENT. THE ORDERS FOR SERVICE MEMBER ARE: " & _
schName & " " & schAddress & ".", False, True

' DELETE EACH ITERATION THIS IS A REQUIRED STEP
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

Loop Until IsNull(tpoShopEmail)
' THIS IS THE COMPLETION MESSAGE THAT WILL BE DISPLAYED UPON COMPLETION
txtMessageOutPut.Visible = True
txtMessageOutPut = "EMAIL HAS BEEN SENT AND ORDERS ARE PRINTED. THANK YOU FOR YOUR SUPPORT."

End If
' SET FOCUS ON THE EXIT BUTTON
btnExit.SetFocus

Exit_btnCommitOrders_Click:
Exit Sub

Err_btnCommitOrders_Click:
MsgBox Err.Description
Resume Exit_btnCommitOrders_Click

End Sub

Code String definition / breakdown...

stDocName = "TAD No Cost Orders Listing" Identify the element I am sending from

DoCmd.SendObject acSendReport, This is the command to use the mail server and default client, Outlook in my case.
stDocName, acFormatHTML Pre-defining the e-mail format to HTML, _

"someone@sima.navy.mil" Identify a hard coded e-mail address, , ,
"NO COST TAD ORDERS FOR MRMS"This is the Subject Line..., _
"Here are the latest orders created. Thank You SIMA Training Department." This is in the main body of the E-Mail, _
False, True

This is a little bit different and actually answers your question... the breakdown is as follows...

DoCmd.SendObject, Tells system to use default e-mail client
acSendNoObject, There is no attachment
acFormatHTML, Use HTML format for the E-Mail
tpoShopEmail, , , _This is a field on my form fed from a table, in this field is a valid E-Mail address, this is appended to the To: line in Outlook
"NO COST TAD ORDERS FOR " & mbrRate & " " & mbrFullName, _ Subject line, I am hard coding the first part the & = field names and spaces that are appended as well.

"THE NO COST TAD ORDERS FOR SERVICE MEMBER " & mbrRate & " " & mbrFullName & _
" WILL BE READY FOR PICK UP BY C.O.B. THE FOLLOWING BUSINESS DAY. ANY QUESTIONS PLEASE CONTACT THE DUTY PERSON AT 6-2907 OR 6-2910. THANK YOU, FROM THE SIMA TRAINING DEPARTMENT. THE ORDERS FOR SERVICE MEMBER ARE: " & _
schName & " " & schAddress & ".", This entire string is the message with field names from my table via the form
False, True This statement, sends the E-Mail without opening the message for editing, if you want to edit before you send then change True to False.

I hope this helps!!!

GSM1(SW)McDonald, US Navy...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top