Query SQL VBA (Insert INTO) avec Conditions en variable (Date)
Bonjour à tous,
Voila aprés plusieurs essais et aprés plusieurs jours de recherche, je me tourne une fois de plus vers vous.
Je rencontre un probléme de concernant mon CODE SQL voir ci dessous:
Comme d'habitude je créer ma query avec l'assistant access puis je transpoe en SQL pour y inclure mes variables (rien d'extraordinaire), seulement mes clause "where" déconne je ne sais pas pour quelles raison. la query ne me génére rien du tout ou la totalité des enregistrement...
Je deviens fou à force de retourner ce code dans tout les sens, est ce que quelqu'un pourrait me dire si quelque chose vous semble étrange???
Code:
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
| Private Sub Run_ADD_New_Processing_Click()
Dim SQL As String
Dim Date_deb_inf As Date
Dim Date_deb_sup As Date
Dim Date_fin_inf As Date
Dim Date_fin_sup As Date
If IsNull(Forms![142 NEW_PROCESSING]!Txtbx_Date_deb_inf.Value) Then
Date_deb_inf = "01/01/1900"
Else
Date_deb_inf = Forms![142 NEW_PROCESSING]!Txtbx_Date_deb_inf.Value
End If
If IsNull(Forms![142 NEW_PROCESSING]!Txtbx_Date_deb_sup.Value) Then
Date_deb_sup = "31/12/3000"
Else
Date_deb_sup = Forms![142 NEW_PROCESSING]!Txtbx_Date_deb_sup.Value
End If
If IsNull(Forms![142 NEW_PROCESSING]!Txtbx_Date_fin_inf.Value) Then
Date_fin_inf = "01/01/1900"
Else
Date_fin_inf = Forms![142 NEW_PROCESSING]!Txtbx_Date_fin_inf.Value
End If
If IsNull(Forms![142 NEW_PROCESSING]!Txtbx_Date_fin_sup.Value) Then
Date_fin_sup = "31/12/3000"
Else
Date_fin_sup = Forms![142 NEW_PROCESSING]!Txtbx_Date_fin_sup.Value
End If
SQL = "INSERT INTO M_DATA_MANU_PROCESSING ( Pstrav, Article, Désignation_article, Origbes, Stat, Qté_A_venir, Début, Fin, Statut_ord_glob, Date_MAJ ) SELECT M_DATA_CM07.Pstrav, M_DATA_CM07.Article, M_DATA_CM07.Désignation_article, M_DATA_CM07.Origbes, M_DATA_CM07.Stat, M_DATA_CM07.Qté_A_venir, M_DATA_CM07.Début, M_DATA_CM07.Fin, M_DATA_CM07.Statut_ord_glob, M_DATA_CM07.Date_MAJ FROM M_DATA_CM07 INNER JOIN M_DATA_WP_PROCESSING_SELECT ON M_DATA_CM07.Pstrav = M_DATA_WP_PROCESSING_SELECT.[Poste de travail] WHERE (((M_DATA_WP_PROCESSING_SELECT.[Select])=True) AND ((M_DATA_CM07.Début)>" & CDate(Date_deb_inf) & ") And ((M_DATA_CM07.Début)<" & CDate(Date_deb_sup) & ") AND ((M_DATA_CM07.Fin)>" & CDate(Date_fin_inf) & ") And ((M_DATA_CM07.Fin)<" & CDate(Date_fin_sup) & "));"
DoCmd.RunSQL SQL
DoCmd.Close
End Sub |
Un grand Merci d'avance
Alex,