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!

Check for Dupe, Insert New Record 2

Status
Not open for further replies.

wchestnut

Programmer
Aug 9, 2010
79
0
0
US
I have a standard form where the user enter's a Contact's information. After the Last Name is entered, I'm using an Embed to look-up the First and Last Name in the Contact table to see if it exists, and if so, warn the user.

I got everything to work except the last step of adding a new record. The first problem was it changed to Change mode and it saved the existing record. I tried to look for ways to clear out the data and change the record pointer but I got an error "Record Not Available".

Here's the Embed Source I have so far:


! Lookup Existing Contact

GET(CONTACT,CON:ByLNameFName2)

IF ERRORCODE() = 0
IF CON:Company = ''
DuplicateNotice = 'WARNING: ' & CLIP(CON:Fname) & ' ' & CLIP(CON:Lname) & ' already exists in the Contact table with NO COMPANY set'
ELSE
DuplicateNotice = 'WARNING: ' & CLIP(CON:Fname) & ' ' & CLIP(CON:Lname) & ' already exitss in the Contact table with the Company: ' & CLIP(CON:Company)
END
! Save Name, Clear Record
LocalRequest = InsertRecord
DO PrimeFields

After the lookup, how change I change it back to Insert mode?
 
Hi!

1. You are trying to access another record of the same file while the record is being edited which could cause problems. The better approach would be to define an ALIAS (CONAlias) for this file in the dictionary, add the alias to the other files and look up the Alias for a matching record.

2. The easier way to check for duplicates is ::

IF DUPLICATE(CON:ByLNameFName2)
...
END

Regards
 
Yeah, I thought that might cause problems but didn't know any other way -- until now. Everything is so template drivin for the basic stuff. Thanks, again!
 
I tried using DUPLICATE on the Key but that particular Key does not have the DUP flag checked in the dictionary. This made sense in this case because we could have more than one Contact with the same First and Last name.

After reading about the function in the Language Reference, I tried DUPLICATE on the File because it said it would check all declared Keys without a DUP attribute checked, but it didn't work, either.


So, I went with your other suggestion and created an Alias for CONTACT (CON) called CONTACTALIAS (CONALIAS) and added CONTACTALIAS in Other Files. I thought, then, this Embed Source would work but it doesn't trigger a duplicate test entry:

! Use Lname, Fname in CONTACTS to look in Alias file
GET(CONTACTALIAS,CONALIAS:ByLNameFName2)
IF ERRORCODE() = 0
! Record Found, Warn User
END

I'm assuming the alias function acts as just another record pointer in the same file, correct?
 
I wish you could EDIT posts here so I didn't leave so many replies. I've made some progress after reading the book. Everything works on the live form, except when I go to click OK to save the record. I get the following error:

An error was experienced during the update of record. Error: Record Not Available (33).

Here is the new code:

IF LocalRequest = InsertRecord
! Recommended to add before DUPLICATE by the book
GET(CONTACT,0)
END

IF DUPLICATE(CONTACT)
IF CON:Company = ''
DuplicateNotice = 'WARNING: ' & CLIP(CON:Fname) & ' ' & CLIP(CON:Lname) & ' already exists in the Contact table with NO COMPANY set'
ELSE
DuplicateNotice = 'WARNING: ' & CLIP(CON:Fname) & ' ' & CLIP(CON:Lname) & ' already exitss in the Contact table with the Company: ' & CLIP(CON:Company)
END
END
 
Hi!

Is the CONTACT file auto-numbered? Why? B'coz for a auto-numbered file, an empty record with the new number is inserted first before the Form is called. IOW, the Form is actually in CHANGE mode and not in INSERT mode. So, a CLEAR(CONTACT,0) is dangerous.

If your key allows Duplicates, then the DUPLICATE() function will NOT work for you.

Simply use the Alias file to do the checking (assuming that the key contains ONLY the First & Last Name i.e.

CLEAR(ACON:Record)
ACON:FirstName = CON:FirstName
ACON:LastName = CON:LastName
GET(CONALIAS, ACON:ByLNameFName2)
IF NOT ERRORCODE()
... issue warning ...
END

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top