?
Solved

docmd.close does not close form

Posted on 2018-02-13
6
High Priority
?
21 Views
Last Modified: 2018-02-13
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
0
Comment
Question by:João serras-pereira
  • 3
  • 3
6 Comments
 
LVL 53

Accepted Solution

by:
Gustav Brock earned 3000 total points
ID: 42467636
You may need:

DoCmd.Close acForm, "NameOfFormToClose"

Open in new window

0
 

Author Comment

by:João serras-pereira
ID: 42467677
The form is itself
will be OK?
0
 
LVL 53

Expert Comment

by:Gustav Brock
ID: 42467687
Yes. Currently you are closing the other form, so ...
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 

Author Closing Comment

by:João serras-pereira
ID: 42467692
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,,,
0
 
LVL 53

Expert Comment

by:Gustav Brock
ID: 42467695
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

0
 

Author Comment

by:João serras-pereira
ID: 42467706
thanks! its (almost) working
but I do really need to post another question... Now I can't add records!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Implementing simple internal controls in the Microsoft Access application.
With the functions here, you can parse, convert, and format back and forth between feet and inches and fractions and decimal inches - for normal as well as extreme values and with extreme precision.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

568 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question