Diese Seite mit anderen teilen ...

Informationen zum Thema:
WinDev Forum
Beiträge im Thema:
Erster Beitrag:
vor 5 Jahren, 10 Monaten
Letzter Beitrag:
vor 5 Jahren, 10 Monaten
Beteiligte Autoren:
Clarion Ghost, Paulo Oliveira, Al, Piet van Zanten, issah

Duplicate Key Error

Startbeitrag von Clarion Ghost am 23.09.2012 10:32


I am collecting email addresses. To prevent the user making duplicate entries I have made the data file item a unique key.

When I try to enter a duplicate email aaddress, WebDev, quite correctly, throws up its own system error.

I would prefer to display info("Duplicate Entry not allowed") and then return the user to the edit box when I try to HAdd or HModify.

How would I do this please.

Many Thanks


Simplest way might be to just do the ff:

if not hreadseekfirst(File,email,edt_email) then
info("Email address already exists")

von issah - am 23.09.2012 14:31
Hi Ian,

If hErrorDuplicates() then

Look on the Webdev Solutions forum for my returntocapture solution.
Of course you can simplify the code for just one field.
1. Create the global string variables sError and sControl.
2. If hErrorDuplicates then sError="errtext"; sControl=MyControl..Alias; return
3. Page load (onload) code (browser): if sError"" THEN Info(sError); sError=""; ReturnToCapture(sControl)


von Piet van Zanten - am 23.09.2012 15:37
check the help for Assisted management of HyperFileSQL errors to enable/disable or customize it.


von Paulo Oliveira - am 24.09.2012 08:55

I have read through the above and am trying to understand how this works,

If I run

HSetDuplicates(Password,EmailAddress, False)

On it's own HSetDuplicates(Password,EmailAddress, False) switches off the duplicate check and the system error window, allowing duplicates to be entered.

Looking at the help text the following finds the duplicate and displays the INFO message. However it also displays system error window.

Am I getting closer?

Many Thanks

IF HErrorDuplicates() THEN
HSetDuplicates(Password,EmailAddress, False) // I expected this to switch off the window after finding the duplicate allowing the info message to display?

von Clarion Ghost - am 24.09.2012 14:58
HSetDuplicates may cause serious problems, if you define one key as unique way do you need to store duplicate values on it?
The only use i see for this function is in some batch import processes to allow all the record to be imported and after that you run some code to be sure that the key only have unique values.

To achieve what you want (as far as i can undestand) HOnError is your best friend.

von Paulo Oliveira - am 24.09.2012 15:21

I have been playing with HOnError but I am still not getting it? The following does the job

// Manage a duplicate error

IF HModify(File) = False THEN
Info("Duplicate Found")

When I run the code. I get two reponses.
1. The system error window displaying the data line and the field with the duplicated error, (In this instant an email address?)
2, The message "Duplicate Found"

If I can hide the system error window I think the problem is resolved.
I have searched the help pages for something to do this, but can't find anything?

Many Thanks

von Clarion Ghost - am 24.09.2012 16:18
example to disable the error management for all the errors, the operation is cancelled for every error and no display of system error window.

init code of the project:

Global procedure:
PROCEDURE disable_hf_errors()
RESULT opCancel

Your code:
IF HModify(File) = False THEN
IF HErrorDuplicates() = True THEN
Info("Duplicate Found")

von Paulo Oliveira - am 24.09.2012 16:26
Hello Ian

You are always going to get duplicate errors when you first create a record if the email address is blank and that it always a possibility

You could leave the email field as indexed but non unique and test for a duplicate manually. To do this, I use the Record number not a primary key

//this code is part of a larger general purpose duplicate checking proc but this is the general method

IF HSeek("LDupChkAlias","CreditorCode",Complete(MySelf,20))
IF HRecnum() HRecNum(Creditor)
//there is a duplicate

Hseek() doesn't read the record so it is much faster than HReadSeek()


von Al - am 24.09.2012 22:27
Hi Guys,

Thank you very much. The penny has finally dropped

von Clarion Ghost - am 25.09.2012 12:56
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.