Close and Return to Form

T

Tammy S.

I have to command buttons that will each open a new form on click. The forms
they open also have command buttons that will return to the original form. I
would like these buttons to also close the forms, but don't know how to code
it.

Here is the existing code:
Private Sub btn_Return_to_Form_Click()
On Error GoTo Err_btn_Return_to_Form_Click

Dim stDocName As Srting
Dim stLinkCriteria As Srting

stDoc Name = "FrmNewAccountsDataEntry"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_btn_Return_to_Form_Click:
Exit Sub

Err_btn_Return_to_Form_Click:
MsgBox Err.Description
Resume Exit_btn_Return_to_Form_Click

End Sub

Thank you,
Tammy
 
M

Marshall Barton

Tammy said:
I have to command buttons that will each open a new form on click. The forms
they open also have command buttons that will return to the original form. I
would like these buttons to also close the forms, but don't know how to code
it.

Here is the existing code:
Private Sub btn_Return_to_Form_Click()
On Error GoTo Err_btn_Return_to_Form_Click

Dim stDocName As Srting
Dim stLinkCriteria As Srting

stDoc Name = "FrmNewAccountsDataEntry"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_btn_Return_to_Form_Click:
Exit Sub

Err_btn_Return_to_Form_Click:
MsgBox Err.Description
Resume Exit_btn_Return_to_Form_Click

End Sub

A form can close itself by using:

DoCmd.Close acForm, Me.Name, acSaveNo
 
J

John W. Vinson

I have to command buttons that will each open a new form on click. The forms
they open also have command buttons that will return to the original form. I
would like these buttons to also close the forms, but don't know how to code
it.

Use the Close event. Alone, DoCmd.Close will close the "active object" but
there's no good way to guarantee WHICH object is active, so have it explicitly
close the form you want closed (the form with the button on it):

Private Sub btn_Return_to_Form_Click()
On Error GoTo Err_btn_Return_to_Form_Click

Dim stDocName As Srting
Dim stLinkCriteria As Srting

stDoc Name = "FrmNewAccountsDataEntry"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, Me.Name

Exit_btn_Return_to_Form_Click:
Exit Sub

Err_btn_Return_to_Form_Click:
MsgBox Err.Description
Resume Exit_btn_Return_to_Form_Click

End Sub
 

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