473,406 Members | 2,336 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Duplicate Error Message

I am designing a database to use a work to assign files to certain people. Form includes Date textbox, File Number textbox, File Type combobox and Assigned To combobox. The form is working fine and the File Number textbox is set “not to accept duplicates”.

What I'd like to do is change the error message that pops up if a duplicate file number is entered and attempted to be assigned.

Right now I get an error message which says "The changes you requested to the table were not successful because they would create duplicate values in the index......etc, etc"

When you click “OK” another message pops up saying “You can’t save this record at this time. If you close this object now, the data changes you made will be lost” and then all the other information entered is cleared.

What I’d like to do is change the message to say “This file number has already been assigned to someone. Please confirm information has been correctly entered”

Upon clicking “OK” return to the file number entry textbox to be able to re-enter the data without losing the rest of the information already entered into the form.

Designing for use with Access97
Mar 16 '07 #1
1 2959
RJMac
9
The form you are using needs to be bound to the Table holding the fields you mentioned, and you need to have Microsoft DAO set in Tools/References on the tool bar. If both of the above are true, then the following should work:

You need to have 2 events set up - One for the Form - the on Current event, and one for the txtFileNumber text box - the AfterUpdate event. I'm assuming that your data table is called tblTable1, and your File Number field is FileNumber. Just insert the subroutines below:

If your File Number is a purely numeric field, just omit the ' either side of txtFileNumber after the SELECT statement!

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. txtFileNumber = Me!FileNumber
  3. End Sub
  4.  
  5. Private Sub txtFileNumber_AfterUpdate()
  6. Dim dbs As Database, rst As Recordset
  7. Set dbs = CurrentDb
  8.  
  9. If Nz(txtFileNumber, "") <> "" Then
  10.  Set rst = dbs.OpenRecordset("SELECT * FROM tblTable1 WHERE FileNumber = '" & txtFileNumber & "';")
  11.  If rst.RecordCount > 0 Then
  12.   MsgBox "This file number has already been assigned to someone. Please confirm information has been correctly entered."
  13.   txtFileNumber = ""
  14.  Else
  15.   Me!FileNumber = txtFileNumber
  16.  End If
  17. End If
  18. End Sub
  19.  
Mar 16 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mohammed Mazid | last post by:
Hi, Basically I have a problem with registering to my quiz system. I had borrowed some code from an existing program but I just do not know why it doesn't work. If (txtUsername = "" Or...
1
by: Gary Lundquest | last post by:
It appears to me that MySQL version 4 returns an error messge when doing an Insert that results in duplicate entries. Version 3 did NOT return an error - it dropped the duplicate entries and ran...
8
by: Mark | last post by:
When my form goes to a new record, I have a procedure that copies the last record added to the form's underlying table into the form. The intent is that a series of new records may have the same...
2
by: stranger | last post by:
My database is set up so people can input parts orders. Sometimes they order the same parts on a monthly basis. I want to be able to duplicate past parts orders and have it pasted in with a new...
2
by: Brad Allison | last post by:
I have created a short routine to read certain data from an AS400 and put it into a small table stored in Access (I know not the best data store, but it is what we have for now). Anyway, some of...
1
by: Mike Hunter | last post by:
(Please CC me on any replies as I'm not on the list) Hi, After a recent power failure, a program that uses a pgsql backend (netdisco) started to send me nastygrams. I tried the author's...
1
by: Joseph Chase | last post by:
I am running version 4.1.13a-log on a Mac XServe. How can I receive a 'duplicate entry' error for an UPDATE? An update isn't creating an entry, so why this error message? ...
8
by: Iona | last post by:
Hi Allan, I'm using a nifty piece of code you put on here some time back to do a duplicate entry check as below. I'm using to check for duplicate names. However I am getting an error message on...
5
by: baur79 | last post by:
Hi guys i try to run this code in loop and to pass even the entry is duplicated def email_insert_in_db(email): sql="INSERT INTO emails (email) values ('%s') "%(email)...
6
by: Dave | last post by:
I really don't like the users getting an unhandled expception page, and I'm still to new with ASP.Net and C#. So please accept my appology for the 2 part question. SqlException (0x80131904) ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.