Solved

error handling on duplicate index value

Posted on 1998-08-14
3
267 Views
Last Modified: 2008-02-26
I have a table that I don't want to allow duplicates into so I've created an index with NO DUPLICATES (duh!)

So when the user enters in a duplicate record I'm trying to trap the error so Access (97) doesn't put up that big ugly box that says
"The changes you requested to the table were not successful because they would create duplicate values in the index...."

The error happens after the Form_BeforeUpdate event.   So how come I can't display my own error message instead of Access putting up a message?

Here is my Form Before Update

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo ErrBU

Exit_Form_BeforeUpdate:
    Exit Sub
ErrBU:
    MsgBox "This is a duplicate part number and description for this manufacturer", vbOKOnly, "Hi it's me, the Central Scrutinizer"
    Resume Exit_Form_BeforeUpdate
End Sub

I put in a breakpoint on the ON ERROR line so I can watch it.  It drops down to the next line (Exit_Form_BeforeUpdate, does the Exit Sub line, then Access puts up it's error message.

On a success record insert (no duplicate) the next event after Form_BeforeUpdate   is amazingly enough Form_AfterUpdate.    The error seems to happen between where I can't figure out how to insert an error handler.

I'd really like to display my error message instead of the one Access puts up.

Thanks in advance.

Jim
0
Comment
Question by:jnearing
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
tomook earned 200 total points
ID: 1959231
The update actually happens between the BeforeUpdate and AfterUpdate events ;) You want to put your error handling code in the Form's OnError handler (Form_Error) and set
    Response = acDataErrContinue
 so Access does not pop up a message box.
0
 
LVL 1

Author Comment

by:jnearing
ID: 1959232
Thanks, that's exactly it.
Now I can go on vacation.

Jim

0
 
LVL 4

Expert Comment

by:tomook
ID: 1959233
Have a good trip.
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question