Click to See Complete Forum and Search --> : AutoNumber in access


ohadbp
October 2nd, 2001, 03:51 AM
hi guys,

for my project i created a database in Access 2000.
In one of my tables my primary key is an autonumber.

my table fields are:

StatusNumber -> Autonumber
StatusName -> Text

in my project i wrote a statement that insert a new StatusName but i get an error becouze it needs me to send also a new StatusNumber.

why does the AutoNumber field need me to give him a number? how can i avoid that?

thanks,
ohad.

Cakkie
October 2nd, 2001, 04:44 AM
When iserting data using a SQL statement, you can specify which column the data need to go in. I assume the table is called tblStatus

' This will insert the first value in the first field, the second in the second field
INSERT INTO tblStatus VALUES(5,"Sometext")

' This will insert "SomeText" into StatusName, and 5 into StatusNumber
INSERT INTO tblStatus (StatusName, StatusNumber) VALUES("SomeText",5)

' both statements will fail, because statusnumber is autonumber, therefore, we omit it
INSERT INTO tblStatus (StatusName) VALUES("SomeText")




Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook