Vorrei inviare una mail da Access a Microsoft Outlook
ho trovato in rete questa funzione
' Procedure : SendEmail
' Author : CARDA Consultants Inc.
' Website :
http://www.cardaconsultants.com
' Purpose : Automate Outlook to send emails with or without attachments
' Copyright : The following may be altered and reused as you wish so long as the
' copyright notice is left unchanged (including Author, Website and
' Copyright). It may not be sold/resold or reposted on other sites (links
' back to this site are allowed).
'
' Input Variables:
' ~~~~~~~~~~~~~~~~
' strTo To Recipient email address string (semi-colon separated list)
' strSubject Text string to be used as the email subject line
' strBody Text string to be used as the email body (actual message)
' bEdit True/False whether or not you wish to preview the email before sending
' strBCC BCC Recipient email address string (semi-colon separated list)
' AttachmentPath single value or array of attachment (complete file paths with
' filename and extensions)
'
' Revision History:
' Rev Date(yyyy/mm/dd) Description
' **************************************************************************************
' 1 2007-Nov-16 Initial Release
'---------------------------------------------------------------------------------------
Function SendEmail(strTo As String, strSubject As String, strBody As String, bEdit As Boolean, _
Optional strBCC As Variant, Optional AttachmentPath As Variant)
'Send Email using late binding to avoid reference issues
Dim objOutlook As Object
Dim objOutlookMsg As Object
Dim objOutlookRecip As Object
Dim objOutlookAttach As Object
Dim i As Integer
Const olMailItem = 0
On Error GoTo ErrorMsgs
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
Set objOutlookRecip = .Recipients.Add(strTo)
objOutlookRecip.Type = 1
If Not IsMissing(strBCC) Then
Set objOutlookRecip = .Recipients.Add(strBCC)
objOutlookRecip.Type = 3
End If
.Subject = strSubject
.Body = strBody
.Importance = 2 'Importance Level 0=Low,1=Normal,2=High
' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
If IsArray(AttachmentPath) Then
For i = LBound(AttachmentPath) To UBound(AttachmentPath) - 1
If AttachmentPath(i) <> "" And AttachmentPath(i) <> "False" Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath(i))
End If
Next i
Else
If AttachmentPath <> "" Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
End If
End If
For Each objOutlookRecip In .Recipients
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
If bEdit Then 'Choose btw transparent/silent send and preview send
.Display
Else
.Send
End If
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
Set objOutlookRecip = Nothing
Set objOutlookAttach = Nothing
ErrorMsgs:
If err.Number = "287" Then
MsgBox "You clicked No to the Outlook security warning. " & _
"Rerun the procedure and click Yes to access e-mail " & _
"addresses to send your message. For more information, " & _
"see the document at
http://www.microsoft.com/office" & _
"/previous/outlook/downloads/security.asp."
Exit Function
ElseIf err.Number <> 0 Then
MsgBox err.Number & " - " & err.Description
Exit Function
End If
End Function
Ho bisogno di allegare una serie di file quindi un Array
Da una maschera con il pulsante
Private Sub cmdInviaAoutlook_Click()
Dim db As DAO.Database
Dim rst As Recordset
Dim strSQL As String
Dim strAllegati As String
10 strSQL = "SELECT tblDoc.*, * " & vbCrLf & _
"FROM tblDoc " & vbCrLf & _
"WHERE (((tblDoc.IdProblemi)= " & [Forms]![frmProblemi]![IdProblemi] & "));"
20 Set db = CurrentDb
30 Set rst = db.OpenRecordset(strSQL, dbOpenSnapshot)
40 If rst.RecordCount > 0 Then
50 rst.MoveLast
60 Do Until rst.BOF
70 strAllegati = strAllegati & """" & rst![strPath] & """, "
80 rst.MovePrevious
90 Loop
100 End If
'110 strAllegati = strAllegati & " "" """
110 strAllegati = strAllegati & """"""
'120 Debug.Print strAllegati
Dim A As Variant
' se copio il contenuto di debug.print strAllegati
' come qui sotto
'A = Array("C:\Tabelle PSolving\Archivio\FOTO\Carlo2006.bmp", "C:\Tabelle PSolving\Archivio\FOTO\Cattura.PNG", "")
'e lancio SendMail
' SendEmail "
mia...@gmail.com", "Prova", "In allegato", True, , A
' tutto funziona
' io vorrei passare l'array
120 A = Array(strAllegati)
130 SendEmail "
mia...@gmail.com", "Prova", "In allegato", True, , A
' mi si apre correttamente la Mail ma senza allegati
140 rst.Close
End Sub
Dove sbaglio penso che non sia corretta la sintassi a riga 120