Yvanne
06-18-2001, 06:37 AM
I am trying to ensure the validation of fields on a form: the user may click a button to save the record or close the form to save the record. They need not "enter" the fields concerned, therefore the field validation does not work. I have managed to trap the errors if the save button is clicked, but on close of the form, I cannot seem to "back-out" of closing the form. Can anyone help?
The Real Yoda
06-18-2001, 06:50 AM
Use the EXIT SUB commannd before the Docmd.close
e.g.
if x = true then
exitsub ' This stops the code if the if statement is met
Else
DoCmd.close
AlanS
06-18-2001, 07:31 AM
Try this event procedure, which should be triggered whenever a record is updated, whether by closing the form, clicking a button, or however.
Private Sub Form_BeforeUpdate(Cancel As Integer)
If (invalid_data_condition_1) then Cancel = True
If (invalid_data_condition_2) then Cancel = True
...
If (invalid_data_condition_n) then Cancel = True
End Sub
Yvanne
06-18-2001, 09:07 AM
I hasten to add that I forgot to say that the form also includes a subform and that the validations concerned are in the subform...Sorry!
In reply to The Real Yoda:
The DoCmd.Close before the ExitSub does not apply if the form is closed using the "X" icon on the form, I actually use your suggestion on the button to save the record and close the form already.
AlanS:
I have tried your suggestion previously but I think it is something to do with the subform since the error message pops up but the form still closes.
My problem only occurs when I choose the "X" icon to close the form.
Thanks for the suggestions so far!