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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search for Existing Record 1

Status
Not open for further replies.

wchestnut

Programmer
Aug 9, 2010
79
US
I can't believe I'm having such a hard time getting this to work! It's SO much easier in dBase/FoxPro!! (ok, I feel better now)

I need to take what a user enters in a field (Company) and look it up to see if it already exists so I can stop them from entering duplicates (numerous ones already exist so I can't change the Key in the Dictionary).

I read somewhere that you have to create aliases in order to do key lookups, so I created one for the COMPANY file. This is what I've been trying:


! Check for existing COMPANY
IF LocalRequest = InsertRecord
! Open secondary Company file
OPEN(COMPANYALIAS)
COMALIAS:Company = CO:Company
! Check if Company key exists
GET(COMALIAS:CompanyKey,COMALIAS:Company)
IF NOT EOF(COMPANYALIAS)
MESSAGE('Company Found: ' & COMPANYALIAS:Company)
CYCLE
ELSE
MESSAGE('Company NOT Found: ' & COMPANYALIAS:Company)
END
END


Why isn't this working? It keeps coming up "Company NOT Found" for existing and non-existing values and never hitting EOF on the alias.
 
I dont know if you are putting the correct keys but the typical way is this:

in stead of
GET(COMALIAS:CompanyKey,COMALIAS:Company)
IF NOT EOF(COMPANYALIAS)

put

GET(COMPANYALIAS,COMALIAS:CompanyKey)
IF NOT ERROR()

Hope this help
 
Hi!

Even though IF ERROR() will work, IF ERRORCODE() is the more optimized way since ERRORCODE() is a integer number and ERROR() is a string.

Regards
 
Interesting... okay, I'll try using that instead. I'm just surprised EOF didn't work, but then I don't think I had GET correctly. Thanks, ShankerJ!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top