Emailing from Access and inserting attachments

G

Guest

Hi there, i am currently in the process of testing/building a new contact
management system based on access forms - i have an email form that users
fill in and then click on an email button to send the contents of the form to
the required contact automatically via access. However as part of filling in
the form i need users to be able to click on a button that will open a browse
button that will allow them to select a single or multiple attachments to the
form and then clicking on the email button will allow them to send the
contents of the form via outlook, which will then obviously include the
attachment(s). these attachments would then have the path to them stored in
a filed in the email back end table.

Does anyone have any code for doing this? This is my current code for
sending the contents of the form via outlook:

Public Sub Command5_Click()
On Error GoTo Err_Command5_Click
Dim strAddress As String
Dim strMsg As String
Dim strTitle As String
Dim strSent As Integer
Dim objOutlookAttach As Outlook.Attachment

DoCmd.RunCommand acCmdSaveRecord

strMsg = Forms!email!body
strAddress = Forms!email!emailaddress
strTitle = Forms!email!subject
strSent = Forms!email!sent

If Forms!email!sent = True Then
MsgBox "This email has already been sent", vbInformation, "Notification"
DoCmd.Close
Else

DoCmd.SendObject , , acFormatHTML, strAddress, , , strTitle, strMsg,
False, False

'Run update to update the sent mail check box
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE email SET email.sent = -1"
DoCmd.SetWarnings True
MsgBox "Email has been sent", vbInformation, "Thank You"
DoCmd.Close
End If

exit_command5_click:
Exit Sub

Err_Command5_Click:
MsgBox Err.Description
Resume exit_command5_click
End Sub


Thanks,

Rhys.
 
G

Guest

It would be easier to use the sendobject command. i.e.

docmd.sendobject acsendform, Name of form... Just look it up in help and it
will give you everything you need.
 

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