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

Batch update Memo Fields

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

    Batch update Memo Fields

    Is it possible to do add a text string to a memo field for all records that match a query?

    It doesn't appear that it can be done via an operation, but I was hoping it could be done manually some way.

    Thanks,

    #2
    It should be possible.
    Suggest you search on updating memo fields as I recall a member - Robin - helped me with this.
    In the meantime, I will look at some legacy stuff which may have it.
    See our Hybrid Option here;
    https://hybridapps.example-software.com/


    Apologies to anyone I haven't managed to upset yet.
    You are held in a queue and I will get to you soon.

    Comment


      #3
      something along the lines of dbf.memoField = dbf.memoField + crlf() + <new data>
      should work.
      Gregg
      https://paiza.io is a great site to test and share sql code

      Comment


        #4
        Using Action Scripting you can "Add Text to Memo Field", an option in the menu. You can put the text in most places. Try it as a simple button event on a form first, I suggest.
        If you look at the code created by the action script, you will be able to create a script which you can run against a selection of records if you wish.

        The code is a bit long winded but does what it says it will.

        If you need a working example, just post back.

        'Insert text into a memo field: 'Info' in current window.
        Dim TextToInsert as c
        Dim InsertPos as n
        TextToInsert = "whatever your new text is"
        InsertPos = -1

        Dim TempObj as p
        dim readonly_flag as l
        'Get a pointer to the Object on the Form/Browse that has the memo field.
        TempObj = obj(parentform.name(16)+":"+"Info") ' my field name for the test
        'Check if the RTF memo is readonly
        readonly_flag = TempObj.field.readonly
        if readonly_flag = .t. then
        ui_msg_box("Error","Cannot insert text into Memo field '"+"Info"+"' because it is read-only",UI_STOP_SYMBOL)
        end
        else
        Dim MemoText as c
        MemoText = TempObj.text
        If InsertPos = 1 then
        MemoText = TextToInsert + MemoText
        Else if InsertPos = -1 then
        MemoText = MemoText + TextToInsert
        Else
        MemoText = substr(MemoText,1,InsertPos - 1 ) + TextToInsert + substr(MemoText,InsertPos)
        End If

        'Now set the Memo field's text property to the next text..
        TempObj.text = MemoText

        'Now activate the memo
        tempobj.activate()
        '...and set the insertion point in the memo field after the inserted text
        if InsertPos = -1 then 'inserting at end of field
        tempobj.topparent.cursor_set(9999999)
        else
        tempobj.topparent.cursor_set(InsertPos + len(TextToInsert))
        end if
        end if
        See our Hybrid Option here;
        https://hybridapps.example-software.com/


        Apologies to anyone I haven't managed to upset yet.
        You are held in a queue and I will get to you soon.

        Comment


          #5
          Mark, be careful with update operations. They are powerful, fast, and relentless. They can wreck your data faster than greased lightning, and often cannot be reversed. My personal policy when running an update operation for the first time, is to be certain I have two separate good backups, on hand so I can restore if Alpha does what I told it to do, but that turned out to be something different than I intended.

          Comment


            #6
            Yeah! We ALL backup don't we?
            listen to Tom and build it in to the operation as standard.
            See our Hybrid Option here;
            https://hybridapps.example-software.com/


            Apologies to anyone I haven't managed to upset yet.
            You are held in a queue and I will get to you soon.

            Comment


              #7
              So... I was able to get the following to work by putting it in a button on a form.

              Code:
              Dim P as P
              
              vMode = parentform.mode_get()
              
              IF vMode = "CHANGE" .or. vMode = "ENTER"
                  parentform.commit()
              END IF
              
              tbl = table.current()
              p.text=tbl.Notes
              
              addstring = "Text to be inserted into Notes field"
              tbl.change_begin()
              
              If alltrim(tbl.Notes) = ""
                  tbl.Notes = tbl.Notes + date_format(date(),"MM-dd-yy") +": " + addstring
                  ELSE
                  tbl.Notes = tbl.Notes + crlf() + date_format(date(),"MM-dd-yy") +": " + addstring
                  END IF
              
              tbl.change_end(.t.)
              Notes.refresh()
              topparent.commit()​
              Now I am attempting to add this to a function that can then be called to run on a batch of records defined by a query.

              I haven't had any success getting that to work and would appreciate it if someone could point me in the right direction.

              This is where I've gotten so far (but it doesn't work)

              Code:
              FUNCTION Memo_Sweep AS C ( )
              
              tSummons = table.open("Summons")
              query.order = ""
              query.filter = "Done = .t. .and. isblank(\"Notes\")"
              qdx = tsummons.query.create()
              vCount=qdx.records_get()
              msgbox("" + vCount)
              tSummons.fetch_first()
              completed_count=0
              while .not. tSummons.fetch_eof()
              goto next_Summons
              tSummons.change_begin()
              '***********************************************************************
              Dim P as P
              
              vMode = parentform.mode_get()
              
              IF vMode = "CHANGE" .or. vMode = "ENTER"
                  parentform.commit()
              END IF
              
              tbl = table.current()
              p.text=tbl.Notes
              
              addstring = "Text to be inserted into Notes field"
              tbl.change_begin()
              
              If alltrim(tbl.Notes) = ""
                  tbl.Notes = tbl.Notes + date_format(date(),"MM-dd-yy") +": " + addstring
                  ELSE
                  tbl.Notes = tbl.Notes + crlf() + date_format(date(),"MM-dd-yy") +": " + addstring
                  END IF
              
              tbl.change_end(.t.)
              Notes.refresh()
              topparent.commit()
              '***********************************************************************
              tSummons.change_end(.t.)
              completed_count = completed_count + i
              next_summons:
              end while
              tSummons.close()
              END FUNCTION​

              Comment


                #8
                Look this over carefully. I don't have a way to test this but this is the way I'd approach this.

                Code:
                vMode = parentform.mode_get()
                
                IF vMode = "CHANGE" .or. vMode = "ENTER"
                parentform.commit()
                END IF
                
                tSummons = table.open("Summons")
                query.order = ""
                query.filter = "Done = .t. .and. isblank(\"Notes\")"
                qdx = tsummons.query.create()
                
                dim vCount as N = 0
                vCount=qdx.records_get()
                
                response = ui_msg_box("Records Found",vCount + " Records to be Processed",UI_INFORMATION_SYMBOL+UI_OK_CANCEL)
                if response = UI_CANCEL_SELECTED then
                    end
                end if​
                
                vCnt = 0
                If vCount >= 1 then
                addstring = "Text to be inserted into Notes field"
                
                tSummons.fetch_first()
                while .not. tSummons.fetch_eof()
                p.text=tSummons.Notes
                
                tSummons.change_begin()
                
                If alltrim(tSummons.Notes) = ""
                tSummons.Notes = tSummons.Notes + date_format(date(),"MM-dd-yy") +": " + addstring
                ELSE
                tSummons.Notes = tSummons.Notes + crlf() + date_format(date(),"MM-dd-yy") +": " + addstring
                END IF
                
                tSummons.change_end(.t.)
                
                vCnt = vCnt + 1
                tSummons.fetch_next()
                end while
                
                msgbox("Success",vCnt + " Records Processed",UI_INFORMATION_SYMBOL+UI_OK)
                
                end if
                
                end
                Last edited by Ronald Anusiewicz; 08-27-2022, 10:51 AM. Reason: Moved second message box line of code
                Alpha 5 Version 11
                AA Build 2999, Build 4269, Current Build
                DBF's and MySql
                Desktop, Web on the Desktop and WEB

                Ron Anusiewicz

                Comment


                  #9
                  Mark,
                  This code works.


                  Code:
                  vMode = parentform.mode_get()
                  
                  IF vMode = "CHANGE" .or. vMode = "ENTER"
                      parentform.commit()
                  END IF
                  
                  query.order = ""
                  query.filter = "Done = .t. .and. isblank(\"Notes\")"
                  dim tSummons as P
                  tSummons = table.open("summons")
                  qdx = tSummons.query_create()
                  
                  dim vCount as N = 0
                  vCount=qdx.records_get()
                  
                  response = ui_msg_box("Records Found",vCount + " Records to be Processed",UI_INFORMATION_SYMBOL+UI_OK_CANCEL)
                  if response = UI_CANCEL_SELECTED then
                      end
                  end if
                  
                  vCnt = 0
                  If vCount >= 1 then
                      addstring = "Text to be inserted into Notes field"
                  
                      tSummons.fetch_first()
                      while .not. tSummons.fetch_eof()
                          p.text=tSummons.Notes
                  
                          tSummons.change_begin()
                  
                          If alltrim(tSummons.Notes) = ""
                              tSummons.Notes = tSummons.Notes + date_format(date(),"MM-dd-yy") +": " + addstring
                          ELSE
                              tSummons.Notes = tSummons.Notes + crlf() + date_format(date(),"MM-dd-yy") +": " + addstring
                          END IF
                  
                          tSummons.change_end(.t.)
                  
                          vCnt = vCnt + 1
                          tSummons.fetch_next()
                      end while
                  
                      msgbox("Success",vCnt + " Records Processed",UI_INFORMATION_SYMBOL+UI_OK)
                  end if
                  
                  tSummons.close()
                  
                  end​
                  Alpha 5 Version 11
                  AA Build 2999, Build 4269, Current Build
                  DBF's and MySql
                  Desktop, Web on the Desktop and WEB

                  Ron Anusiewicz

                  Comment


                    #10
                    I couldn't get the original to work Ron, so see the attached simple Update Operation.

                    Sample_Data.zip

                    Construct:
                    New Operation
                    ..Update Records
                    ...CREATE(not with the Genie)
                    ....Memo Field
                    ......Expression = Memo Field +"new text"
                    .........Condition if required.

                    It works based on the current selection of records, which was in the brief.
                    This is the code block, but it's easier to use the operation builder!

                    if current_filter <> "" then
                    if eval_valid(current_filter,"memo_field") =.f. then
                    a5_Operation_Warning() 'Display warning if current selection is meaningless
                    current_filter = ".t."
                    end if
                    end if

                    if current_order <> "" then
                    if eval_valid(current_order,"memo_field") = .f. then
                    current_order = ""
                    end if
                    end if

                    a_tbl = table.open("memo_field")
                    ON ERROR GOTO ERROR2708202216401300


                    DIM a5_operation_filter as C
                    a5_operation_filter = current_filter
                    query.filter = a5_operation_filter
                    DIM a5_operation_order as C
                    a5_operation_order = current_order
                    query.order = a5_operation_order
                    query.options = "I"+current_flags
                    query.description = "Temporary Query"
                    a_tbl.query_create("N")

                    update.fields = 1
                    update.field1 = "INFO"
                    update.expr1 = "if(Info<>"",Info+"newstuff",INFO)"

                    'Prompt for confirmation before running the Operation.......
                    dim rec_count as n

                    rec_count = a5_get_records_in_query("memo_field",a5_operation_filter,-1,.f.)
                    message_text = rec_count + " record(s) from 'memo_field' will be updated."+crlf(2)+ "OK to proceed?"
                    operation_result=ui_msg_box("Update Operation",message_text,UI_OK_CANCEL+ UI_FIRST_BUTTON_DEFAULT+ UI_INFORMATION_SYMBOL)
                    If operation_result <> ui_ok_selected then
                    end
                    end if



                    a_tbl.update()


                    GOTO CONTINUE2708202216401300
                    ERROR2708202216401300:
                    ON ERROR GOTO 0
                    ui_msg_box("Error","Error running Update Operation"+crlf()+error_text_get())
                    END
                    CONTINUE2708202216401300:
                    a_tbl.close()
                    'Display a dialog box showing the results of the Operation
                    '(If last parameter is blank, button to show result is not displayed).
                    dim args as sql::arguments
                    if eval_valid("arguments") then
                    if typeof(arguments) = "P" then
                    args = arguments
                    end if
                    end if
                    a5_update_op_result(a_records_processed, a_records_violated,"memo_field",a5_operation_filter,args)

                    'If the Operation is run from within a Form or Browse, then refresh the window
                    if is_object(topparent.this) then
                    if topparent.Class() = "form" .or. topparent.class() = "browse" then
                    topparent.Refresh_layout()
                    end if
                    end if
                    See our Hybrid Option here;
                    https://hybridapps.example-software.com/


                    Apologies to anyone I haven't managed to upset yet.
                    You are held in a queue and I will get to you soon.

                    Comment


                      #11
                      Both Ron and Ted's recommendations work great.

                      Thanks for the help!

                      Comment


                        #12
                        Glad it worked out Mark. I once read, some time ago, by a man who has wisely guided me through the years on these boards, I actually believe it might have been Tom Cone, that it can be a slippery slope mixing together both form methods and table methods in combinations within the same script sequence. I found this wise and I've held true to that wisdom and adverted from mixing form methods together with table methods. As well as using operations in a batch method, as he reiterated in this thread.
                        Mike W
                        __________________________
                        "I rebel in at least small things to express to the world that I have not completely surrendered"

                        Comment

                        Working...
                        X