Hi,
Is there an "easy" way to write a full record (all fields) using "INSERT
INTO..." into a table which has an AutoNumber field?
Normally, to write a full new record I would use:
INSERT INTO [tblTable] VALUES (Value1, Value2, ...);
If (say) the first field (Value1) is an AutoNumber, what value can you put
that will preserve the auto-increment function?
NULL doesn't work because the field is a Long.
Omitting the field (via a comma placemarker) doesn't work either.
0 (zero) works in that the record will be written, but the AutoNumber field
will be set to 0 (contrary to what I have read that there is no way to
override an AutoNumber field!).
What does work is to specify all of the field names (except the AutoNumber
field -- leaving it out altogether allows the auto-increment function to
work normally). For example (Field1 is AutoNumber):
INSERT INTO [tblTable] (Field2, Field3,...) VALUES (Value2, Value3,...);
This is OK (and it is what I have done), but if you have a record with a
lot of fields, it means a lot of extra typing (and chances for errors) to
enter all of the field names except for the one which auto-increments. Is
there a simpler way to do this? (Such as a keyword "value" that says
"ignore me")
Or perhaps you think that it is good practice to list the field names in
the syntax anyway (even when there is no AutoNumber field and regardless of
how many fields there are)?
Cheers,
Lyn.