NetTalk Central

Author Topic: Using Loop until Access: on a form  (Read 5542 times)

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Using Loop until Access: on a form
« on: August 18, 2007, 04:20:04 AM »
Hi All,

I'm using the following to calc the totals of records in a browse on a form to make sure it balances before the user saves the current record. I have the code in the ValidateEnd embed. I can use fetch but any files I try to use Loop Until Access on always fail on the next. The funny thing is I can use fetch to return a single record. What am I doing wrong? This particular form I need to do lots of loops...

      L:POC_Amount = 0
      POC:TRAN = p_web.GetSessionValue('POT:TRAN')
      POC:TRN2 = 0
      Set(POC:TRAN_KEY,POC:TRAN_KEY)
      Loop Until Access:POCOST.Next()
        If POC:TRAN ~= p_web.GetSessionValue('POT:TRAN')
          Break
        End
        L:POC_Amount += POC:AMOU
      End

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Using Loop until Access: on a form
« Reply #1 on: August 19, 2007, 05:34:24 AM »
Hi Kevin,

You should not assume that tables have been opened for you.
I suspect the problem in this case is the missing

Access:POCOST.UseFile() before the call to SET.

Event better would be an explicit
Acess:POCOST.Open() and Access:POCOST.Close() around the code.

Cheers
Bruce


kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Using Loop until Access: on a form
« Reply #2 on: August 19, 2007, 03:23:30 PM »
Hi Bruce,

that did not work. I guess if the file was not open a fetch would not have worked either but fetch works.

are you able to do a simple test on your end or do you want me to send you my app to confirm if it is a bug or I am an idiot?

I'll keep doing some testing on my end and get back to you if it starts working

Code below which does not seem to work. First message returns the correct tran# but code never makes it to message('1')

Cheers,

Kevin


 !***Balance PO Dist against PO Tran
      If Access:POCOST.Open()
        Message('Error opening POCOST')
      Else
        L:POC_Amount = 0
        POC:TRAN = p_web.GetSessionValue('POT:TRAN')
    message('POC:TRAN=' & POC:TRAN)
        POC:TRN2 = 0
        Set(POC:TRAN_KEY,POC:TRAN_KEY)
        Loop Until Access:POCOST.Next()
    message('1')
          If POC:TRAN ~= p_web.GetSessionValue('POT:TRAN')
            Break
          End
          L:POC_Amount += POC:AMOU
        End
        If Access:POCOST.Close()
          Message('Error closing POCOST')
        End
      End
   !   If L:POC_Amount ~= p_web.GetSessionValue('POT:AMOU') + p_web.GetSessionValue('POT:TaxAmount')
   !     Exit
   !   End
      Message('L:POC_Amount=' & L:POC_Amount)

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Using Loop until Access: on a form
« Reply #3 on: August 19, 2007, 11:32:09 PM »
Hi Kevin,

You gotta lay off those beers on the weekend  ;)

From my note
>> I suspect the problem in this case is the missing
>> Access:POCOST.UseFile() before the call to SET.

This is consistent with the FETCH working, because the Fetch does a UseFile internally. The Next also does on internally but it comes AFTER the SET, so the SET is essentially ignored, so the NEXT fails.

Cheers
Bruce





kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Using Loop until Access: on a form
« Reply #4 on: August 20, 2007, 01:49:56 AM »
Thanks Bruce that worked - Beers I wish! Maybe more sleep deprivation with the new one awake all night.... at least you confirmed I'm the idiot!