Automatically Close a Form

K

Kez

Hi everyone hope you can help. I have a main form with a command button to open a linked form. When I open the linked form I would like the main form to automatically close. Can anyone help. Thanking you in advance.
 
A

Allen Browne

Put this into the Click event procedure of your command button.

It ensures any edits are written to the table, opens the other form, and
closes itself:

If Me.Dirty Then
Me.Dirty = False
End If
DoCmd.Open "MyOtherForm"
DoCmd.Close acForm, Me.Name

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

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

Kez said:
Hi everyone hope you can help. I have a main form with a command button
to open a linked form. When I open the linked form I would like the main
form to automatically close. Can anyone help. Thanking you in advance.
 
B

Balisteve

Hi,
I have the same question, but don't understand the answer.
I am complete beginner so please type exactly what I should input

My first form is called "Name Input" (this is the form I want to
automatically close)
The form I want to open is called "Address Input"

Sorry to be a bit thick, but I hope you can help me also
 
P

pietlinden

Hi,
I have the same question, but don't understand the answer.
I am complete beginner so please type exactly what I should input

My first form is called "Name Input" (this is the form I want to
automatically close)
The form I want to open is called "Address Input"

Sorry to be a bit thick, but I hope you can help me also

Assuming "Name Input" is open... and cmdCloseThisOpenNext is the name
of the button on your "Name Input" form, this should work.

Private Sub cmdCloseThisOpenNext_Click()
On Error GoTo Err_cmdCloseThisOpenNext_Click

'--open the next form
DoCmd.OpenForm "Address Input", acNormal
'--Close the current form (Me.Name).
DoCmd.Close Me.Name, acForm, acSaveNo

Exit_cmdCloseThisOpenNext_Click:
Exit Sub

Err_cmdCloseThisOpenNext_Click:
MsgBox Err.Description
Resume Exit_cmdCloseThisOpenNext_Click

End Sub
 
Top