DBPix Sample Source Code: frmImages Back to sample
Option Compare Database
Option Explicit
Const strTempDir = "\email-temp\"
Private Sub btnSendEmail_Click()
Dim strPath As String
Dim oApp As Outlook.Application
Dim oMsg As Outlook.MailItem
' Generate a tempoary path to save the image file for attching to the email
strPath = CurrentProject.Path & strTempDir & [Id] & ".jpg"
' Save the image to a temporary file
If DBPixCtrl.ImageSaveFile(strPath) Then
Set oApp = New Outlook.Application
Set oMsg = oApp.CreateItem(olMailItem)
' Add the attachment, then delete the temporary file
oMsg.Attachments.Add strPath, olByValue, 1, "DBPix Email Sample"
Kill strPath
' Set the To, Subject and Body fields
' oMsg.to = "someone@somewhere.com" ' Set the to: address here if applicable
oMsg.Subject = [Description] ' Use the Description field from the database
oMsg.Body = "The image file is attached."
' Display the message for the user to review and send
oMsg.Display
' Clean-up
Set oApp = Nothing
Set oMsg = Nothing
End If
End Sub
Private Sub Form_Current()
' Only enable the send button if an image is present
btnSendEmail.Enabled = IIf(LenB([Image]) > 0, True, False)
End Sub
Back to sample
|