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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sometimes Form closes, sometimes it doesn't. Why?

Status
Not open for further replies.

telephoto

Technical User
Nov 3, 2002
210
GB

I have customers with contracts and equipment, some with equipment not on contract.

From the switchboard I open a (continuous) form "frmSearch" this is based on a query which asks for a name.

From the displayed names I select one, and I can open another form showing that customer's equipment.
If I close the equipment form the search form is still displayed. Good.

From the search form I open the form showing contracts, (the search form is still open ,behind the contracts form). When I close the contracts form the search form closes as well. Bad.

Please can anyone tell me where Access is deciding to close the search form and how I can stop it?

Telephoto
(AKA Confused of Cambridge)
 
From the search form I open the form showing contracts" - how do you do it? What is the code?
"When I close the contracts form the search form closes as well" - code...?

Have fun.

---- Andy
 
We're confused, too! We can't see the code you're using to Close the Contracts Form! You need to post that.

Also, when you say 'Switchboard' are you speaking of one generated by the Access Switchboard Manager, or a custom Form you created to use as a switchboard?

What version of Access are you running?

The Missinglinq

Richmond, Virginia

The Devil's in the Details!
 
Probably because your code looks like

docmd.close
instead of being specific like
docmd.close acform, "form Name
 
Thanks for replies.
I was using docmd.close on both forms. I just tried "close acform" but it didn't make any difference.

I am using Access 2003, to run on Access 2000

The code to open the forms from command buttons is
1)
Code:
DoCmd.OpenForm "frmcontracts"
2)
Code:
stDocName = "frmCustomersMachines"
    DoCmd.OpenForm stDocName, , , stLinkCriteria 'stLinkCriteria is ""

Both forms open with a preset sql statement which is determined just before the open form command.

On form open the code for both contract and machine forms is
Code:
Set Me.Recordset = CurrentDb.OpenRecordset(SqlStr)
The switchboard is a custom form.

T
 
Did you specifically identify the name of the form in the second parameter?
 
Hi MajP

Not sure how you mean...
The customers machines form was set up to open using the Access wizard, so the wizard did its stDocName and stLinkCriteria thing.
There was no criteria, so stDocName was declared as frmCustomersMachines.
This form is still closing using DoCmd.Close, but it is not closing the search form behind it. (A good thing)

T
 
The Close method carries out the Close action in Visual Basic.
Syntax:
Docmd.Close(ObjectType, ObjectName, Save)

All parmeters are optional

ObjectType: An AcObjectType constant that represents the type of object to close.

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

Save: An AcCloseSave constant that specifies whether or not to save changes to the object. The default value is acSavePrompt

It is very sloppy not to specifically call out what to close by name, because it will end up closing whatever has the focus and may not be what you want. Timing can cause problems where sometimes it closes one object and other times a different object. Always specify by name and you will not have a problem. 99% of the time on a form it should be

docmd.close acForm, Me.name
 
I took note of your suggestion earlier, and changed the instruction for cmdClose on frmContracts.

Initially it has a "for/next" loop followed by an "if" - "endif" sequence to check various textboxes have content, and I have now set it to close using:
DoCmd.Close acForm, "frmContracts"

This is the form which closes the form behind it as well.

I can't see how the other form gets the focus to close?

Just to prove the issue I have commented out all the checking code so that only the close command is active.
It still closes both forms. Is it possible that this form is corrupt and needs rebuilding/replacing?

T
 
Sorted.

My error. While cutting and pasting code around I moved an Exit Sub command from the standard "Exit_cmdClose_Click:" line of code that the wizard puts in.
This let the running code step through into the "On Error" section, which had an additional Close command.

Thanks for your interest, apologies because it was my mistake.

T
 
Glad you got it sorted!

The Missinglinq

Richmond, Virginia

The Devil's in the Details!
 
This let the running code step through into the "On Error" section, which had an additional Close command

This exactly proves my point. Never use the close command without specifically telling it what to do. If each close command had a specific item identified to close this problem could not occur. Using the close command without specifying the object is a crap shoot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top