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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| Public Function ExportActionsOutlook()
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset
' Référence à la requête
Set qdf = CurrentDb.QueryDefs("rqexportactionsoutlook")
qdf.Parameters("[Forms]![groupes actions]![numgrpaction]") = Forms![groupes actions]![NumGrpAction]
Set rst = qdf.OpenRecordset()
' Enregistrer d'abord pour s'assurer que les champs requis sont remplis.
DoCmd.RunCommand acCmdSaveRecord
On Error GoTo AjoutAction_Err
'Vérifie qu'il existe des actions à exporter
If rst.RecordCount = 0 Then
MsgBox "Il n'y a aucune action à exporter vers Outlook", vbOKOnly, "Transfert annulé"
Exit Function
Else
rst.MoveFirst
Do While Not rst.EOF
' Ajouter un nouveau rendez-vous.
Dim outobj As New Outlook.Application
Dim outappt As Outlook.AppointmentItem
Set outobj = CreateObject("outlook.application")
Set outappt = outobj.CreateItem(olAppointmentItem)
With outappt
.Start = Nz(rst!HoraireDebut, "")
.Duration = Nz(rst!DuréeAction, "")
.Subject = Nz(rst!Contact, "") & " " & Nz(rst![vendeur/intervenant], "")
.Body = Nz(rst!NotesAction, "")
.Location = Nz(rst!LieuAction, "")
.ReminderMinutesBeforeStart = Nz(rst!MinutesRappel, "")
.ReminderSet = Nz(rst!RappelAction, "")
Debug.Print rst!HoraireDebut, rst!DuréeAction, rst![vendeur/intervenant], rst!NotesAction, rst!LieuAction, rst!MinutesRappel, rst!RappelAction
Debug.Print Forms![groupes actions]!NumGrpAction
' Définir l'indicateur AjoutéàOutlook, enregistrer, afficher un message.
CurrentDb.Execute ("update t_rendezvous set t_rendezvous.ajoutéàoutlook=-1 where ((t_rendezvous.numaction=forms![groupes actions]![sf groupes actions].form))")
.Save
End With
'Boucle
rst.MoveNext
Loop
End If
' Libérer la variable objet Outlook.
Set outobj = Nothing
Set rst = Nothing
Set outappt = Nothing
' Libération de la référence
Set qdf = Nothing
MsgBox " Actions ajoutées à Outlook ! "
Exit Function
AjoutAction_Err:
MsgBox " Erreur " & err.Number & Chr(10) & err.Description
Exit Function
End Function |
Partager