Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Seek() and tableupdate()
Message
From
30/03/1998 11:26:22
 
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00087270
Message ID:
00088139
Views:
23
>>I've a form with a table, and the table have a primary Key, the table is open with buffer mode=5
>>When i do a seek Fox preform an automatic tableupdate, and i got an error that the index was violated, because the value i entered in the textfield allready exists.
>>What is the best solution for cheking if a value entered allready exists
>
>Hi Joao. This is a common difficulty! Here are a couple of ways around it:
>
>1) Use a 2-step process to add a new record. Step 1 - use a preliminary form for the user to enter the primary key field value for the new record. In this form, the controlsource for the text box (or whatever) which receives the primary key value should be a memvar or a property of the form rather than a field of the table. When the user enters a value, you can seek it in the table and determine if it's unique. If not, show an error message. If so, insert the new record, then (Step 2) bring up your record maintenance form and treat it as an edit of an existing record where the user cannot change value of the primary key field.
>
>2) Don't use the actual field value as your primary key. Instead, create a separate field in your table with a meaningless but unique value - such as sys(2015) - for each record, and make that field the primary key. Have an index on your "real" field (account number, name, whatever) but not as a primary key. This way you won't violate referential integrity if a duplicate name or account number is entered. After the user enters the value of the field that you want to be unique, you can seek it to check for uniqueness and take appropriate action if it is not.
>
>There are probably as many ways to handle this as there are developers. Maybe someone else will offer other suggestions too.
>
>HTH,
>Rick

Hi again, Joao,

I just re-read my answer to your question, and realized that my comment about it being "a common difficulty" could be open to misunderstanding. I meant to be empathetic and was trying to say that this is something that probably many developers have run into. I did not mean to imply that it was a simple or obvious problem. I sincerely hope my answer came across in the spirit in which is was intended, and I hope you have found a solution that fits your needs.

Rick
Rick Borup, MCSD

recursion (rE-kur'-shun) n.
  see recursion.
Previous
Reply
Map
View

Click here to load this message in the networking platform