Bonjour,
J'ai un formulaire dont la source de donnée est une instruction SQL que voici.
Cette instruction fait appelle à une fonction que j'ai créée :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 SELECT T_Produit.N°_Commande, T_Produit.N°Auto_Produit, T_Produit.No_Ligne_CDA, T_Produit.N°_Produit_Réf, T_Produit.Code_Article_PSFT, T_Produit.Date_Echéance, T_Produit.Qté_Ligne_Répartition, T_Produit_Référencé.Ref_Article_Fournisseur, T_Produit_Référencé.Unité_de_mesure, T_Produit_Référencé.Libellé_ligne_CDA, [Qté_Ligne_Répartition]-Extrait_Somme_Quantitee_Recue([N°_Commande],[N°Auto_Produit]) AS [Reste à Livrer] FROM T_Produit_Référencé INNER JOIN T_Produit ON T_Produit_Référencé.N°Auto_Produit_Réf = T_Produit.N°_Produit_Réf GROUP BY T_Produit.N°_Commande, T_Produit.N°Auto_Produit, T_Produit.No_Ligne_CDA, T_Produit.N°_Produit_Réf, T_Produit.Code_Article_PSFT, T_Produit.Date_Echéance, T_Produit.Qté_Ligne_Répartition, T_Produit_Référencé.Ref_Article_Fournisseur, T_Produit_Référencé.Unité_de_mesure, T_Produit_Référencé.Libellé_ligne_CDA, [Qté_Ligne_Répartition]-Extrait_Somme_Quantitee_Recue([N°_Commande],[N°Auto_Produit]) HAVING (((T_Produit.N°_Commande)=[Formulaires]![F_Saisie_Entrée_par_Commande]![N°Auto_Commande]));
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 Public Function Extrait_Somme_Quantitee_Recue(N°_Commande_Concernée As Long, N°_Produit_Concerné As String) As Currency Dim RS_Synthèse_Quantitée_Recue As DAO.Recordset Dim Compteur As Long Dim SQL_QLAU As String Set db = CurrentDb Compteur = 0 SQL_QLAU = "SELECT T_Produit.N°_Commande, T_Produit_Réf_T_Emp_Parc.N_Produit, Sum(T_Entrée_Détail.Quantitée_Livrée) AS SommeDeQuantitée_Livrée " SQL_QLAU = SQL_QLAU & "FROM T_Produit INNER JOIN (T_Produit_Réf_T_Emp_Parc INNER JOIN T_Entrée_Détail ON T_Produit_Réf_T_Emp_Parc.N°Auto_Produit_Réf_T_Emp_Parc = T_Entrée_Détail.N°_Produit_Réf_T_Emp_Parc) ON T_Produit.N°Auto_Produit = T_Produit_Réf_T_Emp_Parc.N_Produit " SQL_QLAU = SQL_QLAU & "GROUP BY T_Produit.N°_Commande, T_Produit_Réf_T_Emp_Parc.N_Produit " SQL_QLAU = SQL_QLAU & "HAVING (((T_Produit.N°_Commande) = " & N°_Commande_Concernée & ") And ((T_Produit_Réf_T_Emp_Parc.N_Produit) = '" & N°_Produit_Concerné & "')) " SQL_QLAU = SQL_QLAU & "WITH OWNERACCESS OPTION;" 'Extrait la somme totale des articles reçus pour cet article de cette commande Set RS_Synthèse_Quantitée_Recue = db.OpenRecordset(SQL_QLAU, dbOpenDynaset) 'afin de vérifier qu'il n'y a pas plusieurs enregistrement pour cela il faut fire une boucle 'pour vérifier à nouveau le nombre d'enregistrement suite à Movelast Do Compteur = Compteur + 1 Select Case RS_Synthèse_Quantitée_Recue.RecordCount Case 0 Extrait_Somme_Quantitee_Recue = 0 GoTo fin_ESQR Case 1 RS_Synthèse_Quantitée_Recue.MoveLast Extrait_Somme_Quantitee_Recue = RS_Synthèse_Quantitée_Recue.Fields("SommeDeQuantitée_Livrée").Value Case Else MsgBox "Une erreur c'est produite dans la source SQL : Trop d'enregistrement" Extrait_Somme_Quantitee_Recue = 0 End Select Loop Until Compteur = 2 fin_ESQR: Set db = Nothing Set RS_Synthèse_Quantitée_Recue = Nothing End Function
Le problème se pose lors du chargement du formulaire, c'est très long.
Qu'est ce que je pourrais faire pour améliorer la vitesse?
Merci pour votre réponse.
Partager