Why does this not work?

callumwatson

Registered User.
Local time
Today, 08:13
Joined
Jun 22, 2001
Messages
22
I have written code for a command button which I want to use to compose an e-mail using an address from my form. The composer opens OK but I can't get the address to automatically appear in the message.

My code is a s follows: -

Private Sub E_mail_Click()

If Me.Dirty Then DoCmd.RunCommand acCmdSaveRecord
Command46.HyperlinkAddress = "mailto:" & Me![E-mail address]
ExitHere:
Exit Sub

I have tried to copy code from the sample CONTACT database that Office provides. Obviously have done this unsuccessfully. I would really appreciate any help that anyone could offer.
 
Try using the SendObject in place of Hyperlink Address. I think you will have much better luck with it. This should work for you:

DoCmd.SendObject , , , Me.[E-mail address], , , "OptionalSubjectLine", _
"OptionalMessageText", True

You can also pull the Subject and message text from the form if you would like. You just remove the quotes from the place holder and use me.[field name]. Post back if you have more questions about this.
 
Sorry to ask for more help.

I don't quite understand what you mean by 'Try using the SendObject in place of Hyperlink Address'.

I have looked at HELP but I still don't know how to apply the code in my situation. I am a new VB programmer and I would really appreciate some elaboration on my problem.

Also, I posted the wrong code before. I posted

Command46.HyperlinkAddress = "mailto:" & Me![E-mail address]

Instead of

E_mail.HyperlinkAddress = "mailto:" & Me![E-mail address]
 
Just put the code I posted in place of the E_mail.HyperlinkAddress = "mailto:" & Me![E-mail address]

The Docmd.SendObject should open your default mail program and then place the email address that you have in [E-mail address] in the To: field of your mail program.

I wrote it using your field name so it should plug right into your Sub. Make sure that you comment out your HyperlinkAddress when trying this out. Just put a ' in front of the line like this:

' E_mail.HyperlinkAddress = "mailto:" & Me![E-mail address]

Post back if you have more questions.

It should end up looking something like this:

Code:
Private Sub E_mail_Click()

If Me.Dirty Then DoCmd.RunCommand acCmdSaveRecord

' Comment the line below out
' Command46.HyperlinkAddress = "mailto:" & Me![E-mail address]

DoCmd.SendObject , , , Me.[E-mail address], , , "OptionalSubjectLine", _
"OptionalMessageText", True


ExitHere:


Exit Sub

[This message has been edited by Talismanic (edited 07-10-2001).]
 
It was as easy as that!

Thanks for your perseverance.

Much appreciated, Cal.
 
I assume that means you have it working now.

Here are a few more things to know:

1. To send the mail without user intervention just change the True to False.

2. To remove the "Optional" text I put in there just remove everyting between the ,'s.

3. You can use fields from the form in place of the "Optional" text by removing the quotes and putting a Me.[field name] in its place.

There are a lot more arguments that you can use but that should get you started.
 

Users who are viewing this thread

Back
Top Bottom