Discussion Locked

Making Access get e-mail from field

0 helpful
11 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have several client databases where I could really use the ability to send an e-mail that reads the e-mail address out of a field. I would love to know how to do this in Access 2000 and 97. It is easy to send an e-mail and specifiy the address or just leave the e-mail blank. I want the program to grab the e-mail address itself depending on which record is selected.

I assume this would take some VBA work. I would appreciate it if anyone could point me to some sample code for doing it. If you have some other way to do it don't hesitate to post either.

11 replies

by sankulpune

Hello Kevin,

Its not an answer but a request for more info.

I am not really clear as to what you want to achieve.

A little more detailed explaination would help.

SanKul

by kevin at alexander group

My goal is to add a button to a record that sends an e-mail with the address pulled from a field in the record.

This button might be used to send a report, or just to open an e-mail with the user's e-mail already entered.

I know how to use SendObject, but it only allows me to hard code an address. It does not allow me to specifiy a field to draw the address from.

Make sense?

by mbarker734

In your table creat a field call it email_address.

In the datatype for the field select hyperlink.

all email addresses in this field need to be preceeded by mailto:

so a address in the field will appear as:

mailto:kevin@alexandergroup.com

click on the field and your email program will open with the email address already input.

Hope this helps,

Mark

by mbarker734

Or if you really would rather use a command button, place the following code in the button on click event.

Dim stDoWhat As String

stDoWhat = "~"
[Text1].SetFocus
SendKeys (stDoWhat)

change the [Text1] to a text box field name that you bound to your hyperlink field in the table. Your email program will open with the address already entered.

Good Luck,

Mark

by mmdkj.family

The email table field will need to be the Hyperlink data type. When adding a mailto: link use the email address type of link from the bottom of the left side (Places bar) of the hyperlink dialog box. Make all your hyperlinks preceed with a "mailto:".

Then on your form the email field needs to be on the form and create a command button possibly labeled "Send Email." Use the On Click event and create a macro that goes to the email control and then send the key stroke "enter" key. such as:

action=GoToControl, Control Name=email
action=SendKeys, KeyStrokes={enter}

Save and try it out. For the current record it will go to the email control and then send the enter key stroke which does the same thing as clicking on the hyperlink in thecontrol.

When adding mailto: hyperlinks in the email field you can also include auto subject line text if desired as follows:

mailto:joe@test.com?subject=newsletter

by mfoster

I have done this on several other Databases that I have created. The field can be a standard Text field (Make sure you give yourself plenty of room, Some email names can be quite long). In the OnClick event of your button use the following code:
Private Sub SendConf_AfterUpdate()
Dim stDocName As String
' Name of report if any that you want to send
stDocName = "rptConfirmation"
' Check field for valid name (might want to customize this for your needs)
If EmailName <> " " Then

RunCommand acCmdSaveRecord
'The last parameter (True) will cause the email to pop up for review and additional entry.
DoCmd.SendObject acReport, stDocName, acFormatRTF, Me![EmailName],Me![EmailCC] ,Me![EmailBC] , "Subject ", , True
End If

End Sub

Sorry for the indentation.

Hope this helps.

This discussion is closed to new replies.