[AccessD] Primary Key Violation

Steven W. Erbach serbach at new.rr.com
Mon Nov 17 13:34:17 CST 2003


Gina,

Since Access doesn't have an On Key Violation event, you could put code that handles it in the On Error event. The numeric code for Duplicate Key is 3022. The On Error event procedure has two parameters: DataErr, the error number, and Response, what you tell Access to do about the error. If you have a Select Case DataErr statement in your On Error event code, then you can trap for 3022 and present your own message. Then you can return acDataErrContinue to tell Access to short-circuit the normal duplicate key error message.

There's a good example of this in the Access 2000 Developer's Handbook by Getz, Litwin, and Gilbert.

Regards,
 
Steve Erbach
Scientific Marketing
Neenah, WI

Disclaimer: No tree was killed in the transmission of this message. However, several coulombs of electrons were temporarily inconvenienced.

> ------------Original Message------------
> From: Gina Hoopes <hoopesg at hotmail.com>
> To: AccessD at databaseadvisors.com
> Date: Mon, Nov-17-2003 12:48 PM
> Subject: [AccessD] Primary Key Violation
> 
> I've got a seemingly stupid question, but I can't figure it out.  I've got a 
> form that collects a staff member's first and last name and uses that 
> combination as a primary key (unfortunately, no one can remember their 
> employee ID and we don't collect SSN or anything unique they could enter).  
> If they violate the exclusivity of that first/last name combination, they 
> get the convoluted error message that Access puts out which only serves to 
> confuse.  Is there a way for me to replace that message with my own and, if 
> so, how do I check for the violation and where would I put the error 
> message?  At the moment it comes up when they click the "done" button, which 
> seems like a good place.
> 
> Thanks,
> Gina
> 
> p.s. Please don't chastise me for perceived primary key protocol violations.
> 
> _________________________________________________________________
> Send a QuickGreet with MSN Messenger 
> http://www.msnmessenger-download.com/tracking/cdp_games
> 
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> 



More information about the AccessD mailing list