Send Report by email (1 Viewer)

A

Arti

Guest
I don't know if this is possible, but I want to try to send a report by email by clicking a command button on a form. My problem is that the name of the report is determined by the value of another variable in the form. The form has a pull-down menu of names called "Assigned to:" and I want the button to send the report that has the same name as the value of "Assigned to:" to the person who's name is "Assigned to:". Is there a way to program a command button to have these variables and look them up from the form that the button is on?
 

Neal

Registered User.
Local time
Today, 09:04
Joined
Feb 17, 2000
Messages
116
Is your mail client Outlook? I think I know how you could do that if you use Outlook.
 
A

Arti

Guest
yes, I am using Outlook...
 

Hoa Le

New member
Local time
Today, 09:04
Joined
May 8, 2000
Messages
7
Create a form with a button cmdSend and a textbox named txtRecipient. Next, behind the OnClick event of the button, paste this code:

'-----------------------------
Private Sub cmdSend_Click()

Dim strRecipient As String

On Error GoTo cmdSend_Click_Err


strRecipient = Me.txtRecipient

DoCmd.SendObject , "Attachment here!", "Format here!", strRecipient, "", "", "Subject heading here!", "Your message here!", True, ""

cmdSend_Click_Exit:
Exit Sub

cmdSend_Click_Err:
MsgBox Error$
Resume cmdSend_Click_Exit

End Sub
'--------------------------------

Enter a name in the textbox and click the button to send your e-mail to that name.

Good luck.
 

Mick3911

Registered User.
Local time
Today, 09:04
Joined
Jul 31, 2018
Messages
40
Hi, I appreciate that this thread is a few years old but it has worked great for me. I have tried to send e-mails to more then one e-mail address using this VBA code by inserting [txtReceipient1] [txtReceipient2] and so on but it is not working for me.

Can someone point me in the right direction to rectify this.

Many thanks
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:04
Joined
Sep 21, 2011
Messages
14,253
You would concatenate each email address with a semi colon ';' so that the strRecipient would look like "test@test.co.uk;test2@test2.co.uk"

FWIW it does not matter if the string ends with a ';', it still sends OK, so just set up a loop.
 

Users who are viewing this thread

Top Bottom