Close and Return to Form

  • Thread starter Thread starter Tammy S.
  • Start date Start date
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
 
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
 
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
 
Back
Top