Board index » delphi » Adding new records with MS Access Autoinc field

Adding new records with MS Access Autoinc field

I have a set of MS Access 97 tables linked via an autoinc field in the main
table.
I have some code something like this

         QryProject.Insert;
         QryAddress.Insert;
         ...

            QryProject.Post;
            QryProject.Refresh;
            QryAddress.Post;

(The Address is linked to the Project table via the autoinc field so I need
to assign that value to it before I can post it.)

If I don't call Refresh the value of the autoinc field is still 0 after the
post. If I call Refresh I get an error stating

   "The key value for this row has been changed or deleted at the data
source. The local row is now deleted."

I must be missing something here. How do I do the post without getting this
error?

 

Re:Adding new records with MS Access Autoinc field


I have found a way to get this to work. Only problem is I don't understand
the implications of everything I did so it may cause a lot of problems. Any
advice on this?

First I tried just trapping the error message with a try .. except block but
the error still showed up.

What I did was change the CursorLocation to clUseServer and the CusorType to
clDynamic. This is the part I don't understand. When I do this without the
try..except block I get a message "The operation requested by the
application is not supported by the provider". When I put in the try..except
block the error is trapped and everything seems to work OK.

      if FrmAddPermit.ModalResult = mrOK then
      begin
         try
            DM1.QryPermit.Post;
            DM1.QryPermit.Refresh;
         except
         end;
         NewPlink := DM1.QryPermitPLINK.Value;
         DM1.QryPermit.Close;
         DM1.QryPermit.Parameters[0].Value := NewPlink;
         DM1.QryPermit.Open;
         DM1.QryAddr.Open;
         DM1.QryPInfo.Open;

This ADO is nice but there is a lot I still don't understand. Does anyone
have any idea why this works or at least appears to work?

Quote
Bill Cart <bc...@morpc.org> wrote in message

news:86hrq0$ms81@bornews.borland.com...
Quote
> I have a set of MS Access 97 tables linked via an autoinc field in the
main
> table.
> I have some code something like this

>          QryProject.Insert;
>          QryAddress.Insert;
>          ...

>             QryProject.Post;
>             QryProject.Refresh;
>             QryAddress.Post;

> (The Address is linked to the Project table via the autoinc field so I
need
> to assign that value to it before I can post it.)

> If I don't call Refresh the value of the autoinc field is still 0 after
the
> post. If I call Refresh I get an error stating

>    "The key value for this row has been changed or deleted at the data
> source. The local row is now deleted."

> I must be missing something here. How do I do the post without getting
this
> error?

Re:Adding new records with MS Access Autoinc field


Bill,

Quote
> What I did was change the CursorLocation to clUseServer and the CusorType
to
> clDynamic. This is the part I don't understand. When I do this without the
> try..except block I get a message "The operation requested by the
> application is not supported by the provider". When I put in the
try..except
> block the error is trapped and everything seems to work OK.

The statement that raises the exception is DM1.QryPermit.Refresh.  To
"refresh" a server-side cursor, you can use

DM1.QryPermit.UpdateCursorPos;
DM1.QryPermi1.Resync([]);

-Eric Harmon

Re:Adding new records with MS Access Autoinc field


Hi
I had the same problem but used ADOTable1.Requery in the table afterpost
event which worked with client cursor.
geoff

Other Threads