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

Access Discussion :

[VBA] [SQL] Type incompatible dans le critère


Sujet :

Access

  1. #1
    Membre confirmé
    Inscrit en
    Avril 2006
    Messages
    175
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 175
    Par défaut [VBA] [SQL] Type incompatible dans le critère
    Bonjours à tous,
    Voilà je suis débutant en VBA et travail sur Access 2003. J'ai essayé d'appliqué le tuto de cafeine mais sans succès, je rencontre un problème lorsque je veux sélectionner un critère le msg d'erreur: [FONT=Verdana]Erreur d'exécution '3464' Type de données incompatible dans l'expression du critère[/FONT], apparaît
    Lorsque je clic sur débogage le code renvoyé est:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Me.lblStats.Caption = DCount("*", "HELICOPTER", SQLWhere) & " / " & DCount("*", "HELICOPTER")

    De plus lorsque je double clic sur un enregistrement pour ouvrir le formulaire de saisie, le msg d'erreur: [FONT=Verdana]Erreur d'exécution '3075': Erreur de syntaxe (operateur absent) dans l'expression '[Aircraft_Register]=3a-MSY'.[/FONT]
    Et lorsque je clic sur débogage le code est:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    DoCmd.OpenForm "helicopter", acNormal, , "[Aircraft_Register] = " & Me.lstResults

    Aircraft_Register correspond à ma clé primaire, elle est de type texte. (ex:
    3a-MSY)
    Pouvez-vous m'aider, merci d'avance

  2. #2
    Membre confirmé
    Inscrit en
    Avril 2006
    Messages
    30
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 30
    Par défaut
    quelle est la valeur de "SQLWhere" ?


    essaie plutot:
    DoCmd.OpenForm "helicopter", acNormal, , "[Aircraft_Register] = '" & Me.lstResults & "'"
    ta clé étant en texte, il faut mettre le paramètre entre quote.


    Alain

  3. #3
    Membre confirmé
    Inscrit en
    Avril 2006
    Messages
    175
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 175
    Par défaut
    Merci Alain,
    J'ai changé mon code et ça marche lorsque je clic sur un enregistrement.

    J'ai placé un Debug.Print SQLWhere et j'ai effectué une recherche par critère sur le type d'appareil (AS 332) le même message d'erreur apparaît type 3464.
    Dans ma fenêtre d'exécution est renvoyée la valeur suivante:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    HELICOPTER!Aircraft_Register <> 0 And HELICOPTER!Helicopter_Family = ''
    HELICOPTER!Aircraft_Register <> 0 And HELICOPTER!Helicopter_Family = 'AS 332'

  4. #4
    Membre confirmé
    Inscrit en
    Avril 2006
    Messages
    175
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 175
    Par défaut
    Voilà où j'en suis pour l'instant dans 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
     
    Private Sub RefreshQuery()
    Dim SQL As String
    Dim SQLWhere As String
    SQL = "SELECT Aircraft_Register,Helicopter_Model,SN,Registration_History,Flotation_Status,Helicopter_Family,Country_Helicopter,Last_Update_Date,Last_Update_Person FROM HELICOPTER WHERE Aircraft_Register Is Not Null;"
    If Not Me.chkAircraft_Register Then
        SQL = SQL & " And HELICOPTER!Aircraft_Register like '*" & Me.txtRechAircraft_Register & "*' "
    End If
    If Not Me.chkCountry_Helicopter Then
        SQL = SQL & " And HELICOPTER!Country_Helicopter = '" & Me.cmbRechCountry_Helicopter & "' "
    End If
    If Me.chkFlotation_Status Then
        SQL = SQL & " And HELICOPTER!Flotation_Status = '" & Me.cmbRechFlotation_Status & "' "
    End If
    If Me.chkSN Then
        SQL = SQL & " And HELICOPTER!SN like '*" & Me.txtRechSN & "*' "
    End If
    If Me.chkHelicopter_Family Then
        SQL = SQL & " And HELICOPTER!Helicopter_Family = '" & Me.cmbRechHelicopter_Family & "' "
    End If
    SQLWhere = Trim(Right(SQL, Len(SQL) - InStr(SQL, "Where ") - Len("Where ") + 1))
    SQL = SQL & ";"
    Debug.Print SQLWhere
    Me.lblStats.Caption = DCount("*", "[HELICOPTER]", SQLWhere) & " / " & DCount("*", "[HELICOPTER]")
    Me.lstResults.RowSource = SQL
    Me.lstResults.Requery
    End Sub

  5. #5
    Membre confirmé Avatar de Rcanada
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    130
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Mai 2004
    Messages : 130
    Par défaut
    Un petit aperçu de mon formulaire pour que tu voye à koi correspond le code que je t'ai envoyé...
    Images attachées Images attachées  

  6. #6
    Membre confirmé
    Inscrit en
    Avril 2006
    Messages
    175
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 175
    Par défaut
    Merci pour ton aide,
    le code est vraiment différent de celui du tuto de cafeine, mais le résultat est impressionnant

  7. #7
    Membre averti
    Inscrit en
    Avril 2006
    Messages
    38
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 38
    Par défaut
    Bonjour a tous

    Voila je me permet de poser une question dans cette discussion car j'ai la meme erreur qu'alex.a. J'ai deux critères exacts THEMEPHOTO et NOMSERVICES et un critère continu NOMPHOTOS.
    Voici 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
    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
    77
    78
     
    Option Compare Database
    Private Sub chkNOMPHOTOS_Click()
    If Me.chkNOMPHOTOS Then
        Me.txtrechNOMPHOTOS.Visible = False
    Else
        Me.txtrechNOMPHOTOS.Visible = True
    End If
    RefreshQuery
    End Sub
     
    Private Sub chkNOMSERVICES_Click()
    If Me.chkNOMSERVICES Then
        Me.cmbRechNOMSERVICES.Visible = False
    Else
        Me.cmbRechNOMSERVICES.Visible = True
    End If
    RefreshQuery
    End Sub
    Private Sub chkTHEMEPHOTO_Click()
    If Me.chkTHEMEPHOTO Then
        Me.cmbRechTHEMEPHOTO.Visible = False
    Else
        Me.cmbRechTHEMEPHOTO.Visible = True
    End If
    RefreshQuery
    End Sub
    Private Sub cmbRechTHEMEPHOTO_BeforeUpdate(Cancel As Integer)
    RefreshQuery
    End Sub
    Private Sub cmbRechNOMSERVICES_BeforeUpdate(Cancel As Integer)
    RefreshQuery
    End Sub
     
    Private Sub txtRechNOMPHOTOS_BeforeUpdate(Cancel As Integer)
    RefreshQuery
    End Sub
    Private Sub Form_Load()
    Dim ctl As Control
    For Each ctl In Me.Controls
        Select Case Left(ctl.Name, 3)
            Case "chk"
                ctl.Value = -1
     
            Case "lbl"
                ctl.Caption = "- * - * -"
            Case "txt"
                ctl.Visible = False
                ctl.Value = ""
     
            Case "cmb"
                ctl.Visible = False
     
        End Select
    Next ctl
    Me.lstresults.RowSource = "SELECT NOMPHOTOS, NOMSERVICES, THEMEPHOTO FROM tblPHOTOS;"
    Me.lstresults.Requery
    End Sub
    Private Sub RefreshQuery()
    Dim SQL As String
    Dim SQLWhere As String
    SQL = "SELECT NOMPHOTOS, NOMSERVICES, THEMEPHOTO Where tblPHOTOS!NOMPHOTOS <> 0 "
    If Not Me.chkNOMPHOTOS Then
        SQL = SQL & "And tblPHOTOS!NOMPHOTOS like '*" & Me.txtrechNOMPHOTOS & "*' "
    End If
    If Not Me.chkNOMSERVICES Then
        SQL = SQL & "And tblPHOTOS!NOMSERVICES = '" & Me.cmbRechNOMSERVICES & "' "
    End If
    If Not Me.chkTHEMEPHOTO Then
        SQL = SQL & "And tblPHOTOS!THEMEPHOTO = '" & Me.cmbRechTHEMEPHOTO & "' "
    End If
     
    SQLWhere = Trim(Right(SQL, Len(SQL) - InStr(SQL, "Where ") - Len("Where ") + 1))
    SQL = SQL & ";"
    Me.lblStats.Caption = DCount("*", "tblPHOTOS", SQLWhere) & " / " & DCount("*", "tblPHOTOS")
    Me.lstresults.RowSource = SQL
    Me.lstresults.Requery
    End Sub
    Lorsque je clique sur les cases a cocher j'ai "erreur d'execution 2001: opération annulée"
    Pourquoi?

  8. #8
    Membre averti
    Inscrit en
    Avril 2006
    Messages
    38
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 38
    Par défaut
    Lorsque je débogue il me renvoie vers

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Me.lblStats.Caption = DCount("*", "tblPHOTOS", SQLWhere) & " / " & DCount("*", "tblPHOTOS")

  9. #9
    Membre confirmé
    Inscrit en
    Avril 2006
    Messages
    175
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 175
    Par défaut
    Salut jeck,

    ta clé primaire est aussi de type texte?

    Mon erreur renvoyé est une erreur d'exécution '3075':
    Erreur de syntaxe dans l'espression 'Aircraft_Register <>0; and HELICOPTER!Country_Helicopter=" And
    HELICOPTER!Country_Status= "And HELICOPTER!SN like '**'And
    HELICOPTER!Helicopter_Family="".

    Ma ligne renvoyée est toujours la même et mon Debug.Print WhereSQL me renvoit:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    Aircraft_Register <>0; And HELICOPTER!Flotation_Status = ''  And HELICOPTER!SN like '**'
    Aircraft_Register <> 0; And HELICOPTER!Country_Helicopter = ''  And HELICOPTER!Flotation_Status = ''  And HELICOPTER!SN like '**'  And HELICOPTER!Helicopter_Family = ''

  10. #10
    Expert éminent

    Avatar de Tofalu
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Octobre 2004
    Messages
    9 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Associations - ONG

    Informations forums :
    Inscription : Octobre 2004
    Messages : 9 501
    Par défaut
    Y a un point virgule en trop en plein milieu non ?

  11. #11
    Membre confirmé
    Inscrit en
    Avril 2006
    Messages
    175
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 175
    Par défaut
    Merci Tofalu,

    J’ai changé mon code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    SQL = "SELECT Aircraft_Register,Helicopter_Model,SN,Registration_History,Flotation_Status,Helicopter_Family,Country_Helicopter,Last_Update_Date,Last_Update_Person FROM HELICOPTER WHERE Aircraft_Register <> 0; "
    en:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    SQL = "SELECT Aircraft_Register,Helicopter_Model,SN,Registration_History,Flotation_Status,Helicopter_Family,Country_Helicopter,Last_Update_Date,Last_Update_Person FROM HELICOPTER WHERE Aircraft_Register <> 0 " 
    je n'ai plus d'erreur renvoyée mais lorsque je sélectionne un critère rien ne se passe.

  12. #12
    Membre confirmé
    Inscrit en
    Avril 2006
    Messages
    175
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 175
    Par défaut
    C'est bon ça marche , mon erreur était le alors que Aircraft_Register était de type texte donc:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Aircraft_Register <> '' "
    maintenant que ça marche sur une table je voudrais le faire sur plusieurs tables.

    voici mon code (enfin merci cafeine pour le tuto) qui marche pour une recherche multi-critère sur une table.
    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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
     
    Option Compare Database
    Private Sub chkAircraft_Register_Click()
    If Me.chkAircraft_Register Then
        Me.txtRechAircraft_Register.Visible = False
    Else
        Me.txtRechAircraft_Register.Visible = True
    End If
    RefreshQuery
    End Sub
     
    Private Sub chkFlotation_Status_Click()
    If Me.chkFlotation_Status Then
        Me.cmbRechFlotation_Status.Visible = False
    Else
        Me.cmbRechFlotation_Status.Visible = True
    End If
    RefreshQuery
    End Sub
    Private Sub chkCountry_Helicopter_Click()
    If Me.chkCountry_Helicopter Then
        Me.cmbRechCountry_Helicopter.Visible = False
    Else
        Me.cmbRechCountry_Helicopter.Visible = True
    End If
    RefreshQuery
    End Sub
     
    Private Sub chkSN_Click()
    If Me.chkSN Then
        Me.txtRechSN.Visible = False
    Else
        Me.txtRechSN.Visible = True
    End If
    RefreshQuery
    End Sub
     
    Private Sub chkHelicopter_Family_Click()
    If Me.chkHelicopter_Family Then
        Me.cmbRechHelicopter_Family.Visible = False
    Else
        Me.cmbRechHelicopter_Family.Visible = True
    End If
    RefreshQuery
    End Sub
    Private Sub cmbRechCountry_Helicopter_BeforeUpdate(Cancel As Integer)
    RefreshQuery
    End Sub
    Private Sub cmbRechFlotation_Status_BeforeUpdate(Cancel As Integer)
    RefreshQuery
    End Sub
    Private Sub cmbRechHelicopter_Family_BeforeUpdate(Cancel As Integer)
    RefreshQuery
    End Sub
    Private Sub Form_Load()
    Dim ctl As Control
    For Each ctl In Me.Controls
        Select Case Left(ctl.Name, 3)
            Case "chk"
                ctl.Value = -1
     
            Case "lbl"
                ctl.Caption = "- * - * -"
            Case "txt"
                ctl.Visible = False
                ctl.Value = ""
     
            Case "cmb"
                ctl.Visible = False
     
        End Select
    Next ctl
    Me.lstResults.RowSource = "SELECT Aircraft_Register, SN, Helicopter_Family, Flotation_Status, Country_Helicopter, Helicopter_Model, Registration_History, Last_Update_Date, Last_Update_Person FROM HELICOPTER"
    Me.lstResults.Requery
    End Sub
    Private Sub RefreshQuery()
    Dim SQL As String
    Dim SQLWhere As String
    SQL = "SELECT Aircraft_Register, SN, Helicopter_Family, Flotation_Status, Country_Helicopter, Helicopter_Model, Registration_History, Last_Update_Date, Last_Update_Person FROM HELICOPTER WHERE Aircraft_Register <> '' "
    If Not Me.chkAircraft_Register Then
        SQL = SQL & " And HELICOPTER!Aircraft_Register like '" & Me.txtRechAircraft_Register & "' "
    End If
    If Not Me.chkCountry_Helicopter Then
        SQL = SQL & " And HELICOPTER!Country_Helicopter = '" & Me.cmbRechCountry_Helicopter & "' "
    End If
    If Not Me.chkFlotation_Status Then
        SQL = SQL & " And HELICOPTER!Flotation_Status = '" & Me.cmbRechFlotation_Status & "' "
    End If
    If Not Me.chkHelicopter_Family Then
        SQL = SQL & " And HELICOPTER!Helicopter_Family = '" & Me.cmbRechHelicopter_Family & "' "
    End If
    If Not Me.chkSN Then
        SQL = SQL & " And HELICOPTER!SN like '" & Me.txtRechSN & "' "
    End If
    SQLWhere = Trim(Right(SQL, Len(SQL) - InStr(SQL, "Where ") - Len("Where ") + 1))
    SQL = SQL & ";"
    Debug.Print SQL
    Me.lblStats.Caption = DCount("*", "HELICOPTER", SQLWhere) & " / " & DCount("*", "HELICOPTER")
    Me.lstResults.RowSource = SQL
    Me.lstResults.Requery
    End Sub
     
    Private Sub lstResults_DblClick(Cancel As Integer)
    DoCmd.OpenForm "helicopter", acNormal, , "[Aircraft_Register] = '" & Me.lstResults & "'"
     
    End Sub
    Private Sub txtRechAircraft_Register_BeforeUpdate(Cancel As Integer)
    RefreshQuery
    End Sub
    Private Sub txtRechSN_BeforeUpdate(Cancel As Integer)
    RefreshQuery
    End Sub
    bon courage jeck

  13. #13
    Membre averti
    Inscrit en
    Avril 2006
    Messages
    38
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 38
    Par défaut
    Je te remercie alex.a.
    Sinon ma clé primaire est bien de type texte, mais pour l'instant cela ne fonctionne toujours pas. Je commençais à me demander si vraiment il était possible de réaliser le tuto avec une clé primaire de type texte, mais comme tu as réussi je retrouve espoir.
    Je vais regarder ton code avec attention

  14. #14
    Membre confirmé
    Inscrit en
    Août 2006
    Messages
    134
    Détails du profil
    Informations forums :
    Inscription : Août 2006
    Messages : 134
    Par défaut que faut il faire si clé est du texte
    Citation Envoyé par Alain LF Voir le message
    quelle est la valeur de "SQLWhere" ?


    essaie plutot:
    DoCmd.OpenForm "helicopter", acNormal, , "[Aircraft_Register] = '" & Me.lstResults & "'"
    ta clé étant en texte, il faut mettre le paramètre entre quote.


    Alain
    bonjour, j'ai le meme souci, que faut il faire exactement lorsque la clé primaire est de type texte ?
    jai pas trop compris les paramètre entre Quote????

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Type incompatible dans une requête
    Par tleboukaka dans le forum Bases de données
    Réponses: 1
    Dernier message: 15/10/2007, 11h59
  2. Réponses: 9
    Dernier message: 05/10/2006, 08h31
  3. requête SQL : Type incompatible
    Par Bertr@nd dans le forum VB 6 et antérieur
    Réponses: 10
    Dernier message: 20/06/2006, 11h44
  4. [VBA] [SQL] Type incompatible dans le critere
    Par mimi1 dans le forum VBA Access
    Réponses: 3
    Dernier message: 05/05/2006, 21h18
  5. [LG] Erreur de type incompatible dans assignment
    Par Tuxico dans le forum Langage
    Réponses: 4
    Dernier message: 03/12/2005, 21h06

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