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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| Public Function SynchroCalendrierOutlook()
Dim myOlApp As New outlook.Application
Dim objNamespace As outlook.NameSpace
Dim DossierOutlook As outlook.MAPIFolder
Dim RdvOutlook As outlook.AppointmentItem
Dim FiltreExport As outlook.Items
Dim FiltreImport As outlook.Items
Dim item As Object
Dim Found As Boolean
Dim T As Double
Dim rstRdv As DAO.Recordset
Dim rstImport As DAO.Recordset
Dim Compteur As Single
Dim LigneRdvActif As String
Set objNamespace = myOlApp.GetNamespace("MAPI")
Set DossierOutlook = objNamespace.GetDefaultFolder(olFolderCalendar)
Compteur = 0
T = Timer
Set rstRdv = CurrentDb.OpenRecordset("SELECT t_rendezvous.idaction,t_rendezvous.ajoutéàoutlook,T_RendezVous.HoraireDebut,T_RendezVous.horairefin,T_RendezVous.NotesAction, T_RendezVous.LieuAction, T_RendezVous.RappelAction, T_RendezVous.MinutesRappel, T_RendezVous.NumAction, T_RendezVous.DuréeAction,t_rendezvous.numcontact, [Vendeurs et Intervenants].[Vendeur/Intervenant], RqContacts.Contact " & _
"FROM RqContacts INNER JOIN ([Vendeurs et Intervenants] INNER JOIN T_RendezVous ON [Vendeurs et Intervenants].IdVendeurIntervenant = T_RendezVous.IdIntervenant) ON RqContacts.numContact = T_RendezVous.numContact;")
'Première passe : on ajoute les rdv non présents dans Outlook :
DoCmd.OpenForm ("dialogbox")
Forms![dialogbox].txtdialogbox = "Veuillez patienter pendant le procesus de synchronisation"
rstRdv.MoveFirst
Do While Not rstRdv.EOF
Set FiltreExport = DossierOutlook.Items.Restrict("[start]='" & Format("" & rstRdv!HoraireDebut & "", "dd/mm/yyyy hh:mm") & "' and [end]= '" & Format("" & rstRdv!HoraireFin & "", "dd/mm/yyyy hh:mm") & "' and [subject]= """ & rstRdv!Contact & """")
If FiltreExport.Count = 0 Then
LigneRdvActif = LigneRdvActif & "<br>" & Compteur & ". " & Format("" & rstRdv!HoraireDebut & "", "dd/mm/yyyy hh:mm") & " à " & Format("" & rstRdv!HoraireFin & "", "dd/mm/yyyy hh:mm") & " " & rstRdv!Contact
Found = False
Debug.Print Compteur & " " & rstRdv!HoraireDebut, rstRdv!HoraireFin, rstRdv!Contact
'Création du rdv
Set RdvOutlook = myOlApp.CreateItem(olAppointmentItem)
With RdvOutlook
.Start = rstRdv!HoraireDebut
.Duration = rstRdv!DuréeAction
.Subject = Nz(rstRdv!Contact, "")
.Body = Nz(rstRdv!NotesAction, "")
.Location = Nz(rstRdv!LieuAction, "")
.ReminderMinutesBeforeStart = Nz(rstRdv!MinutesRappel, "")
.ReminderSet = Nz(rstRdv!RappelAction, "")
.Save
End With
' Définir l'indicateur AjoutéàOutlook, enregistrer, afficher un dialogbox.
CurrentDb.Execute ("update t_rendezvous set t_rendezvous.ajoutéàoutlook = true " & _
",t_rendezvous.datecreationoutlook='" & Now() & "' " & _
"where numaction = " & rstRdv!NumAction & ";")
Compteur = Compteur + 1
Forms![dialogbox].txtdialogbox = "<b>" & "Les " & Compteur & " rdv suivants ont été synchronisés avec Outlook :" & "</b>" & "<br>" & "<br>" & " " & LigneRdvActif
Else
Found = True
rstRdv.MoveNext
End If
Loop
'Deuxième passe : On propose d'importer un rdv présent dans outlook inexistant dans la table T_RendezVous d' Access
For Each RdvOutlook In DossierOutlook.Items
Set FiltreImport = DLookup("[numcontact]", "t_rendezvous", "t_rendezvous.[horairedebut]= '" & Format("" & RdvOutlook.Start & "", "#\dd/mm/yyyy hh:mm\#") & "'")
If FiltreImport.Count > 0 Then
Debug.Print RdvOutlook.Subject, RdvOutlook.Start
End If
Next
myOlApp.Quit
Set rstRdv = Nothing
Set rstImport = Nothing
Set myOlApp = Nothing
Set objNamespace = Nothing
Set DossierOutlook = Nothing
Debug.Print Timer - T
End Function |
Partager