PDA

View Full Version : auto increment


ABC123

richie V
01-11-2006, 05:05 PM
in my field rules i selected auto increment
how do i start the the number i want
this is the starting # 06-1000

Stan Mathews
01-11-2006, 05:25 PM
in my field rules i selected auto increment
how do i start the the number i want
this is the starting # 06-1000
The documentation for later versions still applies to your situation.



Creating an Auto-Increment Field


Display the Tables/Sets tab of the Control Panel.

Select the table that will contain the auto-increment field.

Select Design > Field Rules.

Select the field that will be auto-numbered from the drop-down list at top left.

On the Field Types tab under Extended field types select Auto increment.

Display the Data Entry tab.

In the Required section select "Always required".

Check Auto advance after field filled.

For Default mode select "Simple default expression".

For Default value set the initial value of the series. If this is a character field, put quotes around the value (e.g. 00001 for a numeric field and "00001" for a character field).
Put .T. into the Skip field.

Click Save and exit from the Field Rules editor.

richie V
01-11-2006, 06:54 PM
i did exactly that
when i have auto increment on it don't work
if i have auto increment off it enters the defalt value

Tom Cone Jr
01-12-2006, 10:09 AM
Richard,

Here's an example, using A5v7. Will run under A5v5 or A5v6, too.

Compare how this is working, and how it's set up, with what you've been doing.

-- tom

Robin Hoare
01-17-2006, 06:51 PM
I've been having a bit of trouble with autoincrement fields, too.

My field is numerical (4 digit) and I specified a default of 0001 (no ""s)

However I got a zero for the first field ID.

I was working with the recommended "Check auto advance after field filled" and did not check "at start of data entry"

Now I have changed over to Tom's method, which is the reverse: no "Check auto advance..." but checking "at start..."

And it works! The first field ID is now 1 as it should be.

I wonder why.

Robin

Stan Mathews
01-17-2006, 07:00 PM
My field is numerical (4 digit) and I specified a default of 0001 (no ""s)

Probably had a problem (or more precisely unexpected behavior) because 0001 (no ""s) is not numeric.

Robin Hoare
01-17-2006, 08:19 PM
I did try the simple 1 too, same results! (ie. without the leading zeros)

Robin

civitas
08-25-2006, 12:08 AM
I have seen a great deal about creating auto-increment fields. I have a table with over 600 records. I just inserted a new field to give a unique identifier to each record. How do I make auto-increment work on records that are already created? Thanks! -- Arthur

Stan Mathews
08-25-2006, 09:24 AM
I have seen a great deal about creating auto-increment fields. I have a table with over 600 records. I just inserted a new field to give a unique identifier to each record. How do I make auto-increment work on records that are already created? Thanks! -- Arthur
You don't. Temporarily remove the auto-increment designation, populate the field via an update operation, then reinstate the rule. The auto-increment is a data entry field rule, not something that can be applied retroactively to existing records.

civitas
08-25-2006, 01:28 PM
Stan, thanks very much. That did the trick! -- Arthur

Richard Connors
03-02-2007, 11:04 AM
I have the same problem as Civitas. I’m moving an A4v8 set with a mother and two children, both of which are linked through the auto-incrementing ID field. This DB is at least ten years old and has 26620 mother records and over 15000 records in each of the children. Can’t get the auto-increment to work, and now I see why.

I’m new to A5, am using v8, and not sure what you mean by your “populate” instruction to Covitas. Could you expand this for me?

Stan Mathews
03-02-2007, 11:45 AM
I have the same problem as Civitas. I’m moving an A4v8 set with a mother and two children, both of which are linked through the auto-incrementing ID field. This DB is at least ten years old and has 26620 mother records and over 15000 records in each of the children. Can’t get the auto-increment to work, and now I see why.

I’m new to A5, am using v8, and not sure what you mean by your “populate” instruction to Covitas. Could you expand this for me?

You can use an update operation to "populate" (modify, replace, etc) any user entered field with data of the appropriate data type. You first have to change the field from auto-increment to user entered, run the update, then change it back to auto-increment. I'm not sure what your exact need is. If you explain what you need to do I can advise more directly.

Richard Connors
03-02-2007, 01:08 PM
Oh, sorry. When I enter a new record into the mother, the ID field appears as 99000, no matter what I try. If I manually enter the value I want—26621—it reverts to 99000 anyway. I’ve followed all the alternative suggestions above and nothing works.

Stan Mathews
03-02-2007, 01:38 PM
Oh, sorry. When I enter a new record into the mother, the ID field appears as 99000, no matter what I try. If I manually enter the value I want—26621—it reverts to 99000 anyway. I’ve followed all the alternative suggestions above and nothing works.

I believe the auto-increment behavior changed between A4 and A5 (any version). The machinery behind the auto_increment field will never increment to nor allow entry of a value less than the present "highest" value in the field. Since you are seeing the 99000, it seems there must be a 98999 value in your table somewhere. I would suggest that you open the main table in question (the parent of your set). Sort descending on the auto-increment field. Note the values you see.

You are expecting to see 26620 as the highest value. Is this what you find?

civitas
03-03-2007, 09:40 AM
Thanks so much! I really appreciate the help. -- Arthur

Stan Mathews
03-03-2007, 02:09 PM
Thanks so much! I really appreciate the help. -- Arthur

Please describe what you found so anyone who visits this post later might also be able to diagnose their issues.

Richard Connors
03-15-2007, 10:21 AM
You don't. Temporarily remove the auto-increment designation, populate the field via an update operation, then reinstate the rule. The auto-increment is a data entry field rule, not something that can be applied retroactively to existing records.

I'm trying to move an A4v8 "client" file to A5v8. It has an ID field of 5 characters, the max value of which is 26670. No matter what I do, the value entered is 99000. I tried this suggestion of first removing the auto-increment designation and doing an update. Didn't work. I then manually entered three records with values 30000, 30001, and 30002, then re-established the auto-increment. That didn't make any difference either. Still enters 99000,

I played with it a bit. Made the field 6 characters instead of 5, for example. Then the auto-increment entered the value 990000.

Very frustrating. This file is way too big to lose. I need some major help here, please.

Tom Cone Jr
03-15-2007, 10:57 AM
I've only seen this when my ID field had unexpected data in it. If it were me, I'd study the table to verify that the highest field value is only "26670".

It's not clear from your post if the field is numeric or character type. If you can't solve this on your own, let us know which is applicable when you reply.

-- tom

Al Buchholz
03-15-2007, 11:36 AM
Richard

Open a default browse for the table. Highlight the ID field, then from the menus - navigate - tools - field statistics. You should see something similar to what the attached image shows for Alphasports.

Check the max value for that field.

Richard Connors
03-15-2007, 12:30 PM
I've only seen this when my ID field had unexpected data in it. If it were me, I'd study the table to verify that the highest field value is only "26670".

It's not clear from your post if the field is numeric or character type. If you can't solve this on your own, let us know which is applicable when you reply.

-- tom

Interesting. It's a character field in both A4 and A5. When I sort that field in A4 it displays in strict numerical order--first record "1", last record "26670". When I sort the same field in A5 it shows the first or lowest record as "1", but the highest is "99". Because of some deleted records over the years, there is no record "999" and also there is no "9999". Apparently, the decimal placeholders, or zeros, didn't come thru the conversion properly. Record "00099" in A4 came through as "99000" in A5.

How can I keep the zeros in their proper places?

Tom Cone Jr
03-15-2007, 03:47 PM
Richard, what you describe suggests to me that the data type for the ID field in Alpha Four was numeric, and Alpha Five converted it to character. Did you append records from the Alpha four table, or did you just begin using a copy of the A4 dbf?

In any case the answer to your original question is now clear. The "99 " sorts to the top of the list, and is being used by the autoinc field rule as expected.

If you turn off the field rule you can define an "update" operation that will prepend leading zeros using an expression like this:

padl(alltrim(ID), len(ID), "0")

I caution you not to do this without making a safety backup copy of your data first. Many an update operation has gone awry and they're dang difficult to reverse. Run the update against a throw away copy of the table first, before running it against your real data.

Once the field values have been zero filled you can then turn the autoinc field rule back on.

Richard Connors
03-19-2007, 01:10 PM
Richard, what you describe suggests to me that the data type for the ID field in Alpha Four was numeric, and Alpha Five converted it to character. Did you append records from the Alpha four table, or did you just begin using a copy of the A4 dbf?

In any case the answer to your original question is now clear. The "99 " sorts to the top of the list, and is being used by the autoinc field rule as expected.

If you turn off the field rule you can define an "update" operation that will prepend leading zeros using an expression like this:

padl(alltrim(ID), len(ID), "0")

Yes, this sounds right to me. Can you give me a little more detail about preparing the update? The genie doesn't seem to allow what I need to do.

Richard Connors
03-22-2007, 11:07 AM
OK, got it! Had to mess around with the indexes and not use the genie, but it worked! Thanks for everything.

Richard