Link to home
Start Free TrialLog in
Avatar of João serras-pereira
João serras-pereiraFlag for Portugal

asked on

docmd.close does not close form

Hi
On my app I have a button aiming at opening an external form which collects some data, computes it, adds a record to the database and should return to the invoking form.
The new form is "modal" and "pop-up".

so I click the button, it opens the form, fills/computes data, and I have a "close button" (the form has no close event or button).

currently, the code  on the "close"  button is:

Private Sub btn_sairNovoExame_Click()

On Error GoTo errorTrap

    Call logMe("btn_sairNovoExame_Click", "start")
    If IsNull(Me.frm_MotivoExame) Then
        MsgBox "Motivo de Exame não preenchido"
    End If
    If IsNull(Me.frm_dataExame) Then
        MsgBox "Data de Exame não preenchida"
    End If
    Me.frm_idExame = Forms![_intData].frm_exameRecCount
    Forms![_intData].frm_exameSalvo = True
    DoCmd.RunCommand acCmdSaveRecord
    Forms("frmPaciente").frmExameLista.Requery
    Call logMe("btn_sairNovoExame_Click", "start")
    DoCmd.Close
    Exit Sub
    
errorTrap:
    MsgBox "[btn_sairNovoExame_Click]." & "[" & Err.Number & "].[" & Err.Description & "]"
    Call logMe("btn_sairNovoExame_Click", "errorTrap:" & "[btn_sairNovoExame_Click]." & "[" & Err.Number & "].[" & Err.Description & "]")
    Resume Next
    
End Sub

Open in new window



So I though that on the "Docmd.Close" it shouls close itself and control would be back to the invoking Form.

But what is happening is that (1) the form does not close, (2) the close event of the invoking form is fired and (3) the statement " DoCmd.RunCommand acCmdSaveRecord" crashes when invoking the second time

can anyone help?
/joao
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of João serras-pereira

ASKER

The form is itself
will be OK?
Yes. Currently you are closing the other form, so ...
Thanks! It's running. Now the save record part. i'll post a special question for it. I think that, because the form is bounded, I will not need to save the record. It'll do on its own,,,
It might be the same issue - it is operating on the other form. Try:

If Me.Dirty = True Then
    Me.Dirty = False
End If

Open in new window

thanks! its (almost) working
but I do really need to post another question... Now I can't add records!