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

Automatically creating linked records in two tables?

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

    Automatically creating linked records in two tables?

    My client is currently using an access database (10 years old), so I am stuck with the table structure used there to a great extent.

    In order to keep track of correspondence they first create an Activity (in Activities table). If they then send a letter an entry is made in the Correspondence table that is linked to the record in the Activities table. Obviously this is a very time-consuming process - If they send out a mailshot to 200 people, they have to manually input 400 records.

    I have created a table that stores addresses etc so that the client can create a mailing list. Using this, I can create the records for the Activity and Correspondence tables.

    My problem is how to link the two. i.e.: Each record in the Correspondence table MUST be linked to a record in the Activities table by means of the unique ActivityID field. If I use a script to create the Activity record (ActivityID field is AutoInc) how can I then place this auto-generated ActivityID into the corresponding Correspondence record?

    Because this needs to create multiple records in both tables I am assuming that I need to use some for of do-loop routine i.e. create the Activity record, read the ActivityID field, create the Correspondence record with ActivityID field, move on to next.

    Any help would be really appreciated on this one - it's driving me nuts.
    If computers are so clever how come someone as dumb as me has to tell them what to do?

    #2
    Re: Automatically creating linked records in two tables?

    Paul,

    This is straightforward to do in xbasic, and your script description is good. This fleshes the outline a little more. I assume there is a person table.

    Code:
    tPerson = <open person table>
    tActivity = <open activity table>
    tCorresp = <open correspondence table>
    <query tPerson for the contacts for this activity>
    tPerson.fetch_first()
    
    while .not. tPerson.fetch_eof()
      tActivity.enter_begin()
      ... <activity id is automatically set by field rule>
      tActivity.enter_end(.t.)
    
      tCorresp.enter_begin()
      tCorresp.activity_id = tActivity.activity_id
      ...
      tCorresp.enter_end(.t.)
    
      tPerson.fetch_next()
    end while
    Bill.

    Comment


      #3
      Re: Automatically creating linked records in two tables?

      Thanks for the tips Bill. I will start to play with this.

      My problem is mainly lack of knowledge of the functions available and their syntax.

      You have hopefully pointed me in the right direction.
      If computers are so clever how come someone as dumb as me has to tell them what to do?

      Comment


        #4
        Re: Automatically creating linked records in two tables?

        Once again, my lack of knowledge of xbasic has become glaringly obvious. Despite many hours of experimentation I am no closer to a solution.

        I have attached a much simplified version of the database in the hope that someone may be able to add some code to the button.

        The form is for a set. Browsing the mailing lists (mailing list table) shows the recipients (mailshot table). What I need the code to do when the button is clicked is to create two records for each recipient - first an activity record with the data from the mailshot record, and then a correspondence record with the auto-generated ActivityID from that record.

        I realise I am asking a lot, but I am sure that once I have an example to work from I will be able to crack it.

        Thanking some kind soul in advance.
        If computers are so clever how come someone as dumb as me has to tell them what to do?

        Comment


          #5
          Re: Automatically creating linked records in two tables?

          When the record is created in the correspondence table, what should go in the corrid and type fields?

          My attachment creates the suggested records, I think to your specifications. Currently the corrid and type fields are filled with hard coded values.
          Last edited by Stan Mathews; 12-01-2009, 03:17 PM.
          There can be only one.

          Comment


            #6
            Re: Automatically creating linked records in two tables?

            Thanks for the quick response again Stan.

            I'm afraid I didn't make things as clear as I should have. I need to create the two records for each of the records in browse1 (recipients), not just the selected one.

            Don't worry about the fields in the correspondence table - this info is taken from fields I forgot to include in the example, but your code has given me a good pointer to the method I need to employ to do this.
            If computers are so clever how come someone as dumb as me has to tell them what to do?

            Comment


              #7
              Re: Automatically creating linked records in two tables?

              Code:
              tbl = table.current(2)
              tbl.fetch_first()
              WHILE .not. tbl.fetch_eof()
              	tbl_dest = table.open("activities",FILE_RW_EXCLUSIVE)
              	tbl_dest.enter_begin(.T.)
              	tbl_dest.Funderid = tbl.funderid
              	tbl_dest.Contact = tbl.contact
              	tbl_dest.Address1 = tbl.address1
              	tbl_dest.Address = tbl.address2
              	tbl_dest.Town = tbl.town
              	tbl_dest.Postcode = tbl.postcode
              	tbl_dest.enter_end(.t.)
              	act_id = tbl_dest.activityid
              	tbl_dest.close()
              	
              	tbl_dest2 = table.open("correspondence",FILE_RW_EXCLUSIVE)
              	tbl_dest2.enter_begin(.T.)
              	tbl_dest2.Activityid = act_id
              	tbl_dest2.corrid = "ABC"
              	tbl_dest2.TYPE = "DEV"
              	tbl_dest2.enter_end(.T.)
              	tbl_dest2.close()
              	tbl.fetch_next()
              END WHILE
              There can be only one.

              Comment


                #8
                Re: Automatically creating linked records in two tables?

                Thanks Stan, that's absolutely fantastic.

                I thought that I needed to create a query to filter the records in the mailshot table; I didn't realise that tbl.fetch_eof() would only use the records in the embedded browse.

                Just a quickie.... What is the "2" for in table.current(2), does it tell Alpha that 2 tables are open?
                If computers are so clever how come someone as dumb as me has to tell them what to do?

                Comment


                  #9
                  Re: Automatically creating linked records in two tables?

                  I didn't realise that tbl.fetch_eof() would only use the records in the embedded browse.
                  Effectively, yes. Practically, it uses the records linked to the current parent.

                  What is the "2" for in table.current(2)
                  table.current() or table.current(1) is the parent of a set. The other tables are referenced by their vertical position in the set structure.
                  There can be only one.

                  Comment


                    #10
                    Re: Automatically creating linked records in two tables?

                    Thanks Stan.

                    I'll get the hang of this xbasic lark one day ;-)
                    If computers are so clever how come someone as dumb as me has to tell them what to do?

                    Comment


                      #11
                      Re: Automatically creating linked records in two tables?

                      Looking at Bill's recommendation, which I should have studied before I posted, the code can be improved thusly.

                      Code:
                      tbl_dest = table.open("activities",FILE_RW_EXCLUSIVE)
                      tbl_dest2 = table.open("correspondence",FILE_RW_EXCLUSIVE)
                      tbl = table.current(2)
                      tbl.fetch_first()
                      WHILE .not. tbl.fetch_eof()
                      	tbl_dest.enter_begin(.T.)
                      	tbl_dest.Funderid = tbl.funderid
                      	tbl_dest.Contact = tbl.contact
                      	tbl_dest.Address1 = tbl.address1
                      	tbl_dest.Address = tbl.address2
                      	tbl_dest.Town = tbl.town
                      	tbl_dest.Postcode = tbl.postcode
                      	tbl_dest.enter_end(.t.)
                      	act_id = tbl_dest.activityid
                      	
                      	tbl_dest2.enter_begin(.T.)
                      	tbl_dest2.Activityid = act_id
                      	tbl_dest2.corrid = "ABC"
                      	tbl_dest2.TYPE = "DEV"
                      	tbl_dest2.enter_end(.T.)
                      	tbl.fetch_next()
                      END WHILE
                      tbl_dest.close()
                      tbl_dest2.close()
                      I tend to knock things together without regard for best practices and hope to imporve them later.
                      There can be only one.

                      Comment

                      Working...
                      X