Send Email from Form Problem

A

Andy Roberts

I have a form with a txt box (txtClientRepEmail) which holds an email
address and I have a cmd buttonwhich creates an email using outlook using
the following code:-

Private Sub cmdSendEmail_Click()
Dim Email As String
Dim ref As String
Dim origin As String
Dim destination As String
Dim Notes As String

Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem

Email = Me!txtClientRepEmail

Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

With objEmail
.To = Email
.Display 'sends the email in Outlook. Change to DISPLAY if you want to
be able to
'modify or see what you have created before sending the email
End With

objOutlook.Quit
Set objEmail = Nothing

End Sub

The code breaks on the "Email = Me!txtClientRepEmail" line and I can't
understand why and as a separate issue, in the message created the
receipients address line is displayed as :

(e-mail address removed)#mailto:[email protected]# and not just
(e-mail address removed)
--
Regards

Andy
___________
Andy Roberts
Win XP Pro
Access 2007
 
A

Andy Roberts

Ok, I've figured whyI'm getting the error, but don't know how to fix it. The
form is a continuous form with the email field hidden. The error occurs
when the cmd button at the end of a record with no email address is clicked.
If there is an email address it works.

1. How do I deal with clicking thebutton when there is no email address in
the field (i.e. it is blank)
2. I thought of dealing with this by hiding the the cmd button if the txt
box was clear using the following code on the Form OnLoad event:

Private Sub Form_Load()

If Me.txtClientRepEmail = Null Then
Me.cmdSendEmail.Visible = False
Else
Me.cmdSendEmail.Visible = True
End If

End Sub

But this seems to achieve nothing.

As a separate issue, but related, could I get a "tooltip" to appear showing
the email address when Ihover over the cmd button?

--
Regards

Andy
___________
Andy Roberts
Win XP Pro
Access 2007
 
C

Christopher Robin

1) Easiest thing to do is check for the null/blank. Add this code to your On
Click event:

If IsNull(Me.txtClientRepEmail) Then
MsgBox("Send a nice message here")
else
'send your email here

2) enter some text in the "ControlTip Text" property for the
txtClientRepEmail text box. This is located under "Other" properties.
 
A

Andy Roberts

Thanks Chris

This works great

However, the controltext suggestion just shows whatever I put in the
proprty. What I want to do is show each individual email address as a
control tip (i.e. each one will be different) and either show no tip or a
set message if no email address exits.

--
Regards

Andy
___________
Andy Roberts
Win XP Pro
Access 2007
 
C

Christopher Robin

Apprently you can set the control tip in code.

I.E.
me.txtControl.ControlTipText = "Something you want to see"

so you can use the On Control event and populate it with the data in your
control and format it as a hyperlink.
 
A

Andy Roberts

Chris

Certainly getting there. This kind of helps. If I set the form OnCurrent
event to...

Me.cmdSendEmail.ControlTipText = Me.txtClientRepEmail

....it works to a point, however when hovering over each cmd button it only
displays the email address as a control tip of the selected record. I'm
also still getting it displayed as
(e-mail address removed)#mailto:[email protected]# and not just
(e-mail address removed)
--
Regards

Andy
___________
Andy Roberts
Win XP Pro
Access 2007
 
C

Christopher Robin

Unfortunately, I don't have an exact answer for you. I'd try to set the Is
Hyperlink property to No, and the Display as Hyperlink doesn't seem to have
anything useful for not displaying it as a hyperlink. I'd also check to see
if there are any options for Me.txtClientRepEmail, like ToString or something
to remove the hyperlink.
 

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