1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| Public Function OuvrirAttachments()
On Error GoTo err
' Référence obligatoire : Microsoft Office 11.0 Object Library.
Dim fDialog As Office.FileDialog
Dim varFile As Variant
Dim rst As Recordset
' Prépare le dialog box.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
' Permet de sélectionner plusieurs fichiers dans le dialog box.
.AllowMultiSelect = True
' Titre du dialog box.
.Title = "Choisissez une ou plusieurs pièces jointes"
' Efface les filtres actuels et utilise les nouveaux.
.Filters.Clear
.Filters.Add "All Files", "*.*"
' Affiche le dialog box. Si .Show renvoie True, l'utilisateur à choisi au moins un fichier, si False, l'utilisateur a choisi Cancel.
If .Show = True Then
' Boucle au travers de tous les fichiers sélectionnés et les ajoute au list box.
Set rst = CurrentDb.OpenRecordset("attachments mails")
For Each varFile In .SelectedItems
'Me.filelist.AddItem varFile
With rst
.AddNew
!PathAttachment = varFile
!NumMail = Forms!Mails!NumMail
.Update
End With
Next
rst.Close
Else
MsgBox "Vous avez annulée l'opération en cours"
End If
End With
err:
'Gestion d'erreur
Select Case err.Number
Case 3024:
MsgBox "Fichier inexistant", vbCritical
Case 3820:
MsgBox "Une autre pièce-jointe avec le même nom existe déjà", vbCritical
End Select
Forms![Mails]![Attachments].Requery
Forms![Mails].ListeAttachmentsSélectionnés
End Function |
Partager