Bonjour,

Question concernant le "&"

Il y a celui qui sépare bien l'instruction et le critère séparé par des quotes ou guillemets.
Mais comment différencier le & à l'intérieur d'un critère

car je suis à peu près certain que le code suivant qui ne fonctionne pas est lié à ce fameux & (& du critère :"Heures Improd Fixe & Polyvalence")

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
Public Function xHpoly(Optional ByVal Etb As Double, _
                                    Optional ByVal Semaine As Double)
 
    Dim rec As New ADODB.Recordset
    Dim strSQL As String
 
 
    'Redaction du SQL
    strSQL = "SELECT Sum(T_MPHImprod.Heures) AS  Montant " & _
             "FROM T_Base INNER JOIN (T_NatureHeuresImprod INNER JOIN T_MPHImprod ON T_NatureHeuresImprod.Nature = T_MPHImprod.[Nature Improd]) ON T_Base.Ets = T_MPHImprod.Base" & _
             "WHERE (((T_MPHImprod.[Service Origine] Like '" & "*variable" & "' )AND (T_NatureHeuresImprod.AgrégatFormulaireRH ='" & "Heures Improd Fixe & Polyvalence" & "')"
 
    If Semaine > 0 Then
        strSQL = strSQL & " And (MPHImprod.Semaine = " & Replace(CStr(Semaine), ",", ".") & ")"
    End If
 
    If Etb > 0 Then
        strSQL = strSQL & " And (T_Base.Ets = 955000+" & Etb & "))"
    End If
 
        strSQL = strSQL & "OR ((T_MPHImprod.[Service Origine]='" & "zur" & "' )And (T_MPHImprod.[Service Origine]<>'" & "Distribution variable" & "' )And (T_NatureHeuresImprod.AgrégatFormulaireRH='" & "Heures Improd Fixe & Polyvalence" & "')"
 
    If Semaine > 0 Then
        strSQL = strSQL & " And (MPHImprod.Semaine = " & Replace(CStr(Semaine), ",", ".") & ")"
    End If
 
    If Etb > 0 Then
        strSQL = strSQL & " And (T_Base.Ets = 955000+" & Etb & ")))"
    End If
 
    Dim rst As New ADODB.Recordset
 
    rst.Open strSQL, cnx
 
    On Error GoTo errH01
    rst.MoveFirst
 
    xHpoly = CDbl(rst("Montant"))
 
    rst.Close
    Set rst = Nothing
    Exit Function
 
errH01:
 
    Err.Clear
    xHpoly = 0
    rst.Close
    Set rst = Nothing
 
 
End Function

Ligne 11 et 21
Merci de votre aide