Delphi problems with Access Autonumber field.

Is there a trick to posting a new record to Access when there's an Autonumber field involved? I'm using .Append, setting the field values, and then using the .Post and I get an error if I don't set the autonumber value and I also get an error if I do set the autonumber value.  Any ideas?
dokkenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RBertoraCommented:
I think basically you are in trouble unless you use TQuery.

Using a TQuery you can do something along the lines..

Query1.Sql.Clear;
Query1.Sql.Add(
'insert into tablename values(field2,field3) values('One',500)' );
Query1.Open;

and similar thing for update..

note you do not provide field1 as it is autoinc field.

Rob;-)
0
RBertoraCommented:
Ah, sorry Query1.Execsql;
Rob ;-)
0
kretzschmarCommented:
hi dokken,

just set the required-flag to false on this field, if you have persistent fields.

if not then set this line after the open-statement
table1.FieldByName('NameOfField').Required := False;

meikl ;-)
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

dokkenAuthor Commented:
Meikl,

That worked great, post it as an answer so I can give you the points.
0
kretzschmarCommented:
well dokken,

just pasted:

set the required-flag to false on this field, if you have persistent fields.

if not then set this line after the open-statement
table1.FieldByName('NameOfField').Required := False;

glad to helped you
good luck again

meikl ;-)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dokkenAuthor Commented:
Thanks for the answer... it helped a lot.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.