Close Form button not firing

Sorrells

Registered User.
Local time
Today, 00:54
Joined
Jan 13, 2001
Messages
258
I've searched in this forum for some time and have not found my problem described although some folks have come close.

I have a form, 'Visitation Schedule' that is for user input. Data is actually entered in a subform that is displayed in datasheet view.

The subform has code in the BeforeUpdate event that checks for required fields and has the user complete the record correctly or undo's the record.

Back in the main form, I have this CLOSE command button. The code behind this button is just the docmd.Close with the name of the form.

When there is a partial record with some required fields not completed, here is what happens.
1) Close Form button is pressed
2) Code in subform BeforeUpdate event executes
3) Execution NEVER returns to the Close Form button.

When there is a complete record, then
1) Close Form button is pressed
2)Close form code executes
3) Form closes

In the first case, once the user either completes the record or decides to discard the record, then the Close Form is clicked on again, the form closes without question.

I don't mind the checking in BeforeUpdate but I don't understand why the execution does not return to the code behind the Close Form button.

Does anyone have a reasonable answer for why this is so? Or how I could talk the BeforeUpdate procedure to Close the form if the OnClose had been clicked (this is not always the case!).
 
Does the close button visibly depress when there are subform recs caught in a Before Update trap? Or can you move to another control on the main form under the same scenario?

If the button depresses or you can move to another control on the main form, I'm not sure what's happening.

If not, though, I would guess your Main Form is not receiving focus, let alone firing a click event on your close button (which at a glance seems like an OK thing since it's stopping the user from entering invalid data).

Because of Access's built-in circuitry, your subform's Before Update Event occurs before the Main Form is activated (receives focus). So if your Before Update code cancels the event (DoCmd.CancelEvent), the entire sequence of action is halted at the subform.

Regards,
Tim
 
you might also have a syntax problem. There are several criteria that go with the DoCmd.Close function -

DoCmd.Close acForm, "formname", acSave or acSaveNo

check HELP for more information

HTH

-Al
 

Users who are viewing this thread

Back
Top Bottom