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

Macros et VBA Excel Discussion :

Le "&" d'une instruction sql vba


Sujet :

Macros et VBA Excel

  1. #1
    Membre éclairé
    Homme Profil pro
    Contrôleur de Gestion
    Inscrit en
    Mars 2011
    Messages
    316
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Contrôleur de Gestion
    Secteur : Enseignement

    Informations forums :
    Inscription : Mars 2011
    Messages : 316
    Par défaut Le "&" d'une instruction sql vba
    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

  2. #2
    Rédacteur/Modérateur

    Avatar de Jean-Philippe André
    Homme Profil pro
    Architecte Power Platform, ex-Développeur VBA/C#/VB.Net
    Inscrit en
    Juillet 2007
    Messages
    14 682
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : Canada

    Informations professionnelles :
    Activité : Architecte Power Platform, ex-Développeur VBA/C#/VB.Net
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2007
    Messages : 14 682
    Par défaut
    Salut,

    en principe par d'impact

    Regarde plutot l'espace entre ) et AND (ligne 11)
    devant se transformer en
    Cycle de vie d'un bon programme :
    1/ ça fonctionne 2/ ça s'optimise 3/ ça se refactorise

    Pas de question technique par MP, je ne réponds pas

    Mes ouvrages :
    Migrer les applications VBA Access et VBA Excel vers la Power Platform
    Apprendre à programmer avec Access 2016, Access 2019 et 2021

    Apprendre à programmer avec VBA Excel
    Prise en main de Dynamics 365 Business Central

    Coffrets disponibles de mes ouvrages : https://www.editions-eni.fr/jean-philippe-andre
    Pensez à consulter la FAQ Excel et la FAQ Access

    Derniers tutos
    Excel et les paramètres régionaux
    Les fichiers Excel binaires : xlsb,

    Autres tutos

  3. #3
    Expert confirmé
    Homme Profil pro
    aucune
    Inscrit en
    Avril 2016
    Messages
    7 563
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 84
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : aucune

    Informations forums :
    Inscription : Avril 2016
    Messages : 7 563
    Par défaut
    Bonjour,
    une simble :
    te montrera le texte que contient ta requête :
    crois-tu vraiment que la chaîne de caractères :
    'Heures Improd Fixe & Polyvalence'
    peut être un critère de recherche ?
    Ton problème n'est avant toute autre chose rien d'autre que la construction, par concaténation, de la chaine de caractères qu'est ta variable strSQL.

  4. #4
    Invité
    Invité(e)
    Par défaut
    bonjour,
    car je suis à peu près certain que le code suivant qui ne fonctionne pas est lié à ce fameux &
    et mois car je suis à peu près certain que ta requête c'est n'importe quoi!
    (T_MPHImprod.[Service Origine] Like '" & "*variable" & "'

    le Like en DAO (comme dans Access) c'est Like '*valeur', en ADO c'est Like '%valeur'!

    ici (
    "*variable") nous n'avons pas une variable mais une string!

    (T_MPHImprod.[Service Origine] Like '%" & variable & "' que représente zur et Distribution variable et "Heures Improd Fixe & Polyvalence?
    si ce sont des champs de ta table!

    "WHERE (((T_MPHImprod.[Service Origine] Like '%" & variable & "' )AND (T_NatureHeuresImprod.AgrégatFormulaireRH = [Heures Improd Fixe] & [Polyvalence])"




    strSQL = strSQL & "OR ((T_MPHImprod.[Service Origine]=[zur] ) And (T_MPHImprod.[Service Origine]<>[Distribution variable]
    Dernière modification par Invité ; 23/11/2016 à 13h48.

  5. #5
    Membre éclairé
    Homme Profil pro
    Contrôleur de Gestion
    Inscrit en
    Mars 2011
    Messages
    316
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Contrôleur de Gestion
    Secteur : Enseignement

    Informations forums :
    Inscription : Mars 2011
    Messages : 316
    Par défaut
    dysorthographie

    Ci joint le SQL de la requête Access

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    SELECT T_MPHImprod.Semaine, T_MPHImprod.[Nature Improd], T_MPHImprod.Heures, T_Base.Ets
    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.Semaine)=45) AND ((T_MPHImprod.[Service Origine]) Like "*variable") AND ((T_Base.Ets)=955059) AND ((T_NatureHeuresImprod.AgrégatFormulaireRH)="Heures Improd Fixe & Polyvalence")) OR (((T_MPHImprod.Semaine)=45) AND ((T_MPHImprod.[Service Origine])="zur" And (T_MPHImprod.[Service Origine])<>"Distribution variable") AND ((T_Base.Ets)=955059) AND ((T_NatureHeuresImprod.AgrégatFormulaireRH)="Heures Improd Fixe & Polyvalence"));

  6. #6
    Invité
    Invité(e)
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    strSQL = "SELECT T_MPHImprod.Semaine, T_MPHImprod.[Nature Improd], T_MPHImprod.Heures, T_Base.Ets"
    strSQL = strSQL & " FROM T_Base INNER JOIN (T_NatureHeuresImprod INNER JOIN T_MPHImprod "
    strSQL = strSQL & " ON T_NatureHeuresImprod.Nature = T_MPHImprod.[Nature Improd]) "
    strSQL = strSQL & " ON T_Base.Ets = T_MPHImprod.Base"
    strSQL = strSQL & " WHERE (((T_MPHImprod.Semaine)=45) AND "
    strSQL = strSQL & " ((T_MPHImprod.[Service Origine]) Like '%variable')"
    strSQL = strSQL & "  AND ((T_Base.Ets)=955059) "
    strSQL = strSQL & " AND ((T_NatureHeuresImprod.AgrégatFormulaireRH)='Heures Improd Fixe & Polyvalence')) "
    strSQL = strSQL & " OR (((T_MPHImprod.Semaine)=45) AND ((T_MPHImprod.[Service Origine])='zur' "
    strSQL = strSQL & " And (T_MPHImprod.[Service Origine])<>'Distribution variable') AND ((T_Base.Ets)=955059) "
    strSQL = strSQL & " AND ((T_NatureHeuresImprod.AgrégatFormulaireRH)='Heures Improd Fixe & Polyvalence'));"
    tu peux simplifier ta close where!
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    strSQL = strSQL & " WHERE T_MPHImprod.Semaine=45 "
    strSQL = strSQL & " AND T_Base.Ets=955059 "
    strSQL = strSQL & " AND T_NatureHeuresImprod.AgrégatFormulaireRH='Heures Improd Fixe & Polyvalence' "
    strSQL = strSQL & " AND (T_MPHImprod.[Service Origine] Like '%variable' "
    strSQL = strSQL & "     OR T_MPHImprod.[Service Origine]='zur'   "
    strSQL = strSQL & "     OR T_MPHImprod.[Service Origine]<>'Distribution variable'"
    strSQL = strSQL & "     ) "
    note cependant que '%variable' c'est bien déferrant de 'Distribution variable'
    Dernière modification par Invité ; 23/11/2016 à 14h38.

  7. #7
    Membre éclairé
    Homme Profil pro
    Contrôleur de Gestion
    Inscrit en
    Mars 2011
    Messages
    316
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Contrôleur de Gestion
    Secteur : Enseignement

    Informations forums :
    Inscription : Mars 2011
    Messages : 316
    Par défaut
    note cependant que '%variable' c'est bien déferrant de 'Distribution variable'
    Oui on est bien d'accord car il y a trois critères :
    Terrain (Fixe/Variable)
    Distribution (Fixe/Variable)
    Structure (Fixe)

    J'essaye de reprendre ta réponse mais en incluant les variables

    xHpoly(Optional ByVal Etb As Double, _
    Optional ByVal Semaine As Double)


    à la place de

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    strSQL = strSQL & " ON T_Base.Ets = T_MPHImprod.Base"
    strSQL = strSQL & " WHERE (((T_MPHImprod.Semaine)=45) AND "
    J'obtiens valeur


    Je vais trouver la solution

    mais voici ce que j'ai rectifié au cas où

    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
    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 ( 1=1"
     
     
     
     
     
        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 & " AND (T_NatureHeuresImprod.AgrégatFormulaireRH = '" & "Heures Improd Fixe & Polyvalence" & "')"
        strSQL = strSQL & " AND ((T_MPHImprod.[Service Origine] Like '" & "%variable" & "')"
        strSQL = strSQL & " OR (T_MPHImprod.[Service Origine] = '" & "zur" & "')"
        strSQL = strSQL & " OR (T_MPHImprod.[Service Origine] <> '" & "Distribution variable" & "'))"
     
     
        MsgBox strSQL
     
        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

  8. #8
    Invité
    Invité(e)
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    strSQL = strSQL & " WHERE (((T_MPHImprod.Semaine)=" & replace(cstr(Semaine),",",".") & ") AND "
    sur les parametre optionnal tu peux mettres des valeur par défaut! dans certains cas c'est obligatoire!

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    PublicFunction xHpoly(OptionalByVal Etb As Double =22, _
                                        Optional ByVal Semaine As Double=1)

  9. #9
    Membre éclairé
    Homme Profil pro
    Contrôleur de Gestion
    Inscrit en
    Mars 2011
    Messages
    316
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Contrôleur de Gestion
    Secteur : Enseignement

    Informations forums :
    Inscription : Mars 2011
    Messages : 316
    Par défaut
    dysorthographie

    Merci pour ce retour

    En fait je crois savoir ce qui bloque.
    Ce doit être les variables de la déclaration et plus précisément "ETb" qui doit être en conflit avec les autres sub function
    Ce qui m'amène à affirmer cela, c'est que j'ai essayé la Sub que tu m'as fourni

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    strSQL = "SELECT T_MPHImprod.Semaine, T_MPHImprod.[Nature Improd], T_MPHImprod.Heures, T_Base.Ets"
    strSQL = strSQL & " FROM T_Base INNER JOIN (T_NatureHeuresImprod INNER JOIN T_MPHImprod "
    strSQL = strSQL & " ON T_NatureHeuresImprod.Nature = T_MPHImprod.[Nature Improd]) "
    strSQL = strSQL & " ON T_Base.Ets = T_MPHImprod.Base"
    strSQL = strSQL & " WHERE (((T_MPHImprod.Semaine)=45) AND "
    strSQL = strSQL & " ((T_MPHImprod.[Service Origine]) Like '%variable')"
    strSQL = strSQL & "  AND ((T_Base.Ets)=955059) "
    strSQL = strSQL & " AND ((T_NatureHeuresImprod.AgrégatFormulaireRH)='Heures Improd Fixe & Polyvalence')) "
    strSQL = strSQL & " OR (((T_MPHImprod.Semaine)=45) AND ((T_MPHImprod.[Service Origine])='zur' "
    strSQL = strSQL & " And (T_MPHImprod.[Service Origine])<>'Distribution variable') AND ((T_Base.Ets)=955059) "
    strSQL = strSQL & " AND ((T_NatureHeuresImprod.AgrégatFormulaireRH)='Heures Improd Fixe & Polyvalence'));"
    et elle fonctionne. Dès que j'essaye de remplacer
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    strSQL = strSQL & "  AND ((T_Base.Ets)=955059) "
    par

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    strSQL = strSQL & "  AND ((T_Base.Ets = 955000+" & Etb & ") "
    ça coince!!

    voici l'ensemble des sub

    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
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    Public Function xHint(Optional ByVal Etb As Double, _
                                 Optional ByVal Activité As String = vbNullString, _
                                        Optional ByVal FV As String = vbNullString, _
                                                                Optional ByVal Semaine As Double)
     
     
        Dim rec As New ADODB.Recordset
        Dim strSQL As String
     
     
        'Redaction du SQL
        strSQL = "SELECT Sum(T_Intérims.[Nombre d'heures])  AS  Montant " & _
                 "FROM T_SemaineTDBHebdo INNER JOIN T_Intérims ON T_SemaineTDBHebdo.[N° Semaine] = T_Intérims.Semaine WHERE 1=1"
     
        If Semaine > 0 Then
            strSQL = strSQL & " And ([T_Intérims.Semaine] = " & Replace(CStr(Semaine), ",", ".") & ")"
        End If
     
        If Etb > 0 Then
            strSQL = strSQL & " And ([T_Intérims.Etablissement] = 955000+" & Etb & ")"
        End If
     
        If Len(Activité) > 0 Then
            strSQL = strSQL & " And ([T_Intérims.Activité] = '" & Activité & "')"
        End If
     
        If Len(FV) > 0 Then
            strSQL = strSQL & " And (T_Intérims.[F/V] = '" & FV & "')"
        End If
     
     
        Dim rst As New ADODB.Recordset
     
        rst.Open strSQL, cnx
     
        On Error GoTo errH01
        rst.MoveFirst
     
        xHint = CDbl(rst("Montant"))
     
        rst.Close
        Set rst = Nothing
        Exit Function
     
    errH01:
     
        Err.Clear
        xHint = 0
        rst.Close
        Set rst = Nothing
     
     
    End Function
     
    Public Function xVint(Optional ByVal Etb As Double, _
                                 Optional ByVal Activité As String = vbNullString, _
                                        Optional ByVal FV As String = vbNullString, _
                                                                Optional ByVal Semaine As Double)
     
     
        Dim rec As New ADODB.Recordset
        Dim strSQL As String
     
     
        'Redaction du SQL
        strSQL = "SELECT Sum(T_Intérims.[Montant payé])  AS  Montant " & _
                 "FROM T_SemaineTDBHebdo INNER JOIN T_Intérims ON T_SemaineTDBHebdo.[N° Semaine] = T_Intérims.Semaine WHERE 1=1"
     
        If Semaine > 0 Then
            strSQL = strSQL & " And ([T_Intérims.Semaine] = " & Replace(CStr(Semaine), ",", ".") & ")"
        End If
     
        If Etb > 0 Then
            strSQL = strSQL & " And ([T_Intérims.Etablissement] = 955000+" & Etb & ")"
        End If
     
        If Len(Activité) > 0 Then
            strSQL = strSQL & " And ([T_Intérims.Activité] = '" & Activité & "')"
        End If
     
        If Len(FV) > 0 Then
            strSQL = strSQL & " And (T_Intérims.[F/V] = '" & FV & "')"
        End If
     
     
        Dim rst As New ADODB.Recordset
     
        rst.Open strSQL, cnx
     
        On Error GoTo errH01
        rst.MoveFirst
     
        xVint = CDbl(rst("Montant"))
     
        rst.Close
        Set rst = Nothing
        Exit Function
     
    errH01:
     
        Err.Clear
        xVint = 0
        rst.Close
        Set rst = Nothing
     
     
    End Function
    Public Function xColis(Optional ByVal Site As Double, _
                                Optional ByVal Semaine As Double)
     
     
        Dim rec As New ADODB.Recordset
        Dim strSQL As String
     
     
        'Redaction du SQL
        strSQL = "SELECT Sum(T_MPHProd.UO) AS  Montant " & _
                 "FROM T_CorrCircuit INNER JOIN T_MPHProd ON T_CorrCircuit.CodeCircuitInformatique = T_MPHProd.[Code Circuit regroupé] WHERE (T_MPHProd.Entrepot <>'" & "MG" & "') And (T_CorrCircuit.[Agrégat Activité]='" & "preparation" & "') And (T_CorrCircuit.[Agrégat ActivitéBis]='" & "preparation" & "')"
     
        If Semaine > 0 Then
            strSQL = strSQL & " And (T_MPHProd.Semaine = " & Replace(CStr(Semaine), ",", ".") & ")"
        End If
     
        If Site > 0 Then
            strSQL = strSQL & " And (T_MPHProd.[Nom Base] = 955000+" & Site & ")"
        End If
     
     
     
     
     
        Dim rst As New ADODB.Recordset
     
        rst.Open strSQL, cnx
     
        On Error GoTo errH01
        rst.MoveFirst
     
        xColis = CDbl(rst("Montant"))
     
        rst.Close
        Set rst = Nothing
        Exit Function
     
    errH01:
     
        Err.Clear
        xColis = 0
        rst.Close
        Set rst = Nothing
     
     
    End Function
     
    Public Function xZur(Optional ByVal Site As Double, _
                                Optional ByVal Semaine As Double)
     
     
        Dim rec As New ADODB.Recordset
        Dim strSQL As String
     
     
        'Redaction du SQL
        strSQL = "SELECT Sum(T_MPHProd.UO) AS  Montant " & _
                 "FROM T_CorrCircuit INNER JOIN T_MPHProd ON T_CorrCircuit.CodeCircuitInformatique = T_MPHProd.[Code Circuit regroupé] WHERE (T_MPHProd.Entrepot <>'" & "MG" & "') And (T_CorrCircuit.[Agrégat Activité]='" & "preparation" & "') And (T_CorrCircuit.[Agrégat ActivitéBis]='" & "preparationzur" & "')"
     
        If Semaine > 0 Then
            strSQL = strSQL & " And (T_MPHProd.Semaine = " & Replace(CStr(Semaine), ",", ".") & ")"
        End If
     
        If Site > 0 Then
            strSQL = strSQL & " And (T_MPHProd.[Nom Base] = 955000+" & Site & ")"
        End If
     
     
     
     
     
        Dim rst As New ADODB.Recordset
     
        rst.Open strSQL, cnx
     
        On Error GoTo errH01
        rst.MoveFirst
     
        xZur = CDbl(rst("Montant"))
     
        rst.Close
        Set rst = Nothing
        Exit Function
     
    errH01:
     
        Err.Clear
        xZur = 0
        rst.Close
        Set rst = Nothing
     
     
    End Function
     
    Public Function xEqcC(Optional ByVal Base As String = vbNullString, _
                                        Optional ByVal Semaine As Double)
     
     
        Dim rec As New ADODB.Recordset
        Dim strSQL As String
     
     
        'Redaction du SQL
        strSQL = "SELECT Sum(U_CoefRemplissage.EQC) AS  Montant " & _
                 "FROM U_CoefRemplissage WHERE U_CoefRemplissage.Activite Not In ('" & "zur" & "','" & "zur+mea" & "')"
     
        If Semaine > 0 Then
            strSQL = strSQL & " And ([Semaine] = " & Replace(CStr(Semaine), ",", ".") & ")"
        End If
     
        If Len(Base) > 0 Then
            strSQL = strSQL & " And ([Nom Base] = 955000+'" & Base & "')"
        End If
     
     
        Dim rst As New ADODB.Recordset
     
        rst.Open strSQL, cnx
     
        On Error GoTo errH01
        rst.MoveFirst
     
        xEqcC = CDbl(rst("Montant"))
     
        rst.Close
        Set rst = Nothing
        Exit Function
     
    errH01:
     
        Err.Clear
        xEqcC = 0
        rst.Close
        Set rst = Nothing
     
     
    End Function
    Public Function xEqc(Optional ByVal Base As String = vbNullString, _
                                        Optional ByVal Semaine As Double)
     
     
        Dim rec As New ADODB.Recordset
        Dim strSQL As String
     
     
        'Redaction du SQL
        strSQL = "SELECT Sum(U_CoefRemplissage.EQC) AS  Montant " & _
                 "FROM U_CoefRemplissage WHERE 1=1"
     
        If Semaine > 0 Then
            strSQL = strSQL & " And ([Semaine] = " & Replace(CStr(Semaine), ",", ".") & ")"
        End If
     
        If Len(Base) > 0 Then
            strSQL = strSQL & " And ([Nom Base] = 955000+'" & Base & "')"
        End If
     
     
        Dim rst As New ADODB.Recordset
     
        rst.Open strSQL, cnx
     
        On Error GoTo errH01
        rst.MoveFirst
     
        xEqc = CDbl(rst("Montant"))
     
        rst.Close
        Set rst = Nothing
        Exit Function
     
    errH01:
     
        Err.Clear
        xEqc = 0
        rst.Close
        Set rst = Nothing
     
     
    End Function
     
    Public Function xPal(Optional ByVal Site As Double, _
                                Optional ByVal Semaine As Double)
     
     
        Dim rec As New ADODB.Recordset
        Dim strSQL As String
     
     
        'Redaction du SQL
        strSQL = "SELECT Sum(T_MPHProd.UO) AS  Montant " & _
                 "FROM T_CorrCircuit INNER JOIN T_MPHProd ON T_CorrCircuit.CodeCircuitInformatique = T_MPHProd.[Code Circuit regroupé] WHERE (T_MPHProd.Entrepot <>'" & "MG" & "') And (T_CorrCircuit.[Agrégat Activité]='" & "reception" & "')"
     
        If Semaine > 0 Then
            strSQL = strSQL & " And (T_MPHProd.Semaine = " & Replace(CStr(Semaine), ",", ".") & ")"
        End If
     
        If Site > 0 Then
            strSQL = strSQL & " And (T_MPHProd.[Nom Base] = 955000+" & Site & ")"
        End If
     
     
     
     
     
        Dim rst As New ADODB.Recordset
     
        rst.Open strSQL, cnx
     
        On Error GoTo errH01
        rst.MoveFirst
     
        xPal = CDbl(rst("Montant"))
     
        rst.Close
        Set rst = Nothing
        Exit Function
     
    errH01:
     
        Err.Clear
        xPal = 0
        rst.Close
        Set rst = Nothing
     
     
    End Function
    Public Function xStock(Optional ByVal Site As Double, _
                                Optional ByVal Semaine As Double)
     
     
        Dim rec As New ADODB.Recordset
        Dim strSQL As String
     
     
        'Redaction du SQL
        strSQL = "SELECT Sum(T_MPHProd.UO) AS  Montant " & _
                 "FROM T_CorrCircuit INNER JOIN T_MPHProd ON T_CorrCircuit.CodeCircuitInformatique = T_MPHProd.[Code Circuit regroupé] WHERE (T_MPHProd.Entrepot <>'" & "MG" & "') And (T_CorrCircuit.[Agrégat Activité]='" & "stockage" & "')"
     
        If Semaine > 0 Then
            strSQL = strSQL & " And (T_MPHProd.Semaine = " & Replace(CStr(Semaine), ",", ".") & ")"
        End If
     
        If Site > 0 Then
            strSQL = strSQL & " And (T_MPHProd.[Nom Base] = 955000+" & Site & ")"
        End If
     
     
     
     
     
        Dim rst As New ADODB.Recordset
     
        rst.Open strSQL, cnx
     
        On Error GoTo errH01
        rst.MoveFirst
     
        xStock = CDbl(rst("Montant"))
     
        rst.Close
        Set rst = Nothing
        Exit Function
     
    errH01:
     
        Err.Clear
        xStock = 0
        rst.Close
        Set rst = Nothing
     
     
    End Function
     
    Public Function xDStock(Optional ByVal Site As Double, _
                                Optional ByVal Semaine As Double)
     
     
        Dim rec As New ADODB.Recordset
        Dim strSQL As String
     
     
        'Redaction du SQL
        strSQL = "SELECT Sum(T_MPHProd.UO) AS  Montant " & _
                 "FROM T_CorrCircuit INNER JOIN T_MPHProd ON T_CorrCircuit.CodeCircuitInformatique = T_MPHProd.[Code Circuit regroupé] WHERE (T_MPHProd.Entrepot <>'" & "MG" & "') And (T_CorrCircuit.[Agrégat Activité]='" & "destockage" & "')"
     
        If Semaine > 0 Then
            strSQL = strSQL & " And (T_MPHProd.Semaine = " & Replace(CStr(Semaine), ",", ".") & ")"
        End If
     
        If Site > 0 Then
            strSQL = strSQL & " And (T_MPHProd.[Nom Base] = 955000+" & Site & ")"
        End If
     
     
     
     
     
        Dim rst As New ADODB.Recordset
     
        rst.Open strSQL, cnx
     
        On Error GoTo errH01
        rst.MoveFirst
     
        xDStock = CDbl(rst("Montant"))
     
        rst.Close
        Set rst = Nothing
        Exit Function
     
    errH01:
     
        Err.Clear
        xDStock = 0
        rst.Close
        Set rst = Nothing
     
     
    End Function
     
     
    Public Function xProd(Optional ByVal Site As Double, _
                                Optional ByVal Semaine As Double)
     
     
        Dim rec As New ADODB.Recordset
        Dim strSQL As String
     
     
        'Redaction du SQL
        strSQL = "SELECT Sum(T_MPHProd.[Heures Prod]) AS  Montant " & _
                 "FROM T_CorrCircuit INNER JOIN T_MPHProd ON T_CorrCircuit.CodeCircuitInformatique = T_MPHProd.[Code Circuit regroupé] WHERE (T_MPHProd.Entrepot <>'" & "MG" & "') And (T_CorrCircuit.[Agrégat Activité]='" & "preparation" & "') And (T_CorrCircuit.[Agrégat ActivitéBis]='" & "preparation" & "')"
     
        If Semaine > 0 Then
            strSQL = strSQL & " And (T_MPHProd.Semaine = " & Replace(CStr(Semaine), ",", ".") & ")"
        End If
     
        If Site > 0 Then
            strSQL = strSQL & " And (T_MPHProd.[Nom Base] = 955000+" & Site & ")"
        End If
     
     
     
     
     
        Dim rst As New ADODB.Recordset
     
        rst.Open strSQL, cnx
     
        On Error GoTo errH01
        rst.MoveFirst
     
        xProd = CDbl(rst("Montant"))
     
        rst.Close
        Set rst = Nothing
        Exit Function
     
    errH01:
     
        Err.Clear
        xProd = 0
        rst.Close
        Set rst = Nothing
     
     
    End Function
    Public Function xColisCircuit(Optional ByVal Site As Double, _
                                        Optional ByVal Semaine As Double, _
                                            Optional ByVal Circuit As String = vbNullString)
     
     
        Dim rec As New ADODB.Recordset
        Dim strSQL As String
     
     
        'Redaction du SQL
        strSQL = "SELECT Sum(T_MPHProd.UO) AS  Montant " & _
                 "FROM T_CorrCircuit INNER JOIN T_MPHProd ON T_CorrCircuit.CodeCircuitInformatique = T_MPHProd.[Code Circuit regroupé] WHERE (T_MPHProd.Entrepot <>'" & "MG" & "') And (T_CorrCircuit.[Agrégat Activité]='" & "preparation" & "') And (T_CorrCircuit.[Agrégat ActivitéBis]='" & "preparation" & "')"
     
        If Semaine > 0 Then
            strSQL = strSQL & " And (T_MPHProd.Semaine = " & Replace(CStr(Semaine), ",", ".") & ")"
        End If
     
        If Site > 0 Then
            strSQL = strSQL & " And (T_MPHProd.[Nom Base] = 955000+" & Site & ")"
        End If
     
        If Len(Circuit) > 0 Then
            strSQL = strSQL & " And (T_CorrCircuit.Activité = '" & Circuit & "')"
        End If
     
     
     
     
        Dim rst As New ADODB.Recordset
     
        rst.Open strSQL, cnx
     
        On Error GoTo errH01
        rst.MoveFirst
     
        xColisCircuit = CDbl(rst("Montant"))
     
        rst.Close
        Set rst = Nothing
        Exit Function
     
    errH01:
     
        Err.Clear
        xColisCircuit = 0
        rst.Close
        Set rst = Nothing
     
     
    End Function
     
    Public Function xProdCircuit(Optional ByVal Site As Double, _
                                        Optional ByVal Semaine As Double, _
                                            Optional ByVal Circuit As String = vbNullString)
     
     
        Dim rec As New ADODB.Recordset
        Dim strSQL As String
     
     
        'Redaction du SQL
        strSQL = "SELECT Sum(T_MPHProd.[Heures Prod]) AS  Montant " & _
                 "FROM T_CorrCircuit INNER JOIN T_MPHProd ON T_CorrCircuit.CodeCircuitInformatique = T_MPHProd.[Code Circuit regroupé] WHERE (T_MPHProd.Entrepot <>'" & "MG" & "') And (T_CorrCircuit.[Agrégat Activité]='" & "preparation" & "') And (T_CorrCircuit.[Agrégat ActivitéBis]='" & "preparation" & "')"
     
        If Semaine > 0 Then
            strSQL = strSQL & " And (T_MPHProd.Semaine = " & Replace(CStr(Semaine), ",", ".") & ")"
        End If
     
        If Site > 0 Then
            strSQL = strSQL & " And (T_MPHProd.[Nom Base] = 955000+" & Site & ")"
        End If
     
        If Len(Circuit) > 0 Then
            strSQL = strSQL & " And (T_CorrCircuit.Activité = '" & Circuit & "')"
        End If
     
     
     
     
        Dim rst As New ADODB.Recordset
     
        rst.Open strSQL, cnx
     
        On Error GoTo errH01
        rst.MoveFirst
     
        xProdCircuit = CDbl(rst("Montant"))
     
        rst.Close
        Set rst = Nothing
        Exit Function
     
    errH01:
     
        Err.Clear
        xProdCircuit = 0
        rst.Close
        Set rst = Nothing
     
     
    End Function
     
    Public Function xEqcCircuit(Optional ByVal Base As String = vbNullString, _
                                        Optional ByVal Semaine As Double, _
                                                Optional ByVal Circuit As String = vbNullString)
     
     
        Dim rec As New ADODB.Recordset
        Dim strSQL As String
     
     
        'Redaction du SQL
        strSQL = "SELECT Sum(U_CoefRemplissage.EQC) AS  Montant " & _
                 "FROM U_CoefRemplissage WHERE U_CoefRemplissage.Activite Not In ('" & "zur" & "','" & "zur+mea" & "')"
     
        If Semaine > 0 Then
            strSQL = strSQL & " And ([Semaine] = " & Replace(CStr(Semaine), ",", ".") & ")"
        End If
     
        If Len(Base) > 0 Then
            strSQL = strSQL & " And ([Nom Base] = 955000+'" & Base & "')"
        End If
     
        If Len(Circuit) > 0 Then
            strSQL = strSQL & " And (U_CoefRemplissage.Activite = '" & Circuit & "')"
        End If
     
        Dim rst As New ADODB.Recordset
     
        rst.Open strSQL, cnx
     
        On Error GoTo errH01
        rst.MoveFirst
     
        xEqcCircuit = CDbl(rst("Montant"))
     
        rst.Close
        Set rst = Nothing
        Exit Function
     
    errH01:
     
        Err.Clear
        xEqcCircuit = 0
        rst.Close
        Set rst = Nothing
     
     
    End Function
    Ne faut-il pas que "ETb" soit réinitialisé?

  10. #10
    Membre éclairé
    Homme Profil pro
    Contrôleur de Gestion
    Inscrit en
    Mars 2011
    Messages
    316
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Contrôleur de Gestion
    Secteur : Enseignement

    Informations forums :
    Inscription : Mars 2011
    Messages : 316
    Par défaut
    Je suis désolé de relancer ce post mais je voudrais juste savoir sur ma question précédente si la variable "Etb"doit être réinitialisée car j'ai l'impression ( et ce n'est peut être qu'une impression) que la variable "ETb" garde en mémoire la valeur calculée sur la liste des Sub Function détaillées sur la discussion précédente

    C'est juste pour m'aiguiller et ne pas me focaliser sur un point qui n'est pas forcément celui que je crois.

Discussions similaires

  1. récupérer une instruction sql
    Par oracliste dans le forum Oracle
    Réponses: 2
    Dernier message: 09/11/2006, 11h41
  2. Remplacer l'instruction GO par une instruction SQL
    Par Sytchev3 dans le forum MS SQL Server
    Réponses: 14
    Dernier message: 06/04/2006, 09h28
  3. Passer de la zone d'édition vers une instruction sql
    Par tripper.dim dans le forum C++Builder
    Réponses: 2
    Dernier message: 27/11/2002, 14h44

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