dbTalk Databases Forums  

access2007 trapping errors with form's onError event

comp.databases.ms-access comp.databases.ms-access


Discuss access2007 trapping errors with form's onError event in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Roger
 
Posts: n/a

Default access2007 trapping errors with form's onError event - 07-27-2011 , 09:48 AM






I have a sql server table that is linked into access2007
I have a unique index on a field in that table
I have a form where I deliberately enter a duplicate value for this
field

if I have a command button that does
me.dirty = false

I can trap the error (3146), and err.description will indicate the
name of the index as part of the error message
[Microsoft][ODBC SQL Server Driver][SQL Server]Violation of UNIQUE
KEY constraint 'baanItemNullBuster_uq'.
Cannot insert duplicate key in object 'dbo.tblItem'. (#2627)
[Microsoft][ODBC SQL Server Driver][SQL Server]
The statement has been terminated. (#3621)

this allows me to provide a very specific error message


if the user uses the standard access form interface to 'save' a
record, the error is triggered via the onError event
Form_Error(DataErr As Integer, Response As Integer)

and dataErr has the correct error number so that I can detect the fact
that a duplicate value was entered
but I can't find anything (err.description, errors() array) that will
give me the error string so that I can report which field has the
duplicate

is there such a variable ?

Reply With Quote
  #2  
Old   
Patrick Finucane
 
Posts: n/a

Default Re: access2007 trapping errors with form's onError event - 07-27-2011 , 10:50 AM






On Jul 27, 9:48*am, Roger <lesperan... (AT) natpro (DOT) com> wrote:
Quote:
I have a sql server table that is linked into access2007
I have a unique index on a field in that table
I have a form where I deliberately enter a duplicate value for this
field

if I have a command button that does
* *me.dirty = false

I can trap the error (3146), and err.description will indicate the
name of the index as part of the error message
* * [Microsoft][ODBC SQL Server Driver][SQL Server]Violation of UNIQUE
KEY constraint 'baanItemNullBuster_uq'.
* *Cannot insert duplicate key in object 'dbo.tblItem'. (#2627)
[Microsoft][ODBC SQL Server Driver][SQL Server]
* *The statement has been terminated. (#3621)

this allows me to provide a very specific error message

if the user uses the standard access form interface to 'save' a
record, the error is triggered via the onError event
* *Form_Error(DataErr As Integer, Response As Integer)

and dataErr has the correct error number so that I can detect the fact
that a duplicate value was entered
but I can't find anything (err.description, errors() array) that will
give me the error string so that I can report which field has the
duplicate

is there such a variable ?
Not that I'm aware off. Maybe put a Dcount() or Dlookup() in the
B4Update events of the fields that are unique. Look for the field
with a difference autonumber than the current rec. If the count/value
is unexpected, thap at the contol's event.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.