Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preventing an add to db when error exists

Status
Not open for further replies.

sms28

IS-IT--Management
Dec 10, 2002
19
US
I have a field, agency_id (exit event)with the following code below. If this error exists, I do not want to save the record. I've tried adding the code in the close, deactivate, unload events of the form. That does not seem to work. What's a good solution for preventing the save when there is an error?

If Len(Agency_ID) <> 3 Then
MsgBox &quot;Please enter 3 numbers for Agency ID&quot;
DoCmd.GoToControl &quot;Agency_ID&quot;
End If
 
Move the code to the BeforeUpdate event:

If Len(Agency_ID) <> 3 Then
MsgBox &quot;Please enter 3 numbers for Agency ID&quot;
DoCmd.CancelEvent
Me.Undo
End If

[thumbsup2] Anthony J. DeSalvo
President - ScottTech Software
&quot;Integrating Technology with Business&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top