NetTalk Central

Author Topic: Opening Files to get single record  (Read 3168 times)

rayrip

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • Email
Opening Files to get single record
« on: April 06, 2021, 05:00:18 PM »
Hi,
I'm trying to get a field from a single record file (comptwo). This is the code right after the openFiles Routine:

  get(comptwo,1)
  if error()
    message(error() & 'After opening files')
  else
    loc:startnum=COM2:startnum
    message(loc:startnum)
  .

The code runs when I open the form if I am changing the record (and gets my field), but doesn't get run when I am adding a record.. which is where I need it because I need that loc:startnum for my customer ID# when adding a new record.

I've tried this under the preInsert embed... but the file is not open... should I just go ahead and call the openFiles routine in the PreInsert?

Trying to figure the proper way to do this so I don't cause problems elsewhere.

Thanks,

Ray

rayrip

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • Email
Re: Opening Files to get single record
« Reply #1 on: April 06, 2021, 05:35:36 PM »
I went ahead and called openFiles in the PreInsert 4 end embed code:

  do openFiles
  get(comptwo,1)
  loc:startnum=COM2:startnum+1
  com2:startnum=loc:startnum
  access:comptwo.tryupdate()

  CUS:CustomerNum=loc:startnum
  p_web.SetSessionValue('CUS:CustomerNum',CUS:CustomerNum)

Seems to work and this way it doesn't increase the startnum on a change record. Not sure why openFiles isn't called when changing a record?

As usual, I type the question and I get it figured out right after.. If anyone has a better way please let me know.
Thanks,
Ray


Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Opening Files to get single record
« Reply #2 on: April 09, 2021, 03:58:40 AM »
>> I've tried this under the preInsert embed... but the file is not open... should I just go ahead and call the openFiles routine in the PreInsert?

yes.