From: Tammy S. on 11 Jan 2010 09:34 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
From: Marshall Barton on 11 Jan 2010 10:54 Tammy S. wrote: >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 -- Marsh MVP [MS Access]
From: John W. Vinson on 11 Jan 2010 11:09 On Mon, 11 Jan 2010 06:34:01 -0800, Tammy S. <TammyS(a)discussions.microsoft.com> wrote: >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 -- John W. Vinson [MVP]
|
Pages: 1 Prev: Button to delete all records of a table Next: refresh/requery subform |