close a main form from button on a subform

MilaK

Registered User.
Local time
Today, 05:28
Joined
Feb 9, 2015
Messages
285
I've used the following code behind a button to close a form and it worked great. I made changes to the design and made the form a subform and the code is not working. Please suggest how to close the main form from a button on the subform.

On Error GoTo HandleError
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close ObjectType:=acForm, ObjectName:=Me.Name, Save:=acSavePrompt
HandleExit:
Exit Sub
HandleError:
MsgBox Err.Description
Resume HandleExit
 
you should only need 1 line:

DoCmd.Close acForm, forms!MainForm.name

(you cant use ME.FORM, because thats the subform name)
 
To close the parent form whatever it might be:

Code:
DoCmd.Close acForm, Me.Parent.Name
 

Users who are viewing this thread

Back
Top Bottom