bonjour,

j'ai converti une macro parce que dans mes conditions, access me bloque au niveau de ma longueur de phrase (c'est un peu pénible).

le problème c'est que je n'y connais pas grand choses aux codes...

mon soucis, j'aimerai pouvoir attribuer à un bouton mon code. j'ai pu voir que le bouton par défaut me propose une procédure en Sub et non en function (function est la procédure convertie de ma macro). Alors comment faire pour que mon bouton puisse lire ce code ?

J'ai déjà essayé de remplace ma function par une sub... mais sans réussite. j'ai essayé aussi de mettre function commande1 click() ne marche pas non plus

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
 
'------------------------------------------------------------
' M_F_1_Creer_Coswin_av_Correspondance_coswin
'
'------------------------------------------------------------
Function M_F_1_Creer_Coswin_av_Correspondance_coswin()
On Error GoTo M_F_1_Creer_Coswin_av_Correspondance_coswin_Err
 
' #### Conditions code fournisseur ####
    If (Forms!F_F_0_Creer_Coswin_av_Correspondance_Coswin!ID_TMP <> Forms!F_F_0_Creer_Coswin_av_Correspondance_Coswin!Modifiable52) Then
        ' ID <>Modifiable52  coché
        Forms!F_F_0_Creer_Coswin_av_Correspondance_Coswin!Créer_New_Fournisseur_Usine = -1
    End If
    If (Eval("[Forms]![F_F_0_Creer_Coswin_av_Correspondance_Coswin]![Modifiable52] Is Null")) Then
        ' Modifiable est null
        Forms!F_F_0_Creer_Coswin_av_Correspondance_Coswin!Créer_New_Fournisseur_Usine = 0
    End If
    If (Forms!F_F_0_Creer_Coswin_av_Correspondance_Coswin!ID_TMP = Forms!F_F_0_Creer_Coswin_av_Correspondance_Coswin!Modifiable52) Then
        ' ID=Modifiable       pas coché
        Forms!F_F_0_Creer_Coswin_av_Correspondance_Coswin!Créer_New_Fournisseur_Usine = 0
    End If
 
' #### Conditions Ref fournisseur ####
    If (Eval("[Forms]![F_F_0_Creer_Coswin_av_Correspondance_Coswin]![Référence_Fournisseur_Usine] Is Null")) Then
        ' Erreur Ref four + code four est null
        MsgBox "Vous n'avez pas remplie la référence fournisseur et le code fournisseur", vbCritical, ""
    End If
    ' ref four
    DoCmd.GoToControl "Référence_Fournisseur_Usine"
    If (Eval("[Forms]![F_F_0_Creer_Coswin_av_Correspondance_Coswin]![Référence_Fournisseur_Usine] Is Null And [Forms]![F_F_0_Creer_Coswin_av_Correspondance_Coswin]![Modifiable52] Is Not Null")) Then
        Exit Function
    End If
 
    If (Eval("[Forms]![F_F_0_Creer_Coswin_av_Correspondance_Coswin]![Référence_Fournisseur_Usine] Is Not Null And [Forms]![F_F_0_Creer_Coswin_av_Correspondance_Coswin]![Modifiable52] Is Null")) Then
        ' Erreur Ref four non null et code four null
        MsgBox "Vous n'avez pas de code fournisseur valide !", vbCritical, ""
    End If
    'liste déroulante'
    DoCmd.GoToControl "Modifiable52"
    If (Eval("[Forms]![F_F_0_Creer_Coswin_av_Correspondance_Coswin]![Référence_Fournisseur_Usine] Is Not Null And [Forms]![F_F_0_Creer_Coswin_av_Correspondance_Coswin]![Modifiable52] Is Null")) Then
        Exit Function
    End If
 
    If (Eval("[Forms]![F_F_0_Creer_Coswin_av_Correspondance_Coswin]![Référence_Fournisseur_Usine] Is Not Null And [Forms]![F_F_0_Creer_Coswin_av_Correspondance_Coswin]![Modifiable52] Is Not Null And [Forms]![F_F_0_Creer_Coswin_av_Correspondance_Coswin]![Modifiable52]=[Forms]![F_F_0_Creer_Coswin_av_Correspondance_Coswin]![code four]")) Then
        ' ref four non null et code four non null et qui est = au groupe
        MsgBox "Vous ne pouvez pas avoir pour un même code fournisseur et une référence différente que celle du groupe", vbCritical, ""
    End If
    DoCmd.GoToControl "Référence_Fournisseur_Usine"
    If (Eval("[Forms]![F_F_0_Creer_Coswin_av_Correspondance_Coswin]![Référence_Fournisseur_Usine] Is Not Null And [Forms]![F_F_0_Creer_Coswin_av_Correspondance_Coswin]![Modifiable52] Is Not Null And [Forms]![F_F_0_Creer_Coswin_av_Correspondance_Coswin]![Modifiable52]=[Forms]![F_F_0_Creer_Coswin_av_Correspondance_Coswin]![code four]")) Then
        Exit Function
    End If
 
    If (Eval("[Forms]![F_F_0_Creer_Coswin_av_Correspondance_Coswin]![Référence_Fournisseur_Usine] Is Not Null And [Forms]![F_F_0_Creer_Coswin_av_Correspondance_Coswin]![Modifiable52] Is not Null and [Forms]![F_F_0_Creer_Coswin_av_Correspondance_Coswin]![Modifiable52]<>[Forms]![F_F_0_Creer_Coswin_av_Correspondance_Coswin]![code four]")) Then
        ' ref four est pas null + code four est pas null + <> Groupe
        Forms!F_F_0_Creer_Coswin_av_Correspondance_Coswin!Créer_New_Fournisseur_Usine = -1
    End If
 
    If (Eval("[Forms]![F_F_0_Creer_Coswin_av_Correspondance_Coswin]![Référence_Fournisseur_Usine] Is Not Null And [Forms]![F_F_0_Creer_Coswin_av_Correspondance_Coswin]![Modifiable52] Is not Null and [Forms]![F_F_0_Creer_Coswin_av_Correspondance_Coswin]![Modifiable52]=[Forms]![F_F_0_Creer_Coswin_av_Correspondance_Coswin]![code four]")) Then
        ' ref four est pas null + code four est pas null et = groupe
        MsgBox "Vous ne pouvez pas avoir une référence fournisseur différente du groupe pour cette même référence", vbOKOnly, ""
    End If
 
' #### Mise à jour #####
    ' F_F_0_Creer_Coswin_av_Correspondance_Coswin
    DoCmd.Close acForm, "F_F_0_Creer_Coswin_av_Correspondance_Coswin"
    ' R_C_Mise_a_jour_Code_Fournisseur_a_TMP_Usine
    DoCmd.OpenQuery "R_C_Mise_a_jour_Code_Fournisseur_a_TMP_Usine", acViewNormal, acEdit
    ' R_F_3_Update_TMP_Usine_a_Usine
    DoCmd.OpenQuery "R_F_3_Update_TMP_Usine_a_Usine", acViewNormal, acAdd
    ' R_F_4_Mise_a_jour_Table_Lien_Code_Groupe
    DoCmd.OpenQuery "R_F_4_Mise_a_jour_Table_Lien_Code_Groupe", acViewNormal, acEdit
    ' R_C_Mise_a_jour_ID_Groupe
    DoCmd.OpenQuery "R_C_Mise_a_jour_ID_Groupe", acViewNormal, acEdit
    ' R_C_Mise_a_jour_ID_Source
    DoCmd.OpenQuery "R_C_Mise_a_jour_ID_Source", acViewNormal, acEdit
    ' R_C_Mise_a_jour_Lien_-1
    DoCmd.OpenQuery "R_C_Mise_a_jour_Lien_-1", acViewNormal, acEdit
    ' R_C_Mise_a_jour_Lien_Fait_-1
    DoCmd.OpenQuery "R_C_Mise_a_jour_Lien_Fait_-1", acViewNormal, acEdit
    ' R_A_2_Mise_a_jour_ID_Source_dans_Usine
    DoCmd.OpenQuery "R_A_2_Mise_a_jour_ID_Source_dans_Usine", acViewNormal, acEdit
    ' R_A_3_Mise_a_jour_Id_Groupe_dans_Usine_avec_Code_Coswin
    DoCmd.OpenQuery "R_A_3_Mise_a_jour_Id_Groupe_dans_Usine_avec_Code_Coswin", acViewNormal, acEdit
    ' R_C_Mise_a_jour_Des_Fournisseur_TMP_Usine
    DoCmd.OpenQuery "R_C_Mise_a_jour_Des_Fournisseur_TMP_Usine", acViewNormal, acEdit
    ' #### Fermeture des formulaires ####
    ' F_F_3_SF_Fournisseur
    DoCmd.Close acForm, "F_F_3_SF_Fournisseur"
    ' F_F_2_FS_Source
    DoCmd.Close acForm, "F_F_2_FS_Source"
    ' F_F_1_SF_Groupe
    DoCmd.Close acForm, "F_F_1_SF_Groupe"
    ' F_E_0_Recherche_Groupe
    DoCmd.Close acForm, "F_E_0_Recherche_Groupe"
 
 
M_F_1_Creer_Coswin_av_Correspondance_coswin_Exit:
    Exit Function
 
M_F_1_Creer_Coswin_av_Correspondance_coswin_Err:
    MsgBox Error$
    Resume M_F_1_Creer_Coswin_av_Correspondance_coswin_Exit
 
End Function