> I click on a command button to close, but if these fields are null, I
> don't want it to close. I want it to remain on the current form and
> set focus to the null field.
Try setting the focus to the tab page first, then the field on that page?

Signature
regards,
Br@dley
Mary - 11 Apr 2006 02:41 GMT
My tab page is named "Session".
I tried adding:
Me!Session.SetFocus
before the lines that set focus to the null fields. It closes anyway.
Thanks for your response.
cancelling the BeforeUpdate event only cancels the write to the table, it
doesn't cancel the Close command. you need to explicitly save the record in
the Close button code, and then handle the error that will arise from the
cancelled update, so that the Close command never runs, as
On Error GoTo Err_Handle
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close , , acSaveNo
Err_Exit:
Exit Sub
Err_Handle:
Select Case err.Number
Case Not 2501
MsgBox err.Number & " " & err.Description, "Unknown error"
End Select
hth
> I click on a command button to close, but if these fields are null, I
> don't want it to close. I want it to remain on the current form and set
> focus to the null field.
Mary - 11 Apr 2006 03:11 GMT
Tina,
I figured I was missing something!
That did the trick. Thank you so much for your help!
Mary
tina - 11 Apr 2006 04:46 GMT
you're welcome! :)
> Tina,
>
[quoted text clipped - 3 lines]
>
> Mary
tlyczko - 16 Apr 2006 20:32 GMT
Can this code be used to ensure that a SUBFORM does not close without
having at least one record added via the subform and/or that the
SUBFORM cannot be closed if at least one or more fields in the subform
are not filled in???
Would one put this in the OnExit event of the subform??
Thank you, Tom
tina - 16 Apr 2006 23:36 GMT
no, you can't use the posted code in a subform, because you don't "close" a
subform - you close the main form that the subform is "sitting" on. see my
more detailed answer in your thread started this date and titled "Why is my
BeforeUpdate code not working??".
hth
> Can this code be used to ensure that a SUBFORM does not close without
> having at least one record added via the subform and/or that the
[quoted text clipped - 4 lines]
>
> Thank you, Tom