Bonjour à tous,
Voilà, je veux créer une table Tbl_periode, qui doit contenir les enregistrements de 3 tables différentes dans un intervalle de temps (entre deux dates) bien définie.
Je rencontre 2 problèmes avec mon code:

  1. Au delà du fait que je rentre les dates de début et de fin dans une inputbox, les dates ne sont pas prises ne compte je dois les ressaisir à nouveau comme paramètres.
  2. Seuls les enregistrements de la première table (le résultat la première partie du code) se retrouve dans la table finale tbl_periode.




je poste mon code.


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
Option Explicit
 
Private Sub Commande1_Click()
    Dim sSql1 As String, sSql2 As String, sSql3 As String, cboSubstance As String
 
 
    DateDeb = InputBox("Entrer obligatoirement une date inférieure", , "dd/mm/yyyy")
    DateFin = InputBox("Entrer obligatoirement une date supérieure", , "dd/mm/yyyy")
 
    If IsDate(DateDeb) And IsDate(DateFin) Then
 
 
        'If DLookup("[Substance]", "SUBSTANCE", "[Substance] like ""*" & Nom & "*""") <> "" And Nom <> "" Then
 
        sSql1 = "SELECT RECHERCHE_MINIERE.OPERATEUR, RECHERCHE_MINIERE.TYPE_DEMANDE, RECHERCHE_MINIERE.SUBSTANCE, RECHERCHE_MINIERE.OBJET," _
            & "RECHERCHE_MINIERE.Zone, RECHERCHE_MINIERE.DATE_ARRIVEE_DGMG, RECHERCHE_MINIERE.STATUT " _
            & "INTO [" & "TBL_periode] " _
            & "FROM RECHERCHE_MINIERE " _
            & "WHERE (((RECHERCHE_MINIERE.DATE_ARRIVEE_DGMG) Between DateDeb And DateFin));"
 
 
 
        sSql2 = "INSERT INTO [" & "TBL_periode] " _
            & "SELECT EXPLOITATION_CARRIERES.OPERATEUR, EXPLOITATION_CARRIERES.TYPE_DEMANDE, EXPLOITATION_CARRIERES.SUBSTANCE, EXPLOITATION_CARRIERES.OBJET," _
            & "EXPLOITATION_CARRIERES.Zone, EXPLOITATION_CARRIERES.DATE_ARRIVEE_DGMG, EXPLOITATION_CARRIERES.STATUT " _
            & "FROM EXPLOITATION_CARRIERES " _
            & "WHERE (((EXPLOITATION_CARRIERES.SUBSTANCE)Between DateDeb And DateFin));"
 
        sSql3 = "INSERT INTO [" & "TBL_periode] " _
            & "SELECT EXPLOITATION_MINIERE.OPERATEUR, EXPLOITATION_MINIERE.TYPE_DEMANDE, EXPLOITATION_MINIERE.SUBSTANCE, EXPLOITATION_MINIERE.OBJET," _
            & "EXPLOITATION_MINIERE.Zone, EXPLOITATION_MINIERE.DATE_ARRIVEE_DGMG, EXPLOITATION_MINIERE.STATUT " _
            & "FROM EXPLOITATION_MINIERE " _
            & "WHERE (((EXPLOITATION_MINIERE.SUBSTANCE)Between DateDeb And DateFin));"
        DoCmd.SetWarnings False
        DoCmd.RunSQL sSql1
        DoCmd.RunSQL sSql2
        DoCmd.RunSQL sSql3
        DoCmd.SetWarnings True
    Else
        ' Si la saisie est incorrecte...
        MsgBox "Vous n'avez pas tapé de date !", vbExclamation
 
    End If
 
End Sub
Merci pour votre aide.