473,288 Members | 1,750 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,288 software developers and data experts.

Looping an OnError until duplicate error clears.

Ok, this may not even be possible, but I have to ask if anyone can think of anything. Searches have come up empty.

What I am trying to do in a form is after updating a customerID field, the next field CustomerEntry# populates with a 1. Easy enough.

The issue is that these 2 #'s combined form a unique ID in the table, so I want to make it so if the runtime error for duplicates comes up, it goes to the error handler and adds one to the value, then rechecks for duplicates again, and if the error occurs, try again, etc until there is no duplicate anymore.

Because the duplicate is in the table, not the form, I need to refresh the form to get the desired error. I have successfully got it to loop through once, changing the answer to 2, but after that the OnError doesn't seem to work and the error pops up with the form refreshes again.

I appreciate any ideas people might have. I'm a novice with OCD which is a bad combo ;) After 3 hours of failing I decided to stop trying and seek advice. Thanks to all.
May 27 '16 #1

✓ answered by NeoPa

KeithG:
I'm a novice with OCD which is a bad combo ;)
On the contrary. Software and database design is a perfect fit for OCD!

In this case you may want to consider checking the table first to determine what is the maximum value already in use. Here's (Item Numbering Within a Group) an article that points the way. A different, but quite similar, use case shouldn't put you off. Let us know if you struggle with it.

OTOH. With reference to re-using OnError code ever, it helps to understand that once an error has triggered this code, the error state is such that it knows it's in an error state. That is, until any form of Resume is used.

So, Resume or Resume Next will allow the OnError statement to be re-instated. Using any other way to loop through to your code will ensure it is still in error mode so the OnError won't be active. I hope that makes sense.

8 1473
PhilOfWalton
1,430 Expert 1GB
Please let us see your table structure. It doesn't look too good.

Phil
May 27 '16 #2
The database is at work I will have to wait a few days. Thanks for getting back. The table is a bear I created it years back when I had no idea what I was doing.
May 28 '16 #3
NeoPa
32,554 Expert Mod 16PB
KeithG:
I'm a novice with OCD which is a bad combo ;)
On the contrary. Software and database design is a perfect fit for OCD!

In this case you may want to consider checking the table first to determine what is the maximum value already in use. Here's (Item Numbering Within a Group) an article that points the way. A different, but quite similar, use case shouldn't put you off. Let us know if you struggle with it.

OTOH. With reference to re-using OnError code ever, it helps to understand that once an error has triggered this code, the error state is such that it knows it's in an error state. That is, until any form of Resume is used.

So, Resume or Resume Next will allow the OnError statement to be re-instated. Using any other way to loop through to your code will ensure it is still in error mode so the OnError won't be active. I hope that makes sense.
May 28 '16 #4
Thanks so much, I will read this linked info and give it a whirl. Also thanks for the info about On Error I did not know that!
May 29 '16 #5
Ok I came up with a completely different way to do this using DCount and an unbound text field that equals the ID# for the criteria.

Thanks guys for getting back to me :)
May 29 '16 #6
NeoPa
32,554 Expert Mod 16PB
Hi Keith.

That approach (if I understand you correctly) will work up to a point. It does assume that none of the records are missing from the list and that all existing records within the specified grouping are numbered sequentially from one to the maximum number used.

In my experience that is not a safe thing to rely on. DMax() does a much more reliable job for you.

Good thinking though ;-)
May 30 '16 #7
I didn't think to try that. I will play around with it. Thanks for the suggestions :)
May 30 '16 #8
NeoPa
32,554 Expert Mod 16PB
KeithG:
I didn't think to try that.
It was at the heart of the article I linked to in post #4. If you haven't read that yet I recommend you do. There are a number of gotchas involved that it will help you avoid.

Good luck.
May 30 '16 #9

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

Similar topics

5
by: S.Patten | last post by:
Hi, I have a problem with updating a datetime column, When I try to change the Column from VB I get "Incorrect syntax near '942'" returned from '942' is the unique key column value ...
2
by: Robert Oschler | last post by:
If I set window.onerror to an error handler I've created, I don't see the browser error dialogs anymore but I don't see the alert() messages in my error handler pop up either. Can someone tell me...
1
by: Beau | last post by:
Hi all, thanks in advance. Ok, heres the story. What is happening...... -------------------------------- I've got an ASP page that loops. It loops in order to get data in different,...
13
by: lithoman | last post by:
I'm stumped here. I run the procedure Batch_Select against the database with @ID=18 and I get the expected data. When it loads into a SqlDataReader, it gets messed up somehow. Initially, after the...
1
by: bruce24444 | last post by:
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...
4
by: SJ | last post by:
Hi! I am trying to do a simple udpate on a table and I am getting the error: "Cannot insert duplicate key row in object 'UserInfo' with unique index 'UserInfo_Login'.The statement has been...
1
by: UT-BadBoy | last post by:
Hi, I've been receving this error "System.InvalidOperationException: The namespace, , is a duplicate." and have been unable to locate the exact cause of the exception. I've written a...
2
by: raphael001 | last post by:
In my Visual Basic program I'm just trying to find duplicate values entered into an array from an inputbox, but i can't seem to get the coding right on the final part to check for duplicate values...
8
by: zyzolus | last post by:
Hello, I create 2 unique indexes on 2 fields: Field1 and Field2. What is the way generate custom error message independent of each field?ex.: "Duplicate value in Field1" or "Duplicate value...
1
by: jsungmin | last post by:
hye. I have a little problem about loopping statement. This is the code.. <cfloop query="getQuest"> <cfset count=0> <cfquery name="chechking" datasource="#ds#"> select status_flag...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.