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...