E-mail in Access: small problem

Willem!

Registered User.
Local time
Today, 16:42
Joined
Apr 18, 2006
Messages
50
Hi!

I want to make a button on my form which opens Outlook and places certain e-mail adresses at the right places. I have a small problem though. My current code is as follows:


Private Sub EmailButton_Click()

Dim strToWhom As String
Dim strToCCWhom As String
Dim strMsgBody As String
Dim strSubject As String

strSubject = "Your Subject goes here!"
strToWhom = Me.Emailadres
strToCCWhom = Me.Emaildres2
strMsgBody = "Your Body text goes here!"

DoCmd.SendObject , , , strToWhom, strToCCWhom, , strSubject, strMsgBody, True

End Sub


' Emailadres' and 'Emailadres2' are the names of the text boxes in which the adresses are.

When I click on the EmailButton Outlook pops-up and displays the right adresses, subject and so on at the right place.

However, if I do not send an email and when I closes Outlook, I get a run-time error.

I think I have to put something extra in the code, but I am not really sure what to put in it. Anyone a suggestion?

Cheers,
Willem
 
aah.. after a relaxing weekend i got an apifany, silly me, i knew the answer to my own problem but that i did not know friday...

for the ones who are interested in the answer of my previous problem, you should implement an 'On Error' statement also. So the final code would be:

Private Sub Command56_Click()

On Error GoTo Err_Command56_Click

Dim strToWhom As String
Dim strToCCWhom As String
Dim strMsgBody As String
Dim strSubject As String

strSubject = "Your Subject goes here!"
strToWhom = Me.Emailadres
strToCCWhom = "Your email adres"
strMsgBody = "Your Body text goes here!"

DoCmd.SendObject , , , strToWhom, strToCCWhom, , strSubject, strMsgBody, True

Exit_Command56_Click:
Exit Sub

Err_Command56_Click:
MsgBox Err.Description
Resume Exit_Command56_Click

End Sub

I am learning everyday! :)

Willem
 
Willem thanks for the code,

A little more.....I need to send my report in snapshot format thru the email.
My database (MDE) is set with Shiftbypass key and hide access option. Means when program runs, no menus are displayed except access. In this situation I think I should place a command button onto my Report Master Form and select the desired report, attach with email (Outlook) in snapshot format and send

How can I do this ?

With kind regards,

Ashfaque
 
Hi Ashfaque,

I don't think I could really be helpfull to you, the button-stuff sounds great, if I where you I should look some more on and around the internet. (via eMule you could download several access-VBA books in pdf-format, works for me).

Cheers,
Willem!
 

Users who are viewing this thread

Back
Top Bottom