Cant make changes until a transaction has been started ....

I have a form which calls a codeunit, using the syntax Codeunit.RUN

That codeunit modifys the Item table. When I run the codeunit, the first time it attempts to modify a record I get the following message :

‘You cannot make any changes in the database until a transaction has been begun’

I really thought I understood about write transactions. What am I doing wrong ? I originally had the code as a function within the form and got the same message. This is V4 sp1 using the native database.

Probably you are in a browse- or a snapshot transaction. In these you cannot write to the DB.

You should search for the word CURRENTTRANSACTION somewhere in your code.

I think this is a newer version of “You cannot make any changes in the database from this trigger.”

Any chance of a snippet of code?

Did you state that this was FDB or SQL, Navision database?

SQL will worry more about what you are getting.

Indicate if you are using an existing object and where you are adding the coding. Give sample of coding.

This is my own form and I definitely havent used the words ‘CURRENT TRANSACTION’.

This is using the Navision database.

I wonder if this is because my form includes a subform which displays Item records. I was hoping to make a pass through the Item table and set a couple of booleans, which are then used in the filtering of the subform. The sourcetable for my mainform is one of my own making.

Ok, this is not the problem. I thought you were using SQL-server.

In which trigger do you call the codeunit?

What trigger is calling the code? There are a number of triggers that do not allow modifications to the database; if you try to modify the database from one of these triggers you will get an error. In versions 3.x and earlier the error message was “You cannot make any changes in the database from this trigger.” In version 4.x the error message is “You cannot make any changes in the database until a transaction has been started.”

Its called from a function which is, in turn, called from the OnAfterGetRecord trigger for the mainform.

I am afraid that is not possible.
I think it is better to create a function in the subform. The main form calls that function in the “OnAfterGetRecord”.

The function selects the records to be shown, but MARK’s them (using Rec!), then at the end, put a MARKEDONLY(TRUE); and the subform will show you only the marked record. This will work and as an extra:you don’t write to the DB.

Ahh … I didnt realise this message was to do with triggers that dont allow updates to the database. I moved the call from the OnAfterGet Record trigger to a button on the form. Problem solved, thank you.