Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Help required for newbie on looping through records

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Help required for newbie on looping through records

    I am creating a new system that uses data from an Access database that has been in use for over 10 years.

    Because of this, I am limited in what I can do with regard to restructuring the tables etc.

    Some of the tables have become very large over time, with much of the information now redundant. While this information is not required on a day-to-day basis, we cannot delete it in case it is required in the future.

    There are 4 tables:

    Activities - Correspondence - Clients - Client_Contacts


    I have created duplicate tables (Activities_archive, Correspondence_archive, etc) and, with the guidance of other forum members (thanks Mike & Stan), have used action scripting to allow the user to select a client and move records from the main tables into the archive tables, and back again if required.

    My problem is as follows....

    The Activities, Clients and Client_Contacts tables all contain the Client_ID field, making it easy to select and move records based on the value of this field. The Correspondence table is only linked to the Activities table via the Activity_ID field.

    I guess what I need to do is read the Activity_ID field value for each record in the Activity table where the Client_ID field matches the selected client (currently placed in a variable), and then search for records in the Correspondence table where the Activity_ID field value matches.

    a/ Is this the best way to go about it, or is there a better way (maybe based on a table set)?

    b/ Any script examples would be REALLY appreciated.

    Thanks in advance
    If computers are so clever how come someone as dumb as me has to tell them what to do?

    #2
    Re: Help required for newbie on looping through records

    This jewel in the online store has a section on Duplicating Records in a Set which will make your life much easier. The actual implementation of moving the desired records to the archive tables and recalling them later will be somewhat different than the duplication processs but the looping principles illustrated should be the same.

    Available as a pdf for download and easily searchable.

    (Peter, we must speak about commissions.)
    There can be only one.

    Comment


      #3
      Re: Help required for newbie on looping through records

      You just need to do a double loop.

      First, get the activity_ID from the Archived Activities table, then, you have the Activity_id that you need. Once you have the ID, search through the correspondence table lookingfor records that match the activity_id.

      I am assuming that you want to take non-current records out of the tables and move them to archive tables.

      sample would look something like this:

      Code:
      dim actbl as P
      dim ccntact as P
      dim ccnt_arc as P
      acttbl = table.open("activities_arc")
      ccntact = table.open("Client_contact")
      ccnt_arc = table.open ("client_contact_arc")
      ccntact.index_primary_Put("Activity_id")   
           'Assumes there is an Activity ID index
      actbl.fetch_first()
      while .not.cltbl.fetch_eof()
           ccntact.fetch_find(acttbl.act_id)
           while .not.ccntact.fetch_eof()
                ccnt.arc.enter_begin()
                     ******  add each field from client contact to a corresponding 
                     ******  field in client contact _arc
                ccnt_arc.enter_end(.T.)
                ccntact.fetch_next()
           end while
           acttbl.fetch_next()
      end while
      ccnt._arc.close()
      ccntact.close()
      acttbl.close()
      I am not saying that this is completely executable code, but it should give you a reasonable idea.

      Tom

      Comment


        #4
        Re: Help required for newbie on looping through records

        Thanks for your help guys.

        I have been doing some experiments, and am now completely confused.

        I use an xdialog box to allow the user to select the client, whereupon the client_ID is place in a shared variable vClientID - Works fine

        The following code allows moves all records associated with that client from the client_notes table to the client_notes_archive table without any problems.......

        ********************************
        dim tbl as P

        tbl_source = table.open("client_notes")

        result = tbl_source.move_records_to("client_notes_archive","Client_Id = Var->vClientID")

        ui_msg_box("Result", word(result, 1) + " Client Notes moved to Archive. " + word(result, 2) + " Records not moved.")

        tbl_source.close()
        ********************************


        In order to move records associated with the client from the correspondence table to the correspondence_archive table I have to get the Activityid value for each record in the Activities table associated with the customer by checking the Custid value. I then need to move any records with the same Activityid value.

        I have tried to use the following code to do this...........

        *********************************
        dim actbl as P
        dim indx as P
        dim cortbl as P
        dim count as N
        dim vActID as C

        actbl = table.open("activities")
        cortbl = table.open("correspondence")
        query.filter = "Custid = Var->vClientID"
        indx = actbl.query_create()

        actbl.fetch_first()
        while .NOT. actbl.fetch_eof()
        vActID = actbl.Activityid

        result = cortbl.move_records_to("correspondence_archive","Activityid = Var->vActID")

        actbl.fetch_next()
        end while

        indx.close()
        cortbl.close()
        actbl.close()
        *************************

        This gives an error message that a function cannot be used with this data.

        If I remove the line that should move the records, and write the results to the Trace window instead, I get the correct Activityid printed out 92 times (once for each record) exactly as I would expect.

        What am I missing please?
        If computers are so clever how come someone as dumb as me has to tell them what to do?

        Comment


          #5
          Re: Help required for newbie on looping through records

          Try dimming vActid as shared or leave it as is and constructing the filter like so:
          Code:
                  result = cortbl.move_records_to("correspondence_archive",[COLOR=Red]"Activityid = " + quote(vActID)[/COLOR])
          Tim Kiebert
          Eagle Creek Citrus
          A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

          Comment


            #6
            Re: Help required for newbie on looping through records

            We've had issues with variables in filters. I think that that is what is happening.

            Try this:
            Code:
            dim filt as C
            filt = replace_parameters("Activityid = [VarC->vActID]",local_variables())
             
            'then...
            
            result = cortbl.move_records_to("correspondence_archive",filt)
            This SHOULD insure that the variable is replaced in your expression.

            Tom
            Last edited by Tom Henkel; 03-23-2009, 08:34 AM. Reason: enclose code

            Comment


              #7
              Re: Help required for newbie on looping through records

              Ok guys, thanks for your suggestions, but I still can't get this to work.

              I have used trace.writlne(variablename) to try and see what is happening.

              The variables appear to contain the correct info (trace shows what I expect), but the records where the Activityid field matches the variable are not being moved to the archive table.

              I only need to do this once, as I will ad a field for the client ID to the table and force any new entries to write this info into any new records, so if anyone can think of another way to accomplish this one-off task, that would be great.
              If computers are so clever how come someone as dumb as me has to tell them what to do?

              Comment


                #8
                Re: Help required for newbie on looping through records

                Paul, whenever I compare field values to variables I force myself to remember the possibility that each character field in my table probably includes trailing blank spaces. These blank spaces are part of the field value in each record. Are you comparing your variable with untrimmed field values?

                Comment


                  #9
                  Re: Help required for newbie on looping through records

                  Hi Tom,

                  I don't think this is an issue as the fields are both 11 chrs and the ActivityID is an auto-increment field that is always 11 chrs long
                  If computers are so clever how come someone as dumb as me has to tell them what to do?

                  Comment


                    #10
                    Re: Help required for newbie on looping through records

                    Paul, a good way to get specific assistance is to upload a working copy of the database, after sanitizing the data to protect privacy. Maybe it's time for you to do this so we can see where you're stuck. Include a representative sampling of dummy data, and a narrative description of the steps we must follow to find and trigger the fault.

                    Comment


                      #11
                      Re: Help required for newbie on looping through records

                      Thanks Tom.

                      I will look at doing that now (VERY sensitive info, so I have to create dummy data first)
                      If computers are so clever how come someone as dumb as me has to tell them what to do?

                      Comment


                        #12
                        Re: Help required for newbie on looping through records

                        OK, now I'm going to start throwing toys out of the pram..............

                        After I removed the fields that contained sensitive data, and tested again before uploading, everything worked fine.

                        More investigation required, I think
                        If computers are so clever how come someone as dumb as me has to tell them what to do?

                        Comment


                          #13
                          Re: Help required for newbie on looping through records

                          :D As with just about everything in life, there was another solution to the problem......

                          I managed to find another table from the original Access database that contained both ActivityID and CLientID. I created a new field for the Client_ID in both the Donations and Correspondence tables, and created table sets for both with this new table as the child.

                          It was then a simple matter to open the default browse for each table set, select all records, and use the "Update Record" command in the menu to copy the Client_IDs into the parent tables.

                          I can now use the 'Move_Records_to' command to send all client records to the respective archive tables..... and without those horrid nested loops that take SOOOO LOOOONG (over 60,000 records in each table)

                          Rest assured that I shall be ensuring that all future records created by the Alpha5 system automatically insert the Client_ID into the newly created fields.

                          A big thank you to everyone for their suggestions :)
                          If computers are so clever how come someone as dumb as me has to tell them what to do?

                          Comment

                          Working...
                          X