Can't close form with code (1 Viewer)

chuckgoss

Registered User.
Local time
Today, 21:01
Joined
Mar 26, 2001
Messages
44
Hi all,

I’m having a problem using VB code to close one of my forms.

Unlike the failing form, I successfully use the command: DoCmd.Close in a form that prints a report just prior to the Close command. The failing form, however, creates a new record as a part of its completion and that seems to complicate this action. I do not ask it to print a report.

On the last control of the failing form, I use a message box that appears with the OnExit event and prompts the user with ‘Do you want to Sign-out more parts? Yes, No, Cancel’. I want to close the form when the user clicks ‘No’. The run-time error I get when trying to close the form from here on OnExit or LostFocus events is: 2585 “this action can’t be carried out while processing a form”. I am unable to use the BeforeUpdate or AfterUpdate events on the last control to launch the MsgBox and Close commands. As soon as the form creates and then goes to the new record, that action alone triggers the BeforeUpdate or AfterUpdate events on the form, and accordingly, the MsgBox and Close commands tied to the last control. The MsgBox associated with the last control appears well before form has been filled in ... but only if I try to use BeforeUpdate or AfterUpdate. If I click Cancel on the MsgBox, the focus is put onto the last control (way ahead of schedule. The tab order is correct and functions if I use the OnExit event), if I click ‘Yes’, the focus gets put where I want it to go, if I click ‘No’, I get the error.

I receive the error using the following code combinations. It appears regardless of what kind of event I’m using to get out of the form.

a) DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close

b) Me.Refresh
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close

c) DoCmd.Close acForm, "Sign-Out Form"

d) DoCmd.OpenForm "Switchboard"
DoCmd.Close acForm, "Sign-Out Form"

e) ElseIf resp = vbNo Then
DoCmd.OpenReport "Sign-Out Form Report", acViewNormal
DoCmd.Close
End If

What am I doing wrong?

chuck
 
R

Rich

Guest
Because the message box is part of the form you cannot close the form before closing the message box,you have to cheat a little, close the form with the open event of the report.
HTH
 

Users who are viewing this thread

Top Bottom