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

Unwanted text in TO: line of e-mail created by Access

Status
Not open for further replies.

Pompie1999

Technical User
Jan 22, 2008
6
US
I’m creating my first Access database for a ‘Lending Library’ of management books our location uses. I need to send an e-mail from our library manager to each person who has had a book checked out for more than 90 days. I have a FORM in access that runs a QUERY showing who those individuals are and their e-mail address. I have modified code that I found on a forum to create an e-mail to each of those individuals. When I run the code, it does something unwanted with the TO: line in the e-mail. It takes the e-mail address from the form and populates the TO: line just as it should, but then it appends some unwanted text at the end. How can I get rid of the text that is appended?

The code is as follows:
=========================================
Option Compare Database
Option Explicit

Sub SendMessages(Optional AttachmentPath)

Dim MyDB As Database
Dim MyRS As Recordset
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim TheAddress As String

Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset("qryGT90Days")
MyRS.MoveFirst

' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")

Do Until MyRS.EOF
' Create the e-mail message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
TheAddress = MyRS!

With objOutlookMsg
' Add the To recipients to the e-mail message.
Set objOutlookRecip = .Recipients.Add(TheAddress)
objOutlookRecip.Type = olTo

' Set the Subject, the Body, and the Importance of the e-mail message.
.Subject = Forms!frmGT90Days!MediaTitle
.Body = "Our records show that you checked out the Subject Title more than 90 days ago and have not yet returned it. Please return the book as soon as possible. Thanks ."


.Importance = olImportanceHigh 'High importance

' Resolve the name of each Recipient.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Send
End With
MyRS.MoveNext
Loop
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
====================================================
The e-mail address that is created looks like:
John.Doe@MyCompany.com#[URL unfurl="true"]http://John.Doe@MyCompany.com#[/URL]

The portion that I don't want is everything after the first .com in the e-mail address.
 
It seems that your email address is a hyperlink field. You will need something on the lines of:

HyperlinkPart(NameOfFieldOrControl, acAddress)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top