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

Updating multiple records from script

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

  • Updating multiple records from script

    Sorry about asking a dumb question (again!!!), but I have been struggling with this for hours without success.

    I have a dialog box where the end user selects a current value from a table, with another input field to enter a replacement value. When the user clicks the OK button I want all records with the value in the dropdown to be changed to the value in the input field.

    For example:

    Table1 has a field called "Name"
    The user selects "Bill" in the dropdown and types "William" in the input box.
    When the user clicks OK all instances of "Bill" in the "Name" field of all records are changed to "William"
    The table has about 70k records
    If computers are so clever how come someone as dumb as me has to tell them what to do?

  • #2
    Re: Updating multiple records from script

    If your dropdown was bound to a variable which is populated from your table, and your input field is also a variable then you have the scenario you need for an update operation. If you can create an Update operation using variables in the filter, you can run that update in your form by first passing your layout variables to global variables which the Update uses.
    Robin

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

    Comment


    • #3
      Re: Updating multiple records from script

      Originally posted by MoGrace View Post
      If your dropdown was bound to a variable which is populated from your table, and your input field is also a variable then you have the scenario you need for an update operation. If you can create an Update operation using variables in the filter, you can run that update in your form by first passing your layout variables to global variables which the Update uses.
      Thanks Mo. I understand this, but I am having trouble with the actual process of updating the records.

      I have used the while .NOT. tbl.fetch_eof() to loop through the records, but cannot make the If() statement work so that only those records that match the variable are updated.
      If computers are so clever how come someone as dumb as me has to tell them what to do?

      Comment


      • #4
        Re: Updating multiple records from script

        We seem to be talking about two different things. If you are wanting to do this in an XBasic script while the current table is open, then it seems you would have to filter the records first which the OnChange event of the dropdown can achieve. Then your script can fetch thru the current records in that query without an IF() statement, to do its change_begin() routine. A look at your script would be nice. ;)
        Robin

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

        Comment


        • #5
          Re: Updating multiple records from script

          try this:


          Code:
          dim vtable_value as C="Bill"              
          dim vnew_value as C
          
          dim vresult as C
          vresult=ui_dlg_box("Update",<<%dlg%
          {font=arial,10}{lf};
          Table Value:|[.20vtable_value];
          New Value:|{initial_focus}[.20vnew_value];
          <10OK> <10Cancel>
          %dlg%)
          
          if vresult="Cancel"
          	end 
          end if
          
          ' dim vatriables 
          	dim cycle as N=0
          	dim vrecs as N
          	dim vfilter as C
          
          ' filter for the table
          	vfilter="[COLOR="Red"]your_field_name[/COLOR]="+quote(vtable_value)
          
          'count records in table matching filter for wait dialog
          	vrecs = TABLECOUNT("[COLOR="red"]YOURTABLENAME[/COLOR]",vfilter)
          	cycle = 1
          	DIM GLOBAL pDlg1 as {waitdialog}
          		pDlg1.Set_Title("Please Wait")
          		pDlg1.Create(1,"Percent")
          		pDlg1.Set_Message("")
          		pDlg1.Set_Bottom_Message("")
          		pDlg1.Set_Percent(Var->cycle,Var->vrecs)
          
          	'open table filtered and loop through changing records
          	dim t as P
          	t=table.open("[COLOR="red"]yourtablename[/COLOR]")
          	xi=t.order("",vfilter)
          	t.fetch_first()
          	while .not. t.fetch_eof()
          		t.change_begin()
          			t.[COLOR="Red"]your_field_name[/COLOR]="+=wut(lt(alltrim(vnew_name)))
          		t.change_end(.t.)
          		
          		cycle=cycle+1
          		pDlg1.Set_Percent(Var->cycle,Var->vrecs)
          	t.fetch_next()
          	end while
          	t.close()
          	pDlg1.close()
          Last edited by Mike Wilson; 06-22-2010, 01:01 PM.
          Mike W
          __________________________
          "I rebel in at least small things to express to the world that I have not completely surrendered"

          Comment


          • #6
            Re: Updating multiple records from script

            The table is not open in a browse or form. The routine will run from a button on toolbar.

            The information is very sensitive, so I will create a dummy database to upload.

            Just discovered Mike's reply as I was posting....... will give that a go first.
            Last edited by Sooty57; 06-22-2010, 12:56 PM. Reason: Reply while posting
            If computers are so clever how come someone as dumb as me has to tell them what to do?

            Comment


            • #7
              Re: Updating multiple records from script

              One small change for clarity:

              Code:
              .........
              
              t.change_begin()
                   t.[COLOR="Red"]your_field_name[/COLOR]="+=wut(lt(alltrim(vnew_name)))
              t.change_end(.t.)
              
              .......
              Mike W
              __________________________
              "I rebel in at least small things to express to the world that I have not completely surrendered"

              Comment


              • #8
                Re: Updating multiple records from script

                Originally posted by Mike Wilson View Post
                One small change for clarity:

                Code:
                .........
                
                     t.[COLOR="Red"]your_field_name[/COLOR]="+=wut(lt(alltrim(vnew_name)))
                
                .......
                This line gives script error (expected value) when testing syntax
                If computers are so clever how come someone as dumb as me has to tell them what to do?

                Comment


                • #9
                  Re: Updating multiple records from script

                  The dimmed variable was vnew_value. But I don't understand the purpose in combining WUT() with LT() and ALLTRIM() since that is what this function is supposed to do. I changed it to UT(vnew_value) and that worked.

                  t.Lastname=ut(vnew_value) 'which was the name of the field I made.

                  Mike - that was a nice example for a wait dialog - thanks!
                  Last edited by MoGrace; 06-22-2010, 01:38 PM.
                  Robin

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

                  Comment


                  • #10
                    Re: Updating multiple records from script

                    Modified as per Mo's suggestion and all worked fine.

                    Just a quickie though..... Why is the new name in the field all uppercase?


                    OOps - scrub that question ........ UT()
                    Last edited by Sooty57; 06-22-2010, 01:47 PM. Reason: found answer
                    If computers are so clever how come someone as dumb as me has to tell them what to do?

                    Comment


                    • #11
                      Re: Updating multiple records from script

                      The mistake was a cut and paste error. I like to use wut(lt(value)) so that ONLY the first letter is capped. If you type in aBCde, the result of WUT() will be ABCde. So I like to make all lower case first and then cap the first letter only for uniformity.

                      Glas it worked out.
                      Mike W
                      __________________________
                      "I rebel in at least small things to express to the world that I have not completely surrendered"

                      Comment


                      • #12
                        Re: Updating multiple records from script

                        Interesting that the bubble help in the code editor for the WUT() function does not say that! At least not in v8. It does however say that in the CHM file.
                        Robin

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

                        Comment


                        • #13
                          Re: Updating multiple records from script

                          What changes would I need to make to have this work on a numeric value field. I tried changing the code but kept getting mismatch errors. Alpha 5 V 10.5

                          I need to change one field in a table from every instance of .30 and change it to 30. The table has 1700 records in it so I really do not want to do this manually if possible. I already looked into the operations search and replace but that only works for character fields.

                          Thanks.

                          Comment


                          • #14
                            Re: Updating multiple records from script

                            Preston.
                            Backup the Table
                            Update Records Operation - Numeric - assign a specified value
                            Update Records selected by a Filter Expression. In your case it would be .30.

                            Make sure that the filed is big enoough to take 30.00 so it needs to be N5 at least
                            See our Hybrid Option here;
                            https://hybridapps.example-software.com/


                            There are 3 things you can do in any situation;
                            Live with it, Change it or Walk away from it.

                            Comment


                            • #15
                              Re: Updating multiple records from script

                              Originally posted by Ted Giles View Post
                              Preston.
                              Backup the Table
                              Update Records Operation - Numeric - assign a specified value
                              Update Records selected by a Filter Expression. In your case it would be .30.

                              Make sure that the filed is big enoough to take 30.00 so it needs to be N5 at least
                              Thanks a bunch.

                              I looked right past that before and did not even see it.

                              I think that will give me what I need to add a update button in my app so the end users can change the value in all the records if needed. The field is a 5/2 and is used for a base percentage markup on items in a product catalog.

                              I tell you, with the help of the generous people here, the wiki and the books, I am starting to understand Alpha 5 a lot better.

                              Again, thank you.

                              Comment

                              Working...
                              X