Bonjour à tous,
je reviens avec un autre soucis sur mon code VB Access. N'ayant pas jusque là trouvé de solution sur mon problème précédent j'ai alors décidé de passer à autre chose qui semble bien marché mais j'ai deux débogages lors de l'exécution et je n'ai aucun affichage des informations que je veux récupérer sur les éléments sélectionnés dans mon état.
Je m'explique: J'ai fais deux listes déroulantes, une qui contient la liste des éléments à sélectionner (lstfrs) et une autre (lstfrsselectionnes) qui contiendra les éléments sélectionnés dans la liste "lstfrs" via des boutons de bascules que j'ai créé. Une fois que la bascule des éléments sélectionnés établi, je fais un clique sur le bouton "ok" qui me donne directement l'état de ces éléments. J'ai fais pour mon code un module standard qui contient toute la partie initialisation et dans le module du formule j'ai fais le code d'exécution même du processus. J'ai souligné et mis en gras les lignes où j'ai un débogage:
Voici mon code:
Code contenu dan le module standard:
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
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 ' ----------------------------- ' INITIALISATION DES SELECTIONS ' ----------------------------- ' Entrée : strTableCible <- Nom de la table dont ' on veut sélectionner les lignes ' strClefPrimaire <- Nom de la clef primaire de la table cible. ' strTableSelection <- Nom de la table de sélection ' strWhere <- Clause Where optionnelle ' Sub InitialiserSelection( _ ByVal strTable As String, _ Optional ByVal strClefPrimaire As String, _ Optional ByVal strTableSelection As String = "Table sélection", _ Optional ByVal strWhere As String = "" ) ' Vider la table des sélections 'strTableSelection = "[" & strTableSelection & "]" 'CurrentDb.Execute "DELETE * FROM " & strTableSelection & ";" ' Renseigner les nouvelles valeurs ' de la table des sélections Dim strSQL As String strSQL = "INSERT INTO " & strTableSelection & " (ID frs, Sélectionné)" _ & " SELECT [" & strClefPrimaire & "],True" _ & " FROM [" & strTable & "]" If strWhere <> "" Then strSQL = strSQL & " WHERE " & strWhere CurrentDb.Execute strSQL (1er débogage: Message d'erreur: "Erreur de syntaxe dans l'instruction INSERT INTO" ) End Sub ' ------------------------------- ' SELECTIONNER TOUTES LES LIGNES ' ------------------------------- Sub ToutSelectionner( _ Optional ByVal strTableSelection As String = "Table sélection" ) CurrentDb.Execute "UPDATE [" & strTableSelection & "] SET [Sélectionné] = True;" End Sub ' -------------------------------- ' DESELECTIONNER TOUTES LES LIGNES ' -------------------------------- Sub ToutDeselectionner( _ Optional ByVal strTableSelection As String = "Table sélection" ) CurrentDb.Execute "UPDATE [" & strTableSelection & "] SET [Sélectionné] = False;" End Sub ' -------------------------------- 'INVERSER LA SELECTION D'UNE LIGNE ' -------------------------------- Sub InverserSelection( _ ByVal lngNumero As Long, _ Optional ByVal strTableSelection As String = "Table sélection" ) Dim strSQL As String strSQL = "UPDATE [" & strTableSelection & "] SET [Sélectionné] = TRUE" _ & " WHERE [ID frs] = " & lngNumero CurrentDb.Execute strSQL End Sub ' ------------------------------ ' COMPTER LE NOMBRE DE SELECTION ' ------------------------------ Function NombreSelections( _ Optional ByVal strTableSelection As String = "Table sélection" ) As Long NombreSelections = DCount("*", strTableSelection, "[Sélectionné] = True" ) End Function
Code contenu dans le module du formulaire:
-
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
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 ----------------------- ' CHARGEMENT DU FORMULAIRE ' ------------------------ Private Sub Form_Load() InitialiserSelection "FOURNISSEURS", "ID frs", "Table sélection" MiseAJourListes End Sub ' ---------------------- ' MISE A JOUR DES LISTES ' ---------------------- Private Sub MiseAJourListes() Me.lstfrs.Requery Me.lstfrsselectionnes.Requery End Sub ' -------------------------- ' SELECTION D'UN FOURNISSEUR ' -------------------------- Private Sub btnselectionun_Click() InverserSelection Me.lstfrs.Value 'TransfererUn Me.lstfrs, Me.lstfrsselectionnes MiseAJourListes End Sub ' ---------------------------- ' DESELECTION D'UN FOURNISSEUR ' ---------------------------- Private Sub btndeselectionun_Click() InverserSelection Me.lstfrsselectionnes.Value (2ème débogage: Message d'erreur: Utilisation incorrecte de NULL) 'TransfererUn Me.lstfrsselectionnes, Me.lstfrs MiseAJourListes End Sub ' ---------------------------------- ' SELECTION DE TOUS LES FOURNISSEURS ' ---------------------------------- Private Sub btnselectiontout_Click() ToutSelectionner MiseAJourListes End Sub ' ------------------------------------ ' DESELECTION DE TOUS LES FOURNISSEURS ' ------------------------------------ Private Sub btndeselectiontout_Click() ToutDeselectionner MiseAJourListes End Sub ' -------------------------------------------- ' DOUBLE-CLIC POUR SELECTIONNER UN FOURNISSEUR ' -------------------------------------------- Private Sub lstfrs_DblClick(Cancel As Integer) btnselectionun_Click End Sub ' ---------------------------------------------- ' DOUBLE-CLIC POUR DESELECTIONNER UN FOURNISSEUR ' ---------------------------------------------- Private Sub lstfrsselectionnes_DblClick(Cancel As Integer) btndeselectionun_Click End Sub ' ----------------------- ' FERMETURE DU FORMULAIRE ' ----------------------- Private Sub btnannuler_Click() DoCmd.Close End Sub ' ------------------------ ' VALIDATION DU FORMULAIRE ' ------------------------ Private Sub btnok_Click() ' Est-ce qu'on a sélectionné au moins 1 fournisseur ? If NombreSelections() = 0 Then MsgBox "Vous n'avez sélectionné aucun fournisseur !", vbExclamation Exit Sub End If ' Fermer le formulaire et ouvrir l'état des fournisseurs DoCmd.Close DoCmd.OpenReport "rapport frs", acViewPreview, , "[Sélectionné] = True" End Sub
Je vous remercie d'avance de votre aide.
Dany
Partager