Full Version: how to not allow bad data
UtterAccess Forums > Microsoft® Access > Access Forms
Uplinker78
I have a query set up to check for over lapping events, if there is an event that over laps the querry gives a result of "-1" and if everything is ok "no value", how can I set it up so that they can't close the form that made the overlap till it is corrected?
bome
Normally you do validation before saving the changes in the form. I use one of the following events to validate before saving:

AfterUpdate event for the control = triggers when the value in the control has changed
BeforeUpdate event for the form = triggers before saving the record

This requires knowledge of programming in VBA.
____________
Bo Melin
Steve Schapel
Uplinker,
There are a number of variations on the approach you could take here. The bare bones of it, would be to use the Before Update event of the form, with code something along these lines...
CODE
   If <your test to see if overlap> = -1 Then
      Cancel = True
      MsgBox "Overlap detected."
   End If
Uplinker78
Right now I have is set up so that a msg pops up if there is a time conflict, but if they choose to, they can just ignore it. Any suggestions on what command I would put to stop them from closing the form if there is a conflict, or if they close it, it deletes the record maybe.
bome
You should try to validate if you have a time conflict BEFORE saving the record instead of after.
Can you post the SQL for query you use to check for time conflict? Perhaps we can suggest how you can make the validation using the form's BeforeUpdate event instead.
___________
Bo Melin
Uplinker78
I got it to work, I took away the X button at the top of the screen and replaced it with a close button in the form then put an If stament in VBasic saying
IF querry=-1 then
msgbox"Cant close"
else
docmd.close
Thank you for your help.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.