zarkfoo
07-02-2004, 08:19 AM
I've designed a table with the field "ID" as datatype "AutoNumber". The Field Size is "Long Integer" and the New Values is "Random". Is there a way where it will only randomly generate a positive number? Right now it does both, a positve and negative.
Thanks in advance for your help.
Mile-O
07-02-2004, 08:26 AM
I've designed a table with the field "ID" as datatype "AutoNumber". The Field Size is "Long Integer" and the New Values is "Random". Is there a way where it will only randomly generate a positive number? Right now it does both, a positve and negative.
Thanks in advance for your help.
Firstly, try and name the field 'ID' more appropriately to fit in with your table as the primary key is what you will essentially be joining between other tables - it pays to keep them consistent:
i.e.
EmployeeID
OrderID
InvoiceID
As for your question, if you are already generating random numbers, youc an use the Abs() function to drop the negative sign.
zarkfoo
07-02-2004, 08:39 AM
Mile... thanks for your response. I was using the field "ID" which Access assigned as my primary key because I didn't assign one. So if I'm understanding you correctly, I need to assign a primary key instead of Access, but where do I use the Abs() function if it automatically generates the random number?
Mile-O
07-02-2004, 08:42 AM
Sorry, I just realised you were talking about a Random autonumber and not a typical numeric field.
Why do you want to change these to positive values?
Any way, it's an Autonumber field - you can't change its values.
zarkfoo
07-02-2004, 08:59 AM
In my web application I'm coding, I was going to list the primary key on the page but didn't want it to look weird by having a negative value in it... that's all... but I do want it randomly generated.
Mile-O
07-02-2004, 09:02 AM
There's a negative because the Autonumber falls within a range of minus ten million or so and ten million or so. So, if you display the negatives as positive then you could have an "opposite" that's negative.
for the SQL to convert:
SELECT Abs(ID) As AutoID
FROM MyTable;
Pat Hartman
07-02-2004, 11:06 AM
Certainly you can display the numbers as positive but if you expect to use the autonumber to find a record, you'll need a hidden field that tells you that it should be negative.