Bonjour,
J'ai développé un bouton qui modifie un champ des documents sélectionnés dans une vue et marque dans le champ "ETAT" le mot "Supprimé" . Cela marche bien sauf quand le document est déjà dans l'état "Supprimé", cela fait planter Notes.
La vue est simple un simple SELECT form = "crepas". La routine aussi :
La petite routine UpdateHistory ne casse pas trois pattes à un canard :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Sub Click(Source As Button) Dim s As New notessession Dim db As notesdatabase Dim col As notesdocumentcollection Dim doc As notesdocument Dim workspace As New NotesUIWorkspace Set uiview = workspace.CurrentView Set db=s.CurrentDatabase Set col=db.UnprocessedDocuments Set doc=col.getfirstdocument If doc Is Nothing Then Messagebox "Pour supprimer des repas, veuillez tout d'abord sélectionner des documents en cliquant dans la marge gauche.", MB_OK+MB_ICONINFORMATION,"C.C.F" Exit Sub End If reponse% = Msgbox ("Etes-vous sûr de vouloir supprimer " & col.Count & " repas ?", 4 + 32, "C.C.F - Supprimer des repas") If reponse% = 7 Then ' Non. Exit Sub End If While Not doc Is Nothing If Doc.etat ( 0 ) <> "Supprimé" Then doc.ETAT = "Supprimé" Call UpdateHistory ( "Supprimé", Doc, "Bouton Supprimer repas de la vue Toutes les cantines") Call Doc.Save ( True, True ) Set doc=col.GetNextDocument(doc) End If Wend Call workspace.ViewRefresh Messagebox col.Count & " repas supprimé(s).", 0+64,"C.C.F - Supprimer des repas" End Sub
Pourquoi Notes plante-t-il quand le champ est déjà marqué avec le texte "Supprimé" ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Sub UpdateHistory (Etat As String, Doc As NotesDocument, Instigateur As String) Dim session As New NotesSession Dim Field As NotesItem Dim User As String If Doc.HasItem("Date_history") Then Set Field = Doc.GetFirstItem("Date_history") Call Field.AppendToTextList ( Date$ + " " + Time$ ) Else Set Field = Doc.ReplaceItemValue( "Date_history", Date$ + " " + Time$ ) End If User = session.UserName If Doc.HasItem("Edit_Author") Then Set Field = Doc.GetFirstItem("Edit_Author") Call Field.AppendToTextList ( User ) Else Set Field = Doc.ReplaceItemValue( "Edit_Author", User ) End If If Doc.HasItem("Edit_history") Then Set Field = Doc.GetFirstItem("Edit_history") Call Field.AppendToTextList ( Etat ) Else Set Field = Doc.ReplaceItemValue( "Edit_history", Etat ) End If If Doc.HasItem("Instigateur") Then Set Field = Doc.GetFirstItem("Instigateur") Call Field.AppendToTextList ( Instigateur ) Else Set Field = Doc.ReplaceItemValue( "Instigateur", Instigateur ) End If End Sub
Cordialement.
Christian
Partager