Validate data before Save

H

hughess7

Hi all

I have a routine on the afterupdate of a field which checks for duplicate
data and warns the user if found. In case the user still tries to proceded I
also have the same code (but with cancel = true added) on the beforeupdate of
the form to prevent a save taking place. The only problem is when the
navigation buttons (which I have added manually to my form) are used it
produces an error still eg can not go to specified record.

What is the best way to deal with this, off the top of my head the only
thing I can think of is to try putting the docmd.setwarnings false statement
before the move record command but I suspect there is a better way?

Thanks in advance for any help.
Sue
 
R

Rick B

Why would you not want the same error checking to occur when the user clicks
the navigation buttons? If you are about to move to a new record, then you
should check to make sure the edits on the record are correct.
 
H

hughess7

I do hence I added the validation code, I just want it to not try to perform
the navigation if the save was unsuccessful as this results in an error.

Also, having done further testing my data validation rule causes a problem
when you want to save an edited existing record.

Dim Jetwhere As String

Jetwhere = "[ReviewDate] = #" & Format$(CheckDate, "mm\/dd\/yyyy") & "#" &
"AND Specialist = " & Format(SpecID, "0")

UniqueRec = (DCount("*", "Itinerary", Jetwhere) = 0)

How would I distinguish between saving a new record and modifying an
existing record so i can change the code slightly?

Thanks in advance for any help.
Sue
 
Top