Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error handling on duplicate entries in DB is not working OK

Status
Not open for further replies.

gorcib

Technical User
May 11, 2004
12
SI
I have loop reading text file and import data from it to DB. File name consist of date and at the end of loop I increase the date for 1 day and create the file name to read the next file.
I am trying to solve the problem of error handling on duplicate entries with the foloving code:
[tt]
Private Sub cmdImportPC_Click()
...some code
[highlight]
start:
On Error GoTo errorhandler
[/highlight]
:
Loop to import data to DB
:
Exit Sub
[highlight]errorhandler:
skip (increment file name) to the next file ()
goto start[/highlight]
End Sub
[/tt]
The problem is next:
The first time duplicate entry error rises the code in errorhandling section is executed and there is no problem, the code goes to [tt]start:[/tt] and does all the job. The second time the program tries to insert a duplicate entry the code in errorhandling section is NOT executed, insted of this the system error message popups with the same error number. The program must be terminated.

Why the same error is not cathed with the error handler?


 
You probably need to clear the error within the errror handler with:

Err.Clear

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
I have already tried that but the problem persist. Where should I put Err.Celar statement

Regards, zabig
 
errorhandler:
skip (increment file name) to the next file ()
Err.Clear
goto start

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Maybe it's a matter of semantics but the Err.Clear has never worked as I hoped it would. I think you need to try
Code:
errorhandler:
    skip (increment file name) to the next file ()
    Resume start
 
I would test after the insert statement, and if you have a duplicate value, then jump out of your loop. No need to have a general error trap to catch it.

Also, do you have an on error goto 0 anywhere in the code? That's the only way it will turn off the error handling (unless the goto start is messing it up).

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top