Bonjour
dans un formulaire "frm061" je voudrais en sortant du controle "AgreEndo" effectuer un test et en fonction du resultat fermer le formulaire. J'ai trouve des explications mais ca ne marche pas.
Voici le code du formulaire frm061 qui contient le controle "AgreEnro" et le bouton "btnFermer".

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
Public Sub btnFermer_Click()
    DoCmd.Close acForm, "frm061"
    'DoCmd.Close 'frm061
End Sub
 
Private Sub btnValid_Click()
Dim Msg, Style, Title, Response
    On Error GoTo Err_btnValid_Click
    Msg = "You will create new Patient !" _
        & Chr(13) & Chr(10) _
        & "Do you want to continue ?" _
        & Chr(13) & Chr(10) _
        & "YOU WILL CAN NOT CHANGE AFTER" ' Define message
    Style = vbYesNo + vbExclamation + vbDefaultButton1    ' Define buttons.
    Title = "WARNING"  ' Define title.
    Response = MsgBox(Msg, Style, Title) ' Display message.
    If Response = vbYes Then    ' User chose Yes
        tmpContact = ContacNo
        DoCmd.OpenForm "frmX"
        cPatienN = tmpPatient
        DoCmd.Close 'frm061
        DoCmd.OpenForm "frm062", , , "[cPatienN]=" & tmpPatient
    End If
Exit_btnValid_Click:
    Exit Sub
Err_btnValid_Click:
    MsgBox Err.Description
    Resume Exit_btnValid_Click
End Sub
 
Private Sub Form_Current()
    btnValid.Enabled = False
    txtAgreEnro.Enabled = False
    If IsNull(AgreEnro) Then
        txtAgreEnro.Enabled = True
    End If
End Sub
 
Private Sub txtAgreEnro_Exit(Cancel As Integer)
    Select Case AgreEnro
    Case 1
        btnValid.Enabled = True
        DoCmd.GoToControl "btnValid"
    Case 2
        Forms("frm061").btnFermer_Click
    Case Else
        MsgBox ("'AgreEnro' must contain a value.")
        Forms("frm061").btnFermer_Click
    End Select
End Sub
le code passe au PublicSub btn... et reviens au Forms("frm061"... avec une erreur

Run-time error 2585
This action can’t be carried out while processing a form or report event

Merci de vos lumieres