Bob_Hansen
Senior Member Members
    Offline
 WOW, They have the Internet on computers now!
Posts: 1861
Location: Salem, NH
Joined: Nov 24 th, 2002
|
Re: Automatic numbering
Reply #10 - Feb 11th, 2006 at 5:29pm
|
Print Post
|
Change From: Number = @XLR(@Fn, Number, "Number", "Number") +1
Change To: Number = @ToNumber( @XLR(@Fn, 99999999, "Number", "Number") ) +1
1. The @XLR returns a string so you need to convert the XLR result to a number: @ToNumber( @XLR(........) ) +1
2. The second value of that expression is the number the XLR is looking for. When it does not find that value, it keeps decreasing by one, until it finds the highest value in "Number". And then it does +1 to increase the value by one.
------------------------------------- Four examples: 1. If records have "Number" values from 1 to 158: the XLR looks for 99999999, does not find it, but does get the highest value,158, adds one, and returns a value of 159 for the next value to be assigned.
2. If entering the first record: it does not find 99999999, does get the value of 0, adds one, and returns a value of 1 of the next value to be assigned.
3a. If you had records with "Number" values from 1 to 278, and used XLR starting with 150: then the XLR would return the value of 151 because 150 does exist, and one is added.
3b. Same as above, but if you used XLR starting with 999, then the XLR would return 279, because 999 did not exist, the closest value to it was 278, one was added and 279 was returned. ----------------------------------
The initial 99999999 is just a very high number that will always be higher than any value assigned to "Number" in normal operations.
|