Requéte SQL base access [débutant]

adrix69 Messages postés 6 Date d'inscription mardi 6 juin 2006 Statut Membre Dernière intervention 21 avril 2009 - 6 juin 2006 à 10:53
adrix69 Messages postés 6 Date d'inscription mardi 6 juin 2006 Statut Membre Dernière intervention 21 avril 2009 - 6 juin 2006 à 16:10
bonjour tout le monde, je suis débutant sur vb pourriez vous me dire pourquoi ma requéte ne marche pas merci

Private Sub Commande27_Click()
On Error GoTo Err_Commande27_Click
'
    Dim strCmd As String
    Dim nspCmd As Integer
    Dim gsiCmd As Integer
    Dim gedasCmd As Integer
    Dim laspCmd As Integer
    Dim opacCmd As Integer
   
'
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    DoCmd.OpenForm "Formulaire des procédures"
'    If Me.ref_logiciel 1 And Me.Choix_tous False Then
   
        nspCmd = 0
        gsiCmd = 0
        gedasCmd = 0
        laspCmd = 0
        opacCmd = 0
   
        If Me.Choix_nsp = True Then
            nspCmd = 2
        End If
        If Me.Choix_gsi = True Then
            gsiCmd = 1
        End If
        If Me.Choix_opac = True Then
            opacCmd = 5
        End If
        If Me.Choix_lasp = True Then
            laspCmd = 4
        End If
        If Me.Choix_gedas = True Then
            gedasCmd = 3
        End If
           
           
            strCmd = "SELECT procedure.[procedure], procedure.[ref_logiciel], procedure.[ref_type] FROM [procedure]WHERE (((procedure.[ref_logiciel])='1') AND ((procedure.[ref_type])=" & gsiCmd & " Or (procedure.[ref_type])= " & nspCmd & " Or (procedure.[ref_type])= " & gedasCmd & " Or (procedure.[ref_type])= " & laspCmd & " Or (procedure.[ref_type])= " & opacCmd & " ));"
            Forms![Formulaire des procédures].RecordSource = strCmd
    End If

3 réponses

adrix69 Messages postés 6 Date d'inscription mardi 6 juin 2006 Statut Membre Dernière intervention 21 avril 2009
6 juin 2006 à 11:44
voici le nouveau code

Private Sub Commande27_Click()
On Error GoTo Err_Commande27_Click


    Dim SQL As String
    Dim nspCmd As String
    Dim gsiCmd As String
    Dim gedasCmd As String
    Dim laspCmd As String
    Dim opacCmd As String
   
'
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    DoCmd.OpenForm "Formulaire des procédures"
'    If Me.ref_logiciel 1 And Me.Choix_tous False Then
   
        nspCmd = 0
        gsiCmd = 0
        gedasCmd = 0
        laspCmd = 0
        opacCmd = 0


    SQL = "SELECT procedure.procedure, procedure.ref_logiciel, procedure.ref_type, procedure.result_att, procedure.titre, procedure.result_obt, procedure.conclusion, procedure.refpro FROM [procedure] WHERE (((procedure.ref_logiciel)='1'))"
 If Me.Choix_nsp Then    SQL SQL & "Or procedure!ref_type '*" & nspCmd & "*' "
 End If
 If Me.Choix_gsi Then    SQL SQL & "Or procedure!ref_type '*" & gsiCmd & "*' "
 End If
 If Me.Choix_opac Then    SQL SQL & "Or procedure!ref_type '*" & opacCmd & "*' "
 End If
 If Me.Choix_lasp Then    SQL SQL & "Or procedure!ref_type '*" & laspCmd & "*' "
 End If
 If Me.Choix_gedas Then    SQL SQL & "Or procedure!ref_type '*" & gedasCmd & "*' "
 End If


 SQL = SQL & ";"
 
      Forms![Formulaire des procédures].RecordSource = SQL
       
        End If


 
0
cs_molo molo Messages postés 55 Date d'inscription lundi 14 novembre 2005 Statut Membre Dernière intervention 23 juin 2008
6 juin 2006 à 15:07
Salut,

Comme ça je vois une erreur :

Ta condition WHERE n'existe plus dans ton OR, et ça c'est pas bien

SQL="Select * From Procedure
SQL=SQL & " Where procedure.reflogiciel=1
SQL=SQL & " And procedure.ref_type = '*" & nspCmd & "*' "

SQL=SQL & " OR procedure.reflogiciel=1
SQL=SQL & " And procedure.ref_type = '*" & gsiCmd & "*' "

etc...
cela marche  comme ça !

bye


 
0
adrix69 Messages postés 6 Date d'inscription mardi 6 juin 2006 Statut Membre Dernière intervention 21 avril 2009
6 juin 2006 à 16:10
Voila mon code qui marche mais maintenant j'ai un nouveau probleme, j'aimerais ouvrir un etat avec la requéte SQL qui est généré dans ce code, comment faire svp??


<hr />
Private Sub Commande27_Click()
On Error GoTo Err_Commande27_Click


    Dim SQL As String
    Dim cmd As Boolean
   
'
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    DoCmd.OpenForm "Formulaire des procédures"
'    If Me.ref_logiciel 1 And Me.Choix_tous False Then
   


    SQL = "SELECT procedure.procedure, procedure.ref_logiciel, procedure.ref_type, procedure.result_att, procedure.titre, procedure.result_obt, procedure.conclusion, procedure.refpro FROM [procedure] WHERE (((procedure.ref_logiciel)='1'))"
 
 cmd = False
 
 If Me.Choix_nsp Then
    If cmd = True Then    SQL SQL & " Or procedure.ref_type '2'"
    Else
    cmd = True    SQL SQL & " And (procedure.ref_type '2'"
    End If
 End If


 If Me.Choix_gsi Then
    If cmd = True Then    SQL SQL & " Or procedure.ref_type '1'"
    Else
    cmd = True    SQL SQL & " And (procedure.ref_type '1'"
    End If
 End If
 
 If Me.Choix_opac Then
    If cmd = True Then    SQL SQL & " Or procedure.ref_type '5'"
    Else
    cmd = True    SQL SQL & " And (procedure.ref_type '5'"
    End If
 End If
 
 If Me.Choix_lasp Then
    If cmd = True Then    SQL SQL & " Or procedure.ref_type '4'"
    Else
    cmd = True    SQL SQL & " And (procedure.ref_type '4'"
    End If
 End If
 
 If Me.Choix_gedas Then
    If cmd = True Then    SQL SQL & " Or procedure.ref_type '3'"
    Else
    cmd = True    SQL SQL & " And (procedure.ref_type '3'"
    End If
 End If


If cmd = True Then
  SQL = SQL & ")"
End If


 SQL = SQL & ";"
 
      Forms![Formulaire des procédures].RecordSource = SQL
        End If
   
'
Exit_Commande27_Click:
    Exit Sub


Err_Commande27_Click:
    MsgBox Err.Description
    Resume Exit_Commande27_Click
   
End Sub





<hr />
0
Rejoignez-nous