Alpha Video Training
Results 1 to 8 of 8

Thread: Using <Tbl>.enter_begin() to populate other table removes current record

  1. #1
    Member
    Real Name
    Matthew Davison
    Join Date
    Jun 2010
    Location
    Buffalo, NY
    Posts
    36

    Default Using <Tbl>.enter_begin() to populate other table removes current record

    I have a table with event code called on the CanSaveRecord event to populate another table with a new record. This code does populate the other table but it removes the record that was just manually entered from the open table.Here is the code:

    ================
    CONSTANT ENTER=2
    dim tbl_mode as n
    tbl_mode=table.get("operation_summary").mode_get()
    if (tbl_mode=ENTER) then

    dim mt_num as c
    dim opcode as c
    mt_num=table.get("operation_summary").Mt_Number
    opcode=table.get("operation_summary").Op_Code

    cost_table=table.open("[pathalias.adb_path]\costs_summary")

    cost_table.enter_begin()
    cost_table.Mt_Number=mt_num
    cost_table.Op_Code=opcode
    cost_table.enter_end()
    cost_table.close()
    end if

    =================

    So again just to clarify the new record does appear in "costs_summary.dbf" however the manually entered record in "operation_summary.dbf" disappears as soon as it is entered. Is there a particular line in this code that removes that manually entered record? I'm unable to find anything that would cause the removal unless enter_begin() and enter_end() do something behind the scenes.

  2. #2
    Volunteer Moderator
    Real Name
    Alan Buchholz
    Join Date
    Oct 2000
    Location
    Delavan, Wisconsin
    Posts
    9,644

    Default Re: Using <Tbl>.enter_begin() to populate other table removes current record

    Matthew

    I'd suggest that you use the debug(1) command to help you with the coding.

    You have a few errors in your code and this will cause the cansave event to cancel the save of the original record.

    ie tbl_mode=table.get("operation_summary").mode_get() is not valid syntax
    Al Buchholz
    Bookwood Systems, LTD
    Weekly QReportBuilder Webinars Thursday 1 pm CST

    Occam's Razor - KISS
    Normalize till it hurts - De-normalize till it works.
    Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
    When we triage a problem it is much easier to read sample systems than to read a mind.

  3. #3
    Member
    Real Name
    Matthew Davison
    Join Date
    Jun 2010
    Location
    Buffalo, NY
    Posts
    36

    Default Re: Using <Tbl>.enter_begin() to populate other table removes current record

    That line of code does give me the correct mode of the table as far as I can tell. The function table.get(alias) gives me a table object. From there I can do <obj>.mode_get() with the table object i just received to get the table mode. It seems to be working correctly as far as I can see. What do you see that I am missing?

    The debugger progresses through the script exactly how I thought it would and correctly identified what mode the table was in.
    Last edited by Sperrrow; 06-24-2010 at 10:59 AM.

  4. #4
    Member
    Real Name
    Matthew Davison
    Join Date
    Jun 2010
    Location
    Buffalo, NY
    Posts
    36

    Default Re: Using <Tbl>.enter_begin() to populate other table removes current record

    I fixed the issue by placing this code in the OnSaveRecord event.

  5. #5
    Volunteer Moderator
    Real Name
    Alan Buchholz
    Join Date
    Oct 2000
    Location
    Delavan, Wisconsin
    Posts
    9,644

    Default Re: Using <Tbl>.enter_begin() to populate other table removes current record

    Quote Originally Posted by Sperrrow View Post
    I fixed the issue by placing this code in the OnSaveRecord event.
    Oops - do you mean no code? I don't see your code.
    Al Buchholz
    Bookwood Systems, LTD
    Weekly QReportBuilder Webinars Thursday 1 pm CST

    Occam's Razor - KISS
    Normalize till it hurts - De-normalize till it works.
    Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
    When we triage a problem it is much easier to read sample systems than to read a mind.

  6. #6
    Member
    Real Name
    Matthew Davison
    Join Date
    Jun 2010
    Location
    Buffalo, NY
    Posts
    36

    Default Re: Using <Tbl>.enter_begin() to populate other table removes current record

    Yeah I guess that would help if I posted it. I moved all of this code to OnSaveRecord:

    ================
    CONSTANT ENTER=2
    dim shared tbl_mode as n
    if (tbl_mode=ENTER) then

    dim mt_num as c
    dim opcode as c
    mt_num=table.get("operation_summary").Mt_Number
    opcode=table.get("operation_summary").Op_Code

    cost_table=table.open("[pathalias.adb_path]\costs_summary")

    cost_table.enter_begin()
    cost_table.Mt_Number=mt_num
    cost_table.Op_Code=opcode
    cost_table.enter_end()
    cost_table.close()
    end if

    =================

    Mind you I did change the variable declaration of tbl_mode to "dim shared tbl_mode as n" and also had that line in the CanSaveRecord event because I wasn't sure if you could get the table mode in OnSaveRecord.This code was left in CanSaveRecord:

    =====================
    dim shared tbl_mode as n
    tbl_mode=table.get("operation_summary").mode_get()
    =====================

  7. #7
    "Certified" Alphaholic
    Real Name
    Mike Christensen
    Join Date
    Nov 2005
    Location
    Michigan U.P.
    Posts
    5,937

    Default Re: Using <Tbl>.enter_begin() to populate other table removes current record

    Matthew,
    Instead of constantly obtaining a new table pointer with table.get() the following is more widely used.....(changes in red).
    Code:
    dim tbl as p
    tbl=table.get("operation_summary")
    if tbl.mode_get()="ENTER" then
        
           dim mt_num as c
           dim opcode as c
           mt_num=tbl.Mt_Number
           opcode=tbl.Op_Code
    
           dim cost_table as p
           cost_table=table.open("[pathalias.adb_path]\costs_summary")
    
           cost_table.enter_begin()
              cost_table.Mt_Number=mt_num
              cost_table.Op_Code=opcode
           cost_table.enter_end(.T.) 'default is .T. but like to be explicit
           cost_table.close()
    end if
    Just another way of doing it....pick and choose what works for you!! :)
    Mike
    __________________________________________
    It is only when we forget all our learning that we begin to know.
    It's not what you look at that matters, it's what you see.
    Henry David Thoreau
    __________________________________________




  8. #8
    "Certified" Alphaholic MoGrace's Avatar
    Real Name
    Robin
    Join Date
    Mar 2006
    Location
    Los Angeles
    Posts
    3,711

    Default Re: Using <Tbl>.enter_begin() to populate other table removes current record

    Also when opening another table to enter or change records, putting a flag to use with Enter_end() allows you to trap any errors that might end the script before the table is closed.

    Code:
    dim cost_table as p
    dim commit_flag as L
    commit_flag = .t.
    on error goto ERRMSG
    cost_table=table.open("[pathalias.adb_path]\costs_summary")
           cost_table.enter_begin()
              cost_table.Mt_Number=mt_num
              cost_table.Op_Code=opcode
           cost_table.enter_end(commit_flag) 
    cost_table.close()
    end
    ERRMSG:
    commit_flag = .f.
    'add custom error msg here
    RESUME NEXT
    Robin

    Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

Similar Threads

  1. Save record removes data in form
    By steve745 in forum Alpha Five Version 9 - Desktop Applications
    Replies: 5
    Last Post: 04-08-2009, 02:20 PM
  2. Populate one field with another on new record
    By Outlaw in forum Alpha Five Version 9 - Desktop Applications
    Replies: 5
    Last Post: 01-12-2009, 01:33 AM
  3. tbl.enter_begin(t)....tbl.enter_end(t)
    By enstorms in forum Alpha Five Version 9 - Desktop Applications
    Replies: 15
    Last Post: 09-21-2008, 03:47 PM
  4. Append data from current table from current table
    By BOB SULLIVAN in forum Alpha Five Version 8
    Replies: 4
    Last Post: 03-08-2007, 12:28 PM
  5. <tbl>.enter_begin() not working??
    By Mario Prieto in forum Alpha Five Version 5
    Replies: 5
    Last Post: 04-09-2003, 07:37 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •