10 Replies Latest reply on Feb 5, 2010 12:12 AM by tmack2

    Copy data,table to table

    tmack2

      Title

      Copy data,table to table

      Post

      I want to copy field information from several fields in one table to another table, into alike fields.

      The script I am using is this,

       

      (If[IsEmpty(Child::Home_Address)]

       Go to Layout["CLIENT DATA"(Client)]

      Goto Field[Client::Home_Address]

      Copy[select]

      Goto Layout"[CHILD DATA"(child)]

      Go to Field[Child::Home_Address]

      Paste[No style]

      Endif

       

      I do this for each field of information I want.

       

      Basicly, if the address information is empty in the child table and it will be the same as the parents address info, I want to copy the info.

      I do not want to have to repeat  the step for each field of information.

      Is there a way around is?

        • 1. Re: Copy data,table to table
          mrvodka
             Set the values from the first table to a bunch of variables. Then go to the layout of your second table occurrence, make the new records, and set the fields with the variable values.
          • 2. Re: Copy data,table to table
            philmodjunk
              

            Copy and Paste are definitely steps to avoid using in scripts if there are alternatives (Such as Set Varible and Set Field) available.

             

            In this case, you might want to set things up a bit different to get the same results and avoid copying data from the parent record. When you copy data this way, any updates made to the parent's address will force you to track down and make matching updates for any children with the same address.

             

            You might do this instead:

             

            Keep your address fields in place and leave them blank when they should have the same address as the parent in  the related client record.

             

            Now create a matching calculation field for each address field that display the related Client Address field if the child's address field is blank. Here's an example using the Home_Address field:

             

            cHome_Address would be defined as: If ( IsEmpty(Home_Address) ; Client::Home_Address ; Home_Address)

             

            For better consistency, you might define a field formatted as a check box with "Same address as Parent" or some such text to make the calculation read:

             

            If ( IsEmpty(SameAsParent) ; Client::Home_Address ; Home_Address)

            • 3. Re: Copy data,table to table
              tmack2
                

              Phil, you hit it on the head! this is what I am trying to do. I however can not get my caculation to work. I can however create a scripted button to do this.

               I am not a programmer. I am now just getting started without bennefit of schooling or books.

              Can I ask you for a hint as to what to do with out getting a complete answer as what to do? leave me some work so I can learn.

              • 4. Re: Copy data,table to table
                philmodjunk
                  

                "leave me some work so I can learn."

                Can't see how to add to my last post and still do that...

                 

                Let's try this:

                You say you "can't get my calculation to work".

                 

                How doesn't it work?

                 

                Examine your calculation in detail. How is it different from my example?

                 

                Are you defining a text field with an auto-entered calculation or a calculation field? (You should use a calculation field.)

                • 5. Re: Copy data,table to table
                  tmack2
                    

                  Thank you for your help.

                  Color me stupid, I am missing something.

                  I have made it simpler for me by creating a sample on a single page. Here is what I am doing and this is the error I am receiving.

                   

                  (This action connot be performed because this field is not modifiable).

                   

                  My sample:

                  Attempt to show the "home address" info in the "mail address"

                   

                  Field Name & Type = "Home_Address" text field.

                                              "Mail_Address" text field.

                                              "cMail_Address" calculation field. Set behavior as "checkbox". Calculation reads as,

                   

                  (If ( IsEmpty ( Mailing_Address );Mailing_Address;Home_Address )

                   

                  Action, check the checkbox and receive the error of, (This action connot be performed because this field is not modifiable)

                  • 6. Re: Copy data,table to table
                    philmodjunk
                      

                    Thanks, that points to the problem. I had to puzzle over the phrase "set behavior as checkbox" before I figured out what you are doing.

                     

                    My original expression does not use a check box field. I threw that idea in at the bottom of my post as a possible enhancement that lets you choose whether or not to display the parent's address. Don't try to set up the field as a check box and you'll see the calcuation automatically displays the parent's address whenever the child's address field is empty.

                     

                    If you want the check box field so that so can turn this feature off and on, keep reading:

                     

                    The checkbox field has to be a separate field--not a setting in Field/control | Setup...

                     

                    Define a text field named "SameAsParent"

                    Use Manage | Value Lists... to  create a value list with just one custom value: "Select Parent".

                     

                    Now, change the calculation for cMail_Address:

                     

                    If ( IsEmpty(SameAsParent) ; Client::Home_Address ; Home_Address)

                     

                    Click the checkbox and the parent's address appears. Clear it and you see the child's address (or blank if the fields are empty).

                    • 7. Re: Copy data,table to table
                      tmack2
                        

                      Thank you, things are starting to work out, however it looks now that I need to have more fields on my lay out than I want.

                      I tried to overlay the two fields,("cmail_address" & "mail_address") in hopes that I would be able to type into the "mail_address" field, but it is not working.

                      I overlayed the two fields. One on top of the other.

                      If I put "mail_address" on top of "cmail_address", I am able to type in the field but I am not able to use the option of the calc;(the result is hidden behind the other field). If I reverse this step I get the error of,

                       

                      (This action can not be performed because this field is not modifiable).

                       

                      I tried a couple of things.

                      Attached  the same calculation to a button. Nothing happens.

                      Tried another script, "set variable" using the same calc. nothing happens.

                       

                      So again, I would like to have the choice of typing the info in the fields and; or showing the parent info but I do not want to confuse the user by having two sets of the same fields, one that can be entered in to  and the other that can not be entered in to.

                      Will this be possible?

                       

                      • 8. Re: Copy data,table to table
                        tmack2
                          

                        OK, I have created a script using set field for all the fields I want changed and it works, however, I have to check the "same as parent" check box and then click a button to have it enter the info. I then added to the script, to remove the info if I un-check the "same as parent" checkbox, but also have to click a button to make changes.

                         

                        I now have three different scripts that do; in part ,what I want to do.

                        So if I ditch the copy & paste, do to the reason given in the first part of this thread, I am left with two solutions to work with. A calculation field that I can not enter into and  a complicated button that has to be clicked and check box that has to be checked and un-checked.

                        There just has to be a happy medium somewhere! isn't there?

                         

                        • 9. Re: Copy data,table to table
                          philmodjunk
                            

                          Don't see how you can get around having both sets of fields on the same layout for data entry if you use the calcuated field approach. You could create a second layout for printing that only shows the one set of fields, however.

                           

                          If you prefer the sripted approach, you shouldn't need any calculation fields or a check box. You'd just keep the data fields.

                          • 10. Re: Copy data,table to table
                            tmack2
                              

                            http://forum-en.filemaker.com/t5/user/viewprofilepage/user-id/3005Philmodjunk, Thank you for all the help!

                            I now know of, and I am able to create a script using the set field option. This I feel will help me greatly!

                            I am happy with the script as I have it. Thanks to you