Email from a field on a form.

G

Guest

Hi

I was wondering if it is possible to email from a field on a form. I
currently have a contact form with the contact’s email (work email and home
email) for each record. I would like to click on the email field and be able
to send an email. The only thing I would like to populate in outlook the
email address for that record.

Thank you

Cordell
 
A

Allen Browne

Use SendObject.

This example assumes a Text Box named Email:

If IsNull(Me.Email) Then
Beep
Else
DoCmd.SendObject acSendNoObject, , , Me.Email, , , , , True
End If
 
G

Guest

Hi Cordell,

Yes, it is possible. Here is one method that uses a command button named
"cmdSendEmail" and a text box on the form named "txtEmail":


Private Sub cmdSendEmail_Click()
On Error GoTo ProcError

DoCmd.SendObject To:=Nz(Me.txtEmail, "")

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure cmdSendEmail_Click..."
Resume ExitProc
End Sub


If you later decide that you want to include a subject and/or text in the
body, you can modify the procedure somewhat. For example:


Private Sub cmdSendEmail_Click()
On Error GoTo ProcError

Dim strBody As String

' Use + signs, not ampersands to join the elements. This way,
' if the field named Body is null, the entire thing will be null, and
' then the Nz function will convert it to a zero length string.

strBody = Nz((vbCrLf + vbCrLf + _
"___________________________________________" _
+ vbCrLf + vbCrLf + "You wrote:" + vbCrLf + vbCrLf + Me.Body), "")


DoCmd.SendObject _
To:=Nz(Me.txtEmail, ""), _
Subject:="Re: " & Nz(Me.txtSubject, ""), _
MessageText:=strBody

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure cmdSendEmail_Click..."
Resume ExitProc
End Sub


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 
G

Guest

Thank you very much for quick response. That was exactly what I was looking
for but if I decide not to email the person I get an error. Is there anyway
to fix the error.

Error

Run-time 2501
The sendobject action was cancelled.

Cordell
 
G

Guest

G

Guest

Thanks Guys For the help

Cordell

Tom Wickerath said:
Hi Cordell,

Yes, it is possible. Here is one method that uses a command button named
"cmdSendEmail" and a text box on the form named "txtEmail":


Private Sub cmdSendEmail_Click()
On Error GoTo ProcError

DoCmd.SendObject To:=Nz(Me.txtEmail, "")

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure cmdSendEmail_Click..."
Resume ExitProc
End Sub


If you later decide that you want to include a subject and/or text in the
body, you can modify the procedure somewhat. For example:


Private Sub cmdSendEmail_Click()
On Error GoTo ProcError

Dim strBody As String

' Use + signs, not ampersands to join the elements. This way,
' if the field named Body is null, the entire thing will be null, and
' then the Nz function will convert it to a zero length string.

strBody = Nz((vbCrLf + vbCrLf + _
"___________________________________________" _
+ vbCrLf + vbCrLf + "You wrote:" + vbCrLf + vbCrLf + Me.Body), "")


DoCmd.SendObject _
To:=Nz(Me.txtEmail, ""), _
Subject:="Re: " & Nz(Me.txtSubject, ""), _
MessageText:=strBody

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure cmdSendEmail_Click..."
Resume ExitProc
End Sub


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top