IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBA Access Discussion :

Format date pendant export


Sujet :

VBA Access

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Septembre 2007
    Messages
    29
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2007
    Messages : 29
    Par défaut Format date pendant export
    bonjour
    Voila peut on modifier lors de l'export le format de la date pour enlever les heures
    si j'utilise
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    choixx = "(month(F_POIN.Date_Saisie) = 7 or month(F_POIN.Date_Saisie) = 8)"
    c'est bon
    parcontre
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    choixx = "(month(F_POIN.Date_Saisie) = month(date))"
    ou
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    choixx = "(Format(F_POIN.Date_Saisie,'dd/mm/yyyy')=date())"
    du au format de date je pense

    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
    Sub importpointage()
    MsgBox Month(Date)
    Application.ScreenUpdating = False
        Sheets("import").Visible = True
        Sheets("import").Select
         Cells.Select
        selection.Clear
    choixx = "(month(F_POIN.Date_Saisie) = 7 or month(F_POIN.Date_Saisie) = 8)"
    'choixx = "(Format(F_POIN.Date_Saisie,'dd/mm/yyyy')=date())"
        With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
            "ODBC;DSN=lofic;UID=Administrateur;Trusted_Connection=Yes;APP=Microsoft Office 2010;WSID=DELL04;DATABASE=LOFIC" _
            , Destination:=Range("$A$1")).QueryTable
            .CommandText = _
            "SELECT F_POIN.DO_Piece, F_POIN.RP_Code, F_POIN.AR_ref, F_POIN.Date_Saisie , F_POIN.DL_Qte,  F_POIN.Initiales" _
            & Chr(13) & "" & Chr(10) & "FROM LOFIC.dbo.F_POINTAGE WHERE year(Date_Saisie)='2017' and Initiales IN ('FC0065','FC0105') and RP_Code IN('0FCTRL','FEMBA') AND " & choixx
            .RowNumbers = True
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .BackgroundQuery = True
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .PreserveColumnInfo = True
          .Refresh BackgroundQuery:=False
          .Delete
        End With
     
              Application.ScreenUpdating = True
    End Sub

  2. #2
    Expert éminent
    Avatar de tee_grandbois
    Homme Profil pro
    retraité
    Inscrit en
    Novembre 2004
    Messages
    8 960
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 68
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : retraité

    Informations forums :
    Inscription : Novembre 2004
    Messages : 8 960
    Par défaut
    Bonjour,
    essaie en utilisant un format de date abrégée dans l'instruction Select du paramètre CommandText.

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Septembre 2007
    Messages
    29
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2007
    Messages : 29
    Par défaut
    voila j'ai essayé

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     "SELECT F_POINTAGE.DO_Piece, F_POINTAGE.RP_Code, F_POINTAGE.AR_ref,F_POINTAGE.Date_Saisie=Format(F_POINTAGE.Date_Saisie,'dd/mm/yyyy') , F_POINTAGE.DL_Qte,  F_POINTAGE.Initiales" _
    ou
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     "SELECT F_POINTAGE.DO_Piece, F_POINTAGE.RP_Code, F_POINTAGE.AR_ref,Format(F_POINTAGE.Date_Saisie,'dd/mm/yyyy') , F_POINTAGE.DL_Qte,  F_POINTAGE.Initiales" _
    rien n'y fait erreur de syntaxe

  4. #4
    Expert éminent
    Avatar de tee_grandbois
    Homme Profil pro
    retraité
    Inscrit en
    Novembre 2004
    Messages
    8 960
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 68
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : retraité

    Informations forums :
    Inscription : Novembre 2004
    Messages : 8 960
    Par défaut
    Bonjour,
    ton dernier code est pourtant correct (sauf si la base LOFIC n'est pas une base Access ou ne reconnait pas Format).
    Pour pister les erreurs de syntaxe on va utiliser une variable pour charger CommandText :
    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 importpointage()
    Dim strCommandText as String
    MsgBox Month(Date)
    Application.ScreenUpdating = False
        Sheets("import").Visible = True
        Sheets("import").Select
         Cells.Select
        selection.Clear
    choixx = "(month(F_POIN.Date_Saisie) = 7 or month(F_POIN.Date_Saisie) = 8)"
    'choixx = "(Format(F_POIN.Date_Saisie,'dd/mm/yyyy')=date())"
    strCommandText =   "SELECT F_POIN.DO_Piece, F_POIN.RP_Code, F_POIN.AR_ref, Format(F_POINTAGE.Date_Saisie,'dd/mm/yyyy') as DateSaisie, F_POIN.DL_Qte,  F_POIN.Initiales" _
                   & Chr(13) & Chr(10) & "FROM LOFIC.dbo.F_POINTAGE WHERE year(Date_Saisie)='2017' and Initiales IN ('FC0065','FC0105') and RP_Code IN('0FCTRL','FEMBA') AND " & choixx
    Debug.Print strCommandText     ' pour vérifier la syntaxe et la poster 
     
        With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
            "ODBC;DSN=lofic;UID=Administrateur;Trusted_Connection=Yes;APP=Microsoft Office 2010;WSID=DELL04;DATABASE=LOFIC" _
            , Destination:=Range("$A$1")).QueryTable
            .CommandText = StrCommandText
            .RowNumbers = True
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .BackgroundQuery = True
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .PreserveColumnInfo = True
          .Refresh BackgroundQuery:=False
          .Delete
        End With
     
              Application.ScreenUpdating = True
    End Sub

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Septembre 2007
    Messages
    29
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2007
    Messages : 29
    Par défaut
    bonjour et merci deja
    mais cela me fait erreur de syntaxe
    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
    Sub importpointage()
     
    Application.ScreenUpdating = False
        Sheets("import").Visible = True
        Sheets("import").Select
         Cells.Select
        selection.Clear
    '******************************************
      strCommandText = _
            "SELECT F_POINTAGE.DO_Piece, F_POINTAGE.RP_Code, F_POINTAGE.AR_ref,Format(F_POINTAGE.Date_Saisie,'dd/mm/yyyy') as DateSaisie, F_POINTAGE.DL_Qte,  F_POINTAGE.Initiales" _
            & Chr(13) & "" & Chr(10) & "FROM SOFILEC.dbo.F_POINTAGE WHERE year(Date_Saisie)='2017' and Initiales IN ('SOFC0065','SOFC0105') and RP_Code IN('021COFCTRL','021COFEMBA') "
            Debug.Print strCommandText
     
    '*******************************************
        With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
            "ODBC;DSN=sofilec;UID=Administrateur;Trusted_Connection=Yes;APP=Microsoft Office 2010;WSID=DELL06;DATABASE=SOFILEC" _
            , Destination:=Range("$A$1")).QueryTable
             .CommandText = strCommandText
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .BackgroundQuery = True
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .PreserveColumnInfo = True
          .Refresh BackgroundQuery:=False
          '.Delete
        End With
        ActiveSheet.Columns("d:d").Select
           selection.NumberFormat = "dd/mm/yyyy"
     
         Sheets("import").Columns("A:d").EntireColumn.AutoFit
         'Range("a1").Select
         figervolet
        trierdate
              Application.ScreenUpdating = True
     
    End Sub

  6. #6
    Expert éminent
    Avatar de tee_grandbois
    Homme Profil pro
    retraité
    Inscrit en
    Novembre 2004
    Messages
    8 960
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 68
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : retraité

    Informations forums :
    Inscription : Novembre 2004
    Messages : 8 960
    Par défaut
    mais cela me fait erreur de syntaxe
    OK. Est-il possible que tu précises sur quelle ligne ?

Discussions similaires

  1. Format DATE pour export fichier texte
    Par yeliel0501 dans le forum SAS Base
    Réponses: 3
    Dernier message: 02/07/2013, 13h01
  2. Réponses: 0
    Dernier message: 11/07/2012, 15h19
  3. format date heure export SQL vers Excel
    Par Pedrito95 dans le forum VBScript
    Réponses: 2
    Dernier message: 23/07/2011, 17h29
  4. Date pendant l'export Txt->Excel
    Par Myogtha dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 17/10/2007, 13h26
  5. Format de date lors export vers Excel
    Par Celia1303 dans le forum Access
    Réponses: 7
    Dernier message: 19/12/2006, 07h23

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo