View Full Version : Prevent main form from closing when field not updated in subform


bgotis
02-22-2001, 06:48 AM
In my subform, I want to required entry in the END_DATE field if the field Status ="Complete"

So far the code will continue to take the user back to the END_DATE field and prompt for a date as long as the Status is complete --- *except* if the user just closes the form. They'll get the error message three or four times, but eventually can close the form without entering the required information.

How do I keep the main form from closing when the required data is not entered on the subform?

Thanks in advance.

Anauz
02-22-2001, 07:12 AM
have a boolean called required

if "Me.requiredfield.text" = "" then
required = true
End if

on the click event of button to close the form put the following code in

If required = true then
msgBox("required field is empty")
Else
'code to close the button
End if




[This message has been edited by Anauz (edited 02-22-2001).]

bgotis
02-22-2001, 10:07 AM
In what part of the class module do I name the boolean?

Pat Hartman
02-22-2001, 03:34 PM
You need to put the code in the BEFOREUpdate event of the form. From your description, it sounds like you have placed it in the AFTERUpdate event.

If -your edit goes here- Then
Else
MsgBox "End Date is required, update is being cancelled", vbOKOnly
Cancel = True
Me.END_DATE.SetFocus = True
End If