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

To Find Blank Record in a Table

Status
Not open for further replies.

Z1

Programmer
May 8, 2000
14
US
Hai,<br><br>I am developing an application using <b>VFP6</b>. The DBC which is in use has more 120 table and the no of records varies from 20 to 200,000.The no.of Fields are ranging from 2 to 127. These tables have&nbsp;&nbsp;primary and or candidate index(es). <br><br>As this is a multiuser application, I want to trap error for more than one blank records when user press append button twice by mistake.&nbsp;&nbsp;Now it gives an error as unique indexes violated. <br><br>My objective is to find out if there is any blank record exist, if exist I want to disable the append command button.So the error (#1884-uniqness of primary key) wont happen.<br><br>Is there any VFP Command, which will solve my problem?<br><br>Thanks.<br>
 
There are a number of ways to do strictly what you asked for, Z1, including <br><FONT FACE=monospace>COUNT FOR EMPTY(MYKEY)</font>.<br><br>But a much better way is to not do this at all.&nbsp;&nbsp;Let the users enter the data in text boxes, then when they click the Save button, use the <FONT FACE=monospace>INSERT</font> command to create a record and insert the data from the text box .Values <p>Robert Bradley<br><a href=mailto: > </a><br><a href= - Visual FoxPro Development</a><br>
 
But if he's tied to fields as ControlSources I'm sure he's issuing APPEND BLANK in his New Record command.&nbsp;&nbsp;What is the preferred way of handling this?&nbsp;&nbsp;Leave one blank record in a table and use it for new records?&nbsp;&nbsp;Index on Deleted() and set a filter to NOT DELETED() ?&nbsp;&nbsp;Trap the empty record before record movement and prompt the user with record validation or even before the field moves with field validation on the primary field?&nbsp;&nbsp;<br>Actually I prefer generating primary/candidate integer keys with NewID() in the default value of the field as the VFP sample demonstrates.&nbsp;&nbsp;IMO, promary keys should never have any other meaning than as a unique identifier of the record.&nbsp;&nbsp;Helpful when you use updatable views also.&nbsp;&nbsp;Still you must handle duplicate blanks like in a CustID field you want unique.<br>John Durbin
 
Even if he's tied memvars to his ControlSources (not harmful, but usually unnecessary), he can still use <FONT FACE=monospace>INSERT INTO</font>.<br><br>I suspect, though, that he is binding the ControlSources directly to the columns.&nbsp;&nbsp;Z1, you can do this, but you should use buffering so that if a user aborts in the middle, you won't be left with a blank or incomplete record. <p>Robert Bradley<br><a href=mailto: > </a><br><a href= - Visual FoxPro Development</a><br>
 
RE: Unique keys I usually set up a table and hit this to get the event number.&nbsp;&nbsp;Works better then the record number.&nbsp;&nbsp;Provides a nice audit trail for deleted records.&nbsp;&nbsp;You can do this with a mem file too, but I think you get more flexibility with a table.<br><br>Sounds like you are trying to recycle deleted records.&nbsp;&nbsp;That results in audit trail problems if you have to overwrite a customer number or worse yet an invoice.&nbsp;&nbsp;They should be voided and not deleted.<br><br>Bill Couture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top