Announcement

Collapse
No announcement yet.

Need help

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need help

    Hi guys,

    I need heed some help with an application. I want to insert a record in another table (Table B) when I update or insert a record in Table A. But here is the catch. One of the values that is being inserted has to be incremented based on the the highest existing value.

    Basically if I add a new branch to branches table, I want to also automatically add a record with that branch's name for salaries payable in another table (Accounts). Now lets say that table already has accounts for 3 branches, so the new one will have to increment this number by 1.

    This is for the Chart of Accounts.

    Any help and/or guidance will be much appreciated.

    I think its gotten too late, that's why nothing is clicking!

  • #2
    To update another table you need to set an event onafterinsert/update. In this event you can do all you like on the second table.
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development
    www.scriptcase.eu / www.scriptcase.nl

    Comment


    • #3
      Hey Albert,

      Thanks for the reply. Yeah I got that much figured out. But Im still working on a way to update the second table with a new max +1 value at the same time.

      Update:

      I figured it out! Created a hidden field to calculate the next value, then inserted it in the same table.
      Last edited by gamer99; 10-07-2013, 07:43 AM.

      Comment


      • #4
        To select a max value from the table you can also use 'select max(myfield) as something from mytable and use something to add to your sql statement. You don't need hidden fields to achieve things like this.
        Albert Drent
        aducom software netherlands
        scriptcase partner, reseller, support and (turn-key) development
        www.scriptcase.eu / www.scriptcase.nl

        Comment


        • #5
          Yes but I don't think you can select the max value from the table and insert it in the same table at the same time.

          UPDATE: Where are my manners! Thank you soo much for all the help and guidance, its really appreciated.
          Last edited by gamer99; 10-08-2013, 07:51 AM.

          Comment


          • #6
            No, the only way to be able to is to use an autosequence. But if the time between both actions is short enough the risk is small. On the other hand, using a hidden var. doesn't solve this time issue afaik. But It's hard to tell so from a distance.
            Albert Drent
            aducom software netherlands
            scriptcase partner, reseller, support and (turn-key) development
            www.scriptcase.eu / www.scriptcase.nl

            Comment

            Working...
            X