Is it possible to send e-mails from a form?
Imagine this, I have a form with some data into and I would like to press a
button and send that data directly to a e-mail address. Can I do it? HOW?
Best Regards,
Marco
Look up
DoCmd.SendObject acForm, ,
Sends the form details to e mail but I don't think you really want to do
this because the form info does not very clever.
Its much better to send an e mail based on a report from your form. The
report should be based on the same query as you form which means it will be
displaying the same data as the form when you press send e mail.
To send an e mail, I have generated a send e mail button using the wizard.
(Report Operation\Send Mail)The code for sending the report will be generated
as below.
Private Sub Command142_Click()
On Error GoTo Err_Command142_Click
Dim stDocName As String
stDocName = "YourReportName" 'the report you selected to be sent
DoCmd.SendObject acReport, stDocName
Exit_Command142_Click:
Exit Sub
Err_Command142_Click:
MsgBox Err.Description
Resume Exit_Command142_Click
End Sub
You can modify this code to send specifically to recipients names taken from
controls etc.
My code looks like this
Private Sub SendEMailButton_Click()
On Error GoTo Err_SendEMailButton_Click
Dim stDocName As String
Dim StrTo As String
Dim StrSubject As String
Dim Pge As String
Dim stLinkCriteria As String
StrTo = DLookup("[E_Mail_Address]", "[Tbl_Contact]", "[Contact]='" &
Forms![frm_general_enquiries]![ContactCombo95] & "'")'looks up the name to
send to based on a control on the form being sent from
stDocName = "Rprt_Quote_By_E_Mail" 'The report I am sending (Contains
the same information as the form being viewed in real time.
DoCmd.SendObject acReport, stDocName, To:=StrTo, Subject:="Our Quotation
Ref " & Me.Reference_No 'Our Quotation ref is my tittle can also be based on
a control source if required
Exit_SendEMailButton_Click:
Exit Sub
Err_SendEMailButton_Click:
If StrTo = "" Then 'if there is no e mail address on the form, send error
MsgBox "You have NO E MAIL ADDRESS to send to???????"
Exit Sub
End If
MsgBox Err.Description
Resume Exit_SendEMailButton_Click
End Sub
I hope this at least points you in the right direction. The Method used
above will send to the default e mail agent you have set up, ie Outlook
Express, Outlook or Lotus notes what ever is set as you default e mail
method. It is always best to send snapshot format because the report
formatting is maintained.
Hope this helps
Mike B
--
Advice to Posters.
Mark as answered when completed.
Check your post for replies or request for more information.
Have the COURTESY to send an ending note even if the answer didn''t work.
Thanks once again.
Marco
--
Advice to Posters.
Check your post for replies or request for more information.
Consider providing some feed back to the response you have recieved.
Kindest Regards Mike B
Thanks, your help was very helpful.
I put it work with your help. but, Is any way to control the Send? well what
I mean is, when I press the button, it asks for the type of file that I want
to export and then opens Outtlok and I have to press Send.
Can I tell to access that the default type to export is Snapshot and send
with I have to press Send button of outlook?
Best Regards,
Marco