Full Version: how to not allow bad data
UtterAccess Forums > Microsoft® Access > Access Forms
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?
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
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...
   If <your test to see if overlap> = -1 Then
      Cancel = True
      MsgBox "Overlap detected."
   End If
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.
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
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"
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.