Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What gives with default values and append??
Message
From
16/02/2000 02:21:09
Gavin Reid
L & M Marketing Pty Ltd
Frenchs Forest, Australia
 
 
To
16/02/2000 01:37:27
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00332748
Message ID:
00332763
Views:
28
Hi Bernard,

   Why don't you instead of finding the last client number in CLIENT.DBF have 
a control table which would have the last client number. When you add a record
to the CLIENT.DBF you can then lock the control, add 1 to the last client
number, update the control table, store the last client number in a local
variable, unlock the control table and then return the new client number.

Try something like this:

FUNCTION NextClient

LOCAL nNextClientNo

* ----- Assumes that controltable is already open
SELECT controltable

IF RLOCK()
   * ----- Controltable can be updated
   *       Update the lastclientno in the control table
   REPLACE lastclientno ;
      WITH lastclientno + 1
   nNextClientNo = lastclientno
   UNLOCK
   RETURN nNextClientNo
ELSE
   * ----- Error Message for Controltable in use
   *	   and appropriate coding
ENDIF


Hope this helps,
    Gavin...
>I have this table in a database.
>CLIENTS.DBF Cl_id N(10)
> cl_name C(30)...
>
>and other fields for address etc.
>
>In the Default Value for the field cl_id, I have this expr - nextid("Clients","cl_id")
>
>I edited the Stored Procedures for the database and added the foll code:
>
>FUNCTION NextId
>PARAMETERS pAlias,pId
>PRIVATE ALL LIKE l*
>SELECT (pAlias)
>CALCULATE MAX(&pId) TO lnMax
>RETURN lnMax+1
>
>and saved it all.
>
>Now close all
>
>use clients in 0 SHARED
>SELECT clients
>APPEND BLANK
>
>and I get the error - "Cannot write to the record because it is in use"
>
>I next ran the form wizard and created a clients form. But when I hit the "ADD" button, same result.
>
>If I open the table EXCLUSIVE then no error and all works fine.
>
>What is happening and how do I solve this? I must have the tables shared!
>
>Bernard
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform