All Forms Close on DoCmd.Close

K

Karen

Hi,

I have a form that is opened from another form to capture info about a new person. On the calling form, there is a combobox with 'New' and if it is selected I open a person input form to capture information on the new person.

On the person input form I have an 'Exit' button to close the form with this code behind it

Private Sub cmdExit_Click()
On Error GoTo Err_cmdExit_Click

strNewAgent = txtFullName.Value

DoCmd.Close

Exit_cmdExit_Click:
Exit Sub

Err_cmdExit_Click:
MsgBox Err.Description
Resume Exit_cmdExit_Click

End Sub

When the input form closes, so does the form that called it. Why is this happening?
 
A

Allen Browne

You will probably find there is another reason the previous form is closing,
but to eliminate the possiblity that it is this one you could be specific
about the name of the form to close:

DoCmd.Close acForm, Me.Name

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.


I have a form that is opened from another form to capture info about a new
person. On the calling form, there is a combobox with 'New' and if it is
selected I open a person input form to capture information on the new
person.

On the person input form I have an 'Exit' button to close the form with this
code behind it

Private Sub cmdExit_Click()
On Error GoTo Err_cmdExit_Click

strNewAgent = txtFullName.Value

DoCmd.Close

Exit_cmdExit_Click:
Exit Sub

Err_cmdExit_Click:
MsgBox Err.Description
Resume Exit_cmdExit_Click

End Sub

When the input form closes, so does the form that called it. Why is this
happening?
 
K

Karen

Thanks Allen,

I asked the question and promptly got sick so I'm just getting back. I've
changed all of my docmd.close to point to the name of the form.....we'll
see!
 
B

Billy Yao [MSFT]

Hi Karen,

How are things going? Has Allen's suggestion helped solve your prolbem?

When the Form is needed to be closed, we'd better specify which one we
should perform the DoCmd.Close operation. The complete syntax of this
method is:

Docmd.Close(ObjectType, ObjectName, Save)

If you leave the objecttype and objectname arguments blank (the default
constant, acDefault, is assumed for objecttype), Access will close the
active window. In addition, if you specify the save argument and leave the
objecttype and objectname arguments blank, you must include the objecttype
and objectname arguments' commas.

If a form has a control bound to a field that has its Required property set
to 'Yes,' and the form is closed using the Close method without entering
any data for that field, an error message is not displayed. Any changes
made to the record will be aborted.

Karen, we would appreciate it if you could post here to let us know the
status of the issue. If you have any questions or concerns, please don't
hesitate to let us know. Look forward to hearing from you.

Best regards,

Billy Yao
Microsoft Online Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top