The problem you are facing is that VFP does not let you replace an autoinc 
field because it is readonly.

There are two ways to do a gather, in the scenario you are posting here:

a) check the VFP help for set autoincerror ( I do not use it at all)

b) use gather name

The customers table has an autoincrementing field (custid) that I use as the 
PK for that table. When I need to make changes to a certain record, gather 
is the command of choice. Here's how I do this:

select Customers
gather name oCustomers memo blank     && create an object with empty 
properties (fields)

removeproperty(oCustomers,'custid')

that is, remove from the object oCustomer, the property (field) that is an 
autoincrementing field
then proceed to make changes as necessary in the object's properties

with oCustomers
       .name = 'John Doe'
       .address = '223 Main St.'

       etc.
endwith

gather name oCustomers

This will replace the corresponding fields in the record with the objects's 
properties as above. Because you have removed the custid property (which is 
an autoincrementing field) from the object, you do not touch that field in 
the table, and your gather command replaces all other fields, just as the 
old gather memvar command did.

BTW, you can use the same technique with the insert command, simply by 
replacing the gather name line above with:

insert into customers from name oCustomers

Since you are not attempting to replace the autoinc field with anything, it 
will just operate by itself, incrementing the fields value automatically and 
allowing a new record to be added.

Happy New Year

Rafael Copquin






----- Original Message ----- 
From: "Matt Slay" <[email protected]>
To: <[email protected]>
Sent: Sunday, December 28, 2008 1:38 AM
Subject: Help with GATHER and AutoInc fields


> Need some guidance here... I am trying to copy the data in one record
> to a new record in the same table, then change the JobNo field to some
> new Job umber that I already have and validated as unique.
>
> The problem is that the table has an AutoInc field named "ipkey", and
> VFP does not want to let me do a GATHER for obvious reasons.
>
> So, I understand why it has this limitation because of autoinc, I just
> want to know how one normally works around it.
>
> Presently, to get around it, I am doing a  REPLACE command on every
> field except ipkey, but I was hoping to use the SCATTER NAME / GATHER
> NAME method to avoid having to list out every field, and so I would
> have code that is independent of the field names.
>
> Here's what I wanted to use:
>
> Select 0
> Use Jobs order jobno
> ... navigate to the desired record ..
> SCATTER NAME loCurrentJob
> Append Blank
> Gather NAME loCurrentJob
> replace JobNo with lcNewJobNo && a passed in value, already validated
>
>
>
>
> --- StripMime Report -- processed MIME parts ---
> multipart/alternative
>  text/plain (text body -- kept)
>  text/html
> ---
>
[excessive quoting removed by server]

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/007501c969a6$a2f1c110$6501a...@rafaelpc
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to