Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to close nested forms without ending up on the original page one

Status
Not open for further replies.

rew2009

Technical User
Apr 21, 2009
114
US
I have a general question about nesting forms. I have a main form which has about 16 pages accessed with the named tabs at the top of the main form. The first tabbed page (1) is named “Main”. On page 6 which is named “Management” is a command button that opens up a second form called “Management Info” and in that second form is another command button that opens up a third form that is named “Update Management”. When I finish with the third form and click the close form button (which I created with the wizard) it not only closes that third form, but closes the second form and takes me not to the original page 6 on the main form but takes me to the first page on the main form. I find the same thing happening on other pages of the main form, i.e., if I close out the second or third level of a nested set of forms I end up on the first page of the original form. I want to end up on the previous form when I close up a deeper form not end up at the beginning. Is there something I am missing in opening up and closing nested forms?

Thanks,
 
You will have to provide some of the code or post db for someone to take a look at. Please post the code on the command button to close the form. Without seeing any code, my first guess is that you are using the close method without explicitly specify what to close.

To close a form you use the method "close" of the docmd object. It looks like:
docmd.close

If you do not specify any parameters it closes the active window. I never do it that way. I am always explicit by telling it exactly what to close.

docmd.close acform, "yourFormsName"

Help File said:
The Close method carries out the Close action in Visual Basic.

expression.Close(ObjectType, ObjectName, Save)
expression Required. An expression that returns one of the objects in the Applies To list.

ObjectType Optional AcObjectType.

AcObjectType can be one of these AcObjectType constants.
acDataAccessPage
acDefault default
acDiagram
acForm
acFunction
acMacro
acModule
acQuery
acReport
acServerView
acStoredProcedure
acTable
Note If closing a module in the Visual Basic Editor (VBE), you must use acModule in the objecttype argument.


ObjectName Optional Variant. A string expression that's the valid name of an object of the type selected by the objecttype argument.

Save Optional AcCloseSave.

AcCloseSave can be one of these AcCloseSave constants.
acSaveNo
acSavePrompt default This value is ignored if you are closing a Visual Basic module. The module will be closed, but changes to the module will not be saved.
acSaveYes
If you leave this argument blank, the default constant (acSavePrompt) is assumed.

Remarks
For more information on how the action and its arguments work, see the action topic.

If you leave the objecttype and objectname arguments blank (the default constant, acDefault, is assumed for objecttype), Microsoft Access closes the active window. If you specify the save argument and leave the objecttype and objectname arguments blank, you must include the objecttype and objectname arguments' commas.
 
Also do you have a nested subform or are you just popping open additional forms?

Nested means a form inside a form. A subform can be nested three level deep. You can have a subform, inside a subform, inside a subform.

"is a command button that opens up a second form called "Management Info" and in that second form is another command button that opens up a third form that is named "Update Management" "

Do these forms actually open as nested subforms, or are you just opening a separate pop up form? I beleive it is the latter.
 
I think you are right, these are pop-up forms- some I will have link criteria but some like this are free standing unbound.

This is the code to open a second form:

Private Sub Command1162_Click()
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "MANAGEMENT"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub

And this is the code to close that form:

Private Sub Command7_Click()
On Error GoTo Err_Command7_Click


DoCmd.Close

Exit_Command7_Click:
Exit Sub

Err_Command7_Click:
MsgBox Err.Description
Resume Exit_Command7_Click

End Sub

However, when I changed the “DoCmd.Close” to DoCmd.Close acForm, "Management" it did the same thing.

By the way I appreciate the help. I am trying to learn this coding as I go. I hope there are no stupid questions but I have always wondered why some expressions begin with “ac” like “acForm”.

Thanks for the help.


 
The "ac" is a standard prefix access constants. So there are a lot of functions that have parameters and you can pass them access constants. VB constants start with vb, Excel with xl etc. In VBA these constants represent a long value. Acform is the number 2, acreport 3, vbOkCancel = 1. It would be really hard to remember
Docmd.close 2, "MainForm"
However, it will work if you put the number in there.

Not sure of why this is happening. However go ahead and explicity close all the forms changing
docmd.close with an explicit statement. After that post any code in the popup forms "onClose" event.

A link criteria only tell how a form should open, it does not really cause a "link" between forms. So if form A opens B and B opens C there should be no reason that closing C will automatically close B unless there is some other code in C.
 
If you need someone to take a look, you can post the db on a free file sharing site. There are many of them. I use 4shared.com if I am posting a db for people to view.
 
Thanks for the help, I found the solution - I had code in the "OnActivate" property of the main form to go to the main page. When I removed that it solved the problem. I hate to say it but I was confusing going from the management tabbed page to the main page as closing of the second form. After closing the popup form I wanted to stay on the Management page which was tab 6 but endded up on the first page. Anyway, thanks for your insite on the other questions.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top