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

button: append once update second time

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

    button: append once update second time

    I found this code in a post made by JerryBrightbill:

    rec_num = recno() 'get record number of current record

    tbl1 = table.open("sourcetable") 'open a new instance of the same table
    tbl1.fetch_goto(rec_num) ' find the current record in the new instance of the table

    tbl2 = table.open("destinationtable")
    tbl2.enter_begin()
    tbl2.destination_field1 = tbl1.source_field1
    tbl2.destination_field2 = tbl1.source_field2
    ' and so on until you have filled all of the fields in the destination with values from the current record

    tbl2.enter_end(.T.)
    tbl1.close()
    tbl2.close()


    I use this code to copy two fields to the invoice table outside of the set. The invoice table contains a third field for the invoice number with auto increment turned on. The code is activated with a button (onpush event) on a form (the source). Everything works fine but when the button is pressed twice it also produces two invoices. I'm looking for some code to prevent this. When the button is pressed the second time it should perform an update instead. Is there an easy way to do this?

    #2
    Re: button: append once update second time

    When the button is pressed the second time it should perform an update instead.
    What does this mean? To performs some sort of update you would have to find a previously entered record and change it.

    As posted the code uses .enter_begin() and .enter_end(). You would have to add something to find the desired previously entered record and use .change_begin() and .change_end().
    There can be only one.

    Comment


      #3
      Re: button: append once update second time

      Maybe we can first focus on the part of my question you do understand. Is there some code that could prevent making double invoices for the same record?

      Comment


        #4
        Re: button: append once update second time

        Try something like this
        Code:
        rec_num = recno() 'get record number of current record
        
        tbl1 = table.open("sourcetable") 'open a new instance of the same table
        tbl1.fetch_goto(rec_num) ' find the current record in the new instance of the table
        vCurrInv = tbl1.InvoiceNumber    'use you actual invoicenumber field here
        
        tbl2 = table.open("destinationtable")
        tbl2.order("InvoiceNumber")  'Order the table because fetch_find in the next line needs to
                                     'have the table ordered on the field in which it is looking
                                     'Substite your actual invoicenumber field here for table two.
        
        If tbl2.fetch_find(vCurrInv) > 0 then                 'If current invoice is found in table 2 then the record
            tbl2.change_begin()                               'number is returned which is greater than 0 so table 2
            tbl2.destination_field1 = tbl1.source_field1      'is put in change mode.
            tbl2.destination_field2 = tbl1.source_field2
            tbl2.change_end() 
        Else                                                  'If invoice number is not found then the record number
            tbl2.enter_begin()                                'with the nearest match is returned but as a negative value
            tbl2.destination_field1 = tbl1.source_field1      'so it will be less than 0 which cause the table to be put
            tbl2.destination_field2 = tbl1.source_field2      'into enter mode.
            ' and so on until you have filled all of the fields 
            'in the destination with values from the current record
            tbl2.enter_end(.T.)
        end if
        
        tbl1.close()
        tbl2.close()
        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


          #5
          Re: button: append once update second time

          You could add a logical field to your source table. When you push the button you would have to add code to check if the field is blank then you proceed with the code copying the records from table1 to table2. If the logical field is set to true you do nothing (or give a message that the copying has already taken place. Then at the end of the code for copying you would set the field in the source table to true meaning that the records has already been copied once. That way if you push the button the second time the field would have been set to true and the copying would not proceed.

          Hope I made that clear enough. I'm sure you will hear other ways of doing this.

          FWIW

          Tom Baker

          Edit: I see that Tim Kiebert has already posted a solution.

          Comment


            #6
            Re: button: append once update second time

            Edit

            Comment


              #7
              Re: button: append once update second time

              You've been given two options which approach the same question in different manners. I imagine these two answers are based on the same question I had about what you wanted.

              Tom's approach is to prevent two invoices based on the same source record (composite set record) based on a flag being set. This would mean that the source invoice could not be edited and re-invoiced.

              Tim's approach assumes you might want to edit the source invoice and update the re-copy it to the invoice storage table.

              So the question of deciding which option to use depends on what you really wanted originally. Do you want to prevent the second press of the button from creating an invoice or do you want to allow the user the chance to edit an invoice and change the record in the invoice storage table.

              I say this not to pick apart your question in any petty way. We just needed to know more details in order to get you what you want. If my previous post was taken as derogatory, I apologize. I do tend to be brief.
              There can be only one.

              Comment


                #8
                Re: button: append once update second time

                Thanks Tim and Tom,

                I would like to start with Tim�s solution. I probably did something wrong because I�m still able to produce double invoices. I attached a small example to test the code. Maybe you can tell me what I did wrong?

                Comment


                  #9
                  Re: button: append once update second time

                  Thanks Stan,

                  I�ll have to read everything slowly so I understand what has bin said. I�ll get back to you.

                  Comment


                    #10
                    Re: button: append once update second time

                    Hi Stan,

                    When I edit the source table I would like to update / re-copy it to the invoice storage table. So Tim�s solution would cover it all.

                    Comment


                      #11
                      Re: button: append once update second time

                      Werder

                      You need to change the I_nr field to 'User entered' from 'Auto increment' in field rules and add the following line in the 'enter' section of the code.

                      tbl2.I_nr = vCurrInv

                      or

                      tbl2.I_nr = tbl1.S_nr
                      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


                        #12
                        Re: button: append once update second time

                        This is really great and it now work's perfect! Tim thanks for the code. I only added �topparent.commit()� to the script because otherwise the update function would not work. At least not while being on the form in the changed record itself. The attachment contains the final result for people who are looking for the same solution.

                        Comment


                          #13
                          Re: button: append once update second time

                          I sometime receive the error message "record number is past end of table". The message appears after pressing the button on the form. Does anybody know what this messages means?

                          Comment

                          Working...
                          X