Alpha Video Training
Results 1 to 22 of 22

Thread: Copy previous record from two tables

  1. #1
    Member
    Real Name
    Ivan Lozano
    Join Date
    Apr 2013
    Location
    Azusa, CA. LA County
    Posts
    400

    Default Copy previous record from two tables

    Hello,

    Im trying to create an operation that will copy the previously entered record of two tables. I know how to accomplish this when Im copying a record in just one table, but two tables has me stumped.

    I have a form based on two tables that are joined as a set, and I want to add a button that when pressed will copy the last record from table a, and table b. Then I want to place this copied record into edit mode to change to a new students ID#. The ID# needs to update the parent and child record.

    Is there way to accomplish using the genies? Im barely learning xbasic so this is a bit overwhelming to write. Anything will help, Thanks.

    -Ivan

  2. #2
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Copy previous record from two tables

    Are you saying you want to make one record in a table out of two records in other tables, combining them? The destination has the same fields as both the other tables?

    Whether you use action scripting or xbasic the process will involve copying the record from either of the source tables to the destination table and writing the desired fields from the other source table to the new destination table record.

    Not the sort of thing the genies can handle.
    There can be only one.

  3. #3
    Member
    Real Name
    Ivan Lozano
    Join Date
    Apr 2013
    Location
    Azusa, CA. LA County
    Posts
    400

    Default Re: Copy previous record from two tables

    its more like duplicating the record (in the respective tables), then placing the duplicated record into edit mode to change the student ID. This is all happening in a form by the way.

    I was afraid you would say the genies are unable to accomplish this.

    Do you know of any great learning tools for learning xbasic?

  4. #4
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Copy previous record from two tables

    If you have two table records from which you want to make one final record it is not duplicating (to Alpha). You have to create a record in the destination table and fill in the fields form both of the source records. Alternatively, copy the record from one table and fill in the fields from the other.

    I'll try to work up a sample.
    Attached Files Attached Files
    Last edited by Stan Mathews; 08-13-2014 at 06:19 PM.
    There can be only one.

  5. #5
    Member
    Real Name
    Ivan Lozano
    Join Date
    Apr 2013
    Location
    Azusa, CA. LA County
    Posts
    400

    Default Re: Copy previous record from two tables

    See my attached example

    If you look at the form, and the table set up, Im not trying to combine records. I'm trying to copy a previous record and replace fields manually. See the button Action Scripting so you can kind of see what im trying to accomplish here. The action scripting I placed there is not doing what I want it to do.
    Attached Files Attached Files

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

    Default Re: Copy previous record from two tables

    Hi Ivan,
    I think the problem in trying to copy the record in the browse and then pasting it into the new parent record browse is the link is also being copied from the source and is not linking to the new record. Perhaps a lookup field rule in the notes table would be a better way to use a previous record after you have duplicated the parent record.
    Robin

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

  7. #7
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Copy previous record from two tables

    See if this does what you want.
    Attached Files Attached Files
    There can be only one.

  8. #8
    Member
    Real Name
    Ivan Lozano
    Join Date
    Apr 2013
    Location
    Azusa, CA. LA County
    Posts
    400

    Default Re: Copy previous record from two tables

    PERFECT!! :) That did do it stan, that's exactly what I wanted to do. Now I need to research what you did in xbasic so I can understand whats going on and how to do it on my own. I have other tables where I need to perform this type of operation so I need to learn thing quick.

    Thank you again stan.

  9. #9
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Copy previous record from two tables

    Commented version of the script.

    Code:
    'save the current record on the form
    topparent.commit()
    'establish pointer to parent table (1)
    src1 = table.current(1)
    'establish pointer to child table(2)
    src2 = table.current(2)
    'save current record data from both tables to variables
    record_data1 = src1.record_data_get()
    record_data2 = src2.record_data_get()
    'start a new parent record
    src1.enter_begin()
    'write previous parent record data to parent table
    src1.record_data_set(record_data1)
    src1.enter_end(.T.)
    'get the linking field value from the new record as created by auto-increment
    new_id = src1.orientation_id
    'start a new child record
    src2.enter_begin()
    'write previous child record data to parent table
    src2.record_data_set(record_data2)
    'set/overwrite the linking field value to the new parent record linking value
    src2.Orientation_Id_Fk = new_id
    src2.enter_end(.T.)
    'resynch the form to the set
    topparent.resynch()
    'refresh the display of the form
    topparent.repaint()
    There can be only one.

  10. #10
    Member
    Real Name
    Ivan Lozano
    Join Date
    Apr 2013
    Location
    Azusa, CA. LA County
    Posts
    400

    Default Re: Copy previous record from two tables

    So just to clarify, to establish a pointer like in "src1=table.current(1)", this points to the first table in the set which is the parent, right?

    With that logic if this particular set had 5 tables, and I only wanted to copy a record in the third table in the set, the function would be "src3 = table.current(3)" right? Where "src3" is just the name of the variable. Is my thinking on the right path?

  11. #11
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Copy previous record from two tables

    Correct. The # supplied refers to the vertical position of the table in the set when viewed in the set editor. No adjustment is made for relative "importance" of the linked table. IOW, count straight down ignoring whether the linked table is linked to the parent or linked to another child table.
    There can be only one.

  12. #12
    Member
    Real Name
    Ivan Lozano
    Join Date
    Apr 2013
    Location
    Azusa, CA. LA County
    Posts
    400

    Default Re: Copy previous record from two tables

    Is it possible to cut this xbasic code in half? In other words, create an operation that copies src2 record, and then create a different button that will paste the record once you've navigated to a record of your choosing?

    I already tried to break this up but I guess i'm not doing it correctly.

    My goal is to be able to navigate to a parent record and edit roughly 3 fields, then enter a note in the child table in regards to the edited fields, copy said note from the child table. Then navigate to a different parent record, manually edit roughly three fields again, and paste the previous record note to this record (all while updating the linking field ID's ofcourse). I tried to establish variables within the form to store the info, but the variable keeps losing its definition???

  13. #13
    Member
    Real Name
    Ivan Lozano
    Join Date
    Apr 2013
    Location
    Azusa, CA. LA County
    Posts
    400

    Default Re: Copy previous record from two tables

    Well, I got it to copy and paste, with two separate buttons. But this only works if I stay on the same parent record. Once I navigate and try to paste, it does nothing. Also the ID's are not updating

  14. #14
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Copy previous record from two tables

    Sorry, your description lost me.
    There can be only one.

  15. #15
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Copy previous record from two tables

    This part of the script captures the values in the current record.

    Code:
    'establish pointer to parent table (1)
    src1 = table.current(1)
    'establish pointer to child table(2)
    src2 = table.current(2)
    'save current record data from both tables to variables
    record_data1 = src1.record_data_get()
    record_data2 = src2.record_data_get()
    If you are splitting the script into two parts, the second script will not know anything about what happened before unless you make the variables available to it.

    Code:
    dim shared src1 as P
    dim shared src2 as P
    dim shared record_data1 as B
    dim shared record_data2 as B
    'establish pointer to parent table (1)
    src1 = table.current(1)
    'establish pointer to child table(2)
    src2 = table.current(2)
    'save current record data from both tables to variables
    record_data1 = src1.record_data_get()
    record_data2 = src2.record_data_get()
    Now the first of the second script should establish the connection to the same variables.

    Code:
    dim shared src1 as P
    dim shared src2 as P
    dim shared record_data1 as B
    dim shared record_data2 as B
    'rest of second script goes here
    There can be only one.

  16. #16
    Member
    Real Name
    Ivan Lozano
    Join Date
    Apr 2013
    Location
    Azusa, CA. LA County
    Posts
    400

    Default Re: Copy previous record from two tables

    Heres how I split the script:

    "Copy Script"
    dim shared src2 as P
    dim shared record_data2 as B

    'establish pointer to child table(2)
    src2 = table.current(2)

    'save current record data from both tables to variables
    record_data2 = src2.record_data_get()

    "Paste Script"
    'get the linking field value from the new record as created by auto-increment
    new_id = src2.Apprentice_wp_id_fk
    'start a new child record
    src2.enter_begin()
    'write previous child record data to parent table
    src2.record_data_set(record_data2)
    'set/overwrite the linking field value to the new parent record linking value
    src2.Apprentice_wp_id_fk = new_id
    src2.enter_end(.T.)
    'resynch the form to the set
    topparent.resynch()
    'refresh the display of the form
    topparent.repaint()

    Which is copying the record just fine but its not replacing the ID linking field to the new parent record? What am I doing wrong.

  17. #17
    Member
    Real Name
    Ivan Lozano
    Join Date
    Apr 2013
    Location
    Azusa, CA. LA County
    Posts
    400

    Default Re: Copy previous record from two tables

    I think I see the problem, am I missing the pointer to the parent table?

    so script 1&2 should still have:

    dim shared src1 as P
    src1.table_current(1)

    Except since I don't want to copy anything from the first table, Ill leave out the record_data_get() part. Is that right?

    and script two should point to table one to overwrite the field in table 2 of the record we just pasted.

  18. #18
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Copy previous record from two tables

    'get the linking field value from the new record as created by auto-increment
    new_id = src2.Apprentice_wp_id_fk
    This is not were the linking value is established. The child table needs the value of the auto-increment (I assume) field in the parent table to which you want to link. If you are navigating to a diifferent parent record or beginning a new parent record you would

    Code:
    "Paste Script"
    'get the linking field value from the current parent record or new parent record as created by auto-increment
    src1 = table.current(1)
    new_id = src1.Apprentice_wp_id_fk
    'start a new child record
    src2.enter_begin()
    'write previous child record data to parent table
    src2.record_data_set(record_data2)
    'set/overwrite the linking field value to the new parent record linking value
    src2.Apprentice_wp_id_fk = new_id
    src2.enter_end(.T.)
    'resynch the form to the set
    topparent.resynch()
    'refresh the display of the form
    topparent.repaint()
    You may have a different name for Apprentice_wp_id_fk in the parent table so you would change this to match.
    There can be only one.

  19. #19
    Member
    Real Name
    Ivan Lozano
    Join Date
    Apr 2013
    Location
    Azusa, CA. LA County
    Posts
    400

    Default Re: Copy previous record from two tables

    UPDATE

    Hers my Script 1 "Copy Script"

    dim shared src1 as P
    dim shared src2 as P
    dim shared record_data2 as B

    'establish pointer to child table(2)
    src1 = table.current(1)
    'establish pointer to child table(2)
    src2 = table.current(2)

    'save current record data from both tables to variables
    record_data1 = src1.record_data_get()
    record_data2 = src2.record_data_get()


    Heres my script 2 "Paste Script"

    'get the linking field value from the new record as created by auto-increment
    new_id = src1.Apprentice_id_pk
    'start a new child record
    src2.enter_begin()
    'write previous child record data to parent table
    src2.record_data_set(record_data2)
    'set/overwrite the linking field value to the new parent record linking value
    src2.Apprentice_wp_id_fk = new_id
    src2.enter_end(.T.)
    'resynch the form to the set
    topparent.resynch()
    'refresh the display of the form
    topparent.repaint()

    The first script goes off without a hitch, the 2nd script gives me an error which I wrote in red. It states "Access is denied"

  20. #20
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Copy previous record from two tables

    I think you need to either establish or reestablish the parent table pointer in the paste script. When you establish it in the first script and then navigate to another parent record the pointer still references the original record (I think, never tried anything like this before).

    So in the paste script I would

    src1 = table.current(1)
    new_id = src1.Apprentice_id_pk

    At least I'm hoping that's the issue.
    There can be only one.

  21. #21
    Member
    Real Name
    Ivan Lozano
    Join Date
    Apr 2013
    Location
    Azusa, CA. LA County
    Posts
    400

    Default Re: Copy previous record from two tables

    JACKPOT! That worked stan, thank you again. I really appreciate your patience and help with this.

    Since you say you've never done anything like this before, is this a good way of doing this? Your obviously experienced and knowledgeable, so Im wondering if im going about this application in the right way?

  22. #22
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Copy previous record from two tables

    I've never done anythng like this in terms of any application. My work is data warehousing and data mining. I combine input from outside sources that is related but not inherently compatible. One example is inovicing to use from multiple vendors. I take the invoicing data from them electronically and normalize it to one standard and report profitability, etc to our buyers.
    There can be only one.

Similar Threads

  1. Copy Previous Record
    By John Fringer in forum Application Server Version 9 - Web/Browser Applications
    Replies: 0
    Last Post: 11-20-2008, 11:09 PM
  2. Copy previous record
    By Daniel Earley in forum Alpha Five Version 5
    Replies: 3
    Last Post: 08-20-2002, 05:42 PM
  3. copy previous record
    By Bill in forum Alpha Five Version 4
    Replies: 0
    Last Post: 09-17-2001, 03:10 AM
  4. Copy previous record - NOT
    By Ron McCormack in forum Alpha Five Version 4
    Replies: 2
    Last Post: 08-11-2000, 06:21 AM
  5. copy previous record
    By David Gilbertson in forum Alpha Five Version 4
    Replies: 6
    Last Post: 05-12-2000, 06:15 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
  •