Docmd.Close Closes Wrong Form??

CharlesWh

Registered User.
Local time
Today, 07:11
Joined
Jan 19, 2006
Messages
36
Here is a snippet of some code on a form.

User in the main form (frmPrimaryData)
that form contains among other things clients name and address
a user who wants to change or update it clicks a button which opens up an unbound form, clicking save triggers a SQL UPDATE...

Once thats done I want the form (frmPrimaryDataUpdate) to close but what actually happens is the form behind (frmPrimaryData) closes instead.

Forms!FrmPrimaryData.Requery
DoCmd.Close
Else
 
Maybe you have just set the focus on FrmPrimaryData and then the close action closes that form.

Can you build the form name into the close action? or insert a set focus before the close command to get focus back to the correct form
 
I got this to work where form name is FrmSales

PHP:
DoCmd.Close acForm, "FrmSales", acSaveYes
 
Also remember that the Close action (when called) will close the ACTIVE FORM/REPORT, regardless of what form you put the code. So you must explicitly give the name of the form you want to close (as PNGBill has advised in his last post).

You should rather acSaveNo than acSaveYes because if an error occurs and you save, it will save the current state of the form, not the state you designed it in.
 
Thanks all, I found setting the focus solved the problem.
 
FYI

Code:
[COLOR=#000000][FONT=Courier New][COLOR=#0000bb]DoCmd[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Close acForm[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]"FrmSales"[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb][COLOR=green]acSaveYes[/COLOR]  [/COLOR][/FONT][/COLOR]

The acSaveYes part dosen't save the data, just design changes to the form.

You only need:

Code:
[COLOR=#000000][FONT=Courier New][COLOR=#0000bb]DoCmd[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Close acForm[/COLOR][COLOR=#007700], [/COLOR][COLOR=#dd0000]"FrmSales"[/COLOR][COLOR=#0000bb]  [/COLOR][/FONT][/COLOR]

Since the default attribute is acSavePrompt and it triggers only if some design changes has occured.

JR
 
Code:
DoCmd.Close acForm, Me.Name

Closes that form that called the command.
 
I was going to suggest the code ghudson used only I also explicitly use the part about not saving so things like filters don't accidentally get saved (which doesn't happen frequently but can occur).

DoCmd.Close acForm, Me.Name, acSaveNo


and the benefit of using this is, as ghudson said, it will close the object the code is on without you having to specify the name of the object which makes it easy to copy and paste.
 

Users who are viewing this thread

Back
Top Bottom