Alpha Video Training
Results 1 to 18 of 18

Thread: Alternative method to enter/edit Memo field

  1. #1
    Member
    Real Name
    Mark Williams
    Join Date
    Dec 2005
    Posts
    313

    Default Alternative method to enter/edit Memo field

    Due to having history of corrupt memo fields in our tables, I am attempting to utilize an alternative method of entering and editing memo fields. My idea is to reduce the time the record is in enter or edit mode as much as possible. Our users use these notes fields extensively and may spend 10 minutes at a time entering and editing notes. My thought is to make the memo field on the form read only and then have the user enter/edit the notes via an xdialog box and then transferred to the memo field when the user presses ok, thus putting the record in edit mode only when the user presses ok, instead of all the while they are entering the notes.

    I've attached a sample that allows the user to enter the notes via an xdialog but am not sure how to go about creating a button to edit the contents of the memo field by copying the current contents into an xdialog box, making the necessary changes, then replacing what was in the memo field with the contents of the edited text in the xdialog.

    Sample_Notes.zip

    Appreciate any suggestions.

    Also, I welcome any criticism or advice with my logic.

    Thanks!

  2. #2
    Member
    Real Name
    Marco Gallardo
    Join Date
    Sep 2016
    Posts
    33

    Default Re: Alternative method to enter/edit Memo field

    I'm contemplating reworking some of our note fields as well as we just had some pretty scary corruption occur.

    For you Edit button would something as simple as this work? Just reuse your xdlg code but get the note contents just before.


    Code:
    DIM tbl as P
    DIM SHARED NotesVar as C
    tbl = table.current()
    NotesVar = tbl.NOTES
    
    
    
    DIM SHARED DialBox as C
    ok_button_label = "&OK"
    cancel_button_label = "&Cancel"
    DialBox = ui_dlg_box("Enter Internal Notes",<<%dlg%
    {region}
    Notes:| [%mw%.60,8NotesVar];
    {endregion};
    {line=1,0};
    {region}
    <*15=ok_button_label!OK> <15=cancel_button_label!CANCEL>
    {endregion};
    %dlg%)
    
    If Dialbox = "Cancel"
    	var->NotesVar=""
    	end
    End If
    
    If Var->NotesVar=""
    	end 
    	ELSE
    
    Dim P as P
    DIM SHARED Test AS C
    
    vMode = parentform.mode_get()
    
    IF vMode = "CHANGE" .or. vMode = "ENTER"
    	parentform.commit()
    END IF
    
    tbl = table.current() 
    p.text=tbl.Notes
    
    tbl.change_begin()
    
    'Save the note
    tbl.Notes = var->NotesVar
    
    
    tbl.change_end(.t.)
    Notes.refresh()
    topparent.commit()
    
    'maybe add a catch here to make sure the commit went through
    
    NotesVar = ""
    END IF
    You could probably also add the code to commit the changes within the xdlg itself. If you add Error handling to verify the commit went through it might be a good idea. You could present an option to retry. It might also give the user a chance to copy their work to word/notepad if they fear it won't save properly.
    Last edited by mgallardo; 03-19-2019 at 11:14 AM. Reason: Bolding changes / wraping in code tag

  3. #3
    "Certified" Alphaholic Ronald Anusiewicz's Avatar
    Real Name
    Ronald Anusiewicz
    Join Date
    Oct 2000
    Location
    Southampton, MA
    Posts
    1,547

    Default Re: Alternative method to enter/edit Memo field

    I've had excellent results using this code with memo fields.
    This script is attached to a button on the form and the memo field is read only.

    The nice thing about this script, the memo field is only open long enough to save the change or the enter.
    This script handles both entering a new memo or editing an existing memo.

    In this example, this memo is in a grandchild table.

    Ron

    Code:
    parentform.Commit()
    tparent = table.current(1)
    tgchild = table.current(2)
    vtransno = tgchild.TRANSNO
    vSwkno = tgchild.SWKNO
    
    dim shared t as p
    t = table.get("WOfix")
    p.text=t.action
    
    IF t.action = "" .and. t.swkno = "" THEN
    	IF a5_memo_editor(p,"Edit the Corrective Action Field") = "Save" THEN
    		vSwkRec = tgchild.recno()
    		t = table.open("WOfix")
    		t.enter_begin()
    		t.TRANSNO = vtransno
    		t.SWKNO = vswkno
    		t.action = p.text
    		t.enter_end()
    		t.close()
    		END
    	ELSE
    		cancel()
    		end
    	END IF
    ELSE
    	IF a5_memo_editor(p,"Edit the Corrective Action Field") = "Save" THEN
    		vRec = t.recno()
    		t = table.open("WOfix")
    		t.fetch_goto(vRec)
    		t.change_begin()
    		t.action = p.text
    		t.change_end()
    		t.close()
    	ELSE
    		cancel()
    		end
    	END IF
    END IF
    
    parentform.Resynch()
    
    END
    Alpha Anywhere v3.5
    Version 12.3, Build 2999
    MySql56 & DBF's

    Alpha 4, 5, Anywhere

    Ron Anusiewicz

  4. #4
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,245

    Default Re: Alternative method to enter/edit Memo field

    I can't swear my thinking is correct, but I think the fpt errors are usually caused by disk activity.
    For myself, I've abandoned the dbf memo field in favor of large varchar sql columns as they seem
    to be far more reliable, and you can easily connect them to the record involved.

  5. #5
    Member
    Real Name
    Mark Williams
    Join Date
    Dec 2005
    Posts
    313

    Default Re: Alternative method to enter/edit Memo field

    Quote Originally Posted by mgallardo View Post
    I'm contemplating reworking some of our note fields as well as we just had some pretty scary corruption occur.

    For you Edit button would something as simple as this work? Just reuse your xdlg code but get the note contents just before.


    Code:
    DIM tbl as P
    DIM SHARED NotesVar as C
    tbl = table.current()
    NotesVar = tbl.NOTES
    
    
    
    DIM SHARED DialBox as C
    ok_button_label = "&OK"
    cancel_button_label = "&Cancel"
    DialBox = ui_dlg_box("Enter Internal Notes",<<%dlg%
    {region}
    Notes:| [%mw%.60,8NotesVar];
    {endregion};
    {line=1,0};
    {region}
    <*15=ok_button_label!OK> <15=cancel_button_label!CANCEL>
    {endregion};
    %dlg%)
    
    If Dialbox = "Cancel"
    	var->NotesVar=""
    	end
    End If
    
    If Var->NotesVar=""
    	end 
    	ELSE
    
    Dim P as P
    DIM SHARED Test AS C
    
    vMode = parentform.mode_get()
    
    IF vMode = "CHANGE" .or. vMode = "ENTER"
    	parentform.commit()
    END IF
    
    tbl = table.current() 
    p.text=tbl.Notes
    
    tbl.change_begin()
    
    'Save the note
    tbl.Notes = var->NotesVar
    
    
    tbl.change_end(.t.)
    Notes.refresh()
    topparent.commit()
    
    'maybe add a catch here to make sure the commit went through
    
    NotesVar = ""
    END IF
    You could probably also add the code to commit the changes within the xdlg itself. If you add Error handling to verify the commit went through it might be a good idea. You could present an option to retry. It might also give the user a chance to copy their work to word/notepad if they fear it won't save properly.
    Marco,

    This appears to work fine. Is there a way to not have the current contents of the memo field selected and place the cursor at the end of the existing text when the dialog box is opened?

    Thanks for the help!

  6. #6
    Member
    Real Name
    Marco Gallardo
    Join Date
    Sep 2016
    Posts
    33

    Default Re: Alternative method to enter/edit Memo field

    Quote Originally Posted by Mark Williams View Post
    Is there a way to not have the current contents of the memo field selected and place the cursor at the end of the existing text when the dialog box is opened?
    Don't think I've done that one before but I'll give it a go:
    Code:
    DIM tbl as P
    DIM NotesVar as C
    DIM ptrNotesVar as P
    DIM ptrNotesVar.Object as P
    DIM ptrNotesVar.text as C
    tbl = table.current()
    'NotesVar = tbl.NOTES
    ptrNotesVar.text = tbl.NOTES
    
    
    DIM SHARED DialBox as C
    ok_button_label = "&OK"
    cancel_button_label = "&Cancel"
    
    dlgTitle = "Enter Internal Notes"
    DialBox = ui_dlg_box(dlgTitle,<<%dlg%
    {startup=loadingXdlg}
    {region}
    Notes:| [%mw%.60,8ptrNotesVar];
    {endregion};
    {line=1,0};
    {region}
    <*15=ok_button_label!OK> <15=cancel_button_label!CANCEL>
    {endregion};
    %dlg%,<<%code%
    if a_dlg_button = "loadingXdlg" then
    	a_dlg_button = ""
    	ui_dlg_ctl_goto(dlgTitle,"ptrNotesVar")
    	ptrNotesVar.Object.set_cursor(len(ptrNotesVar.text)+1)
    end if
    %code%)
    
    If Dialbox = "Cancel"
    	ptrNotesVar.text = ""
    	end
    End If
    
    If ptrNotesVar.text = ""
    	end 
    ELSE
    	Dim P as P
    	DIM SHARED Test AS C
    	
    	vMode = parentform.mode_get()
    	
    	IF vMode = "CHANGE" .or. vMode = "ENTER"
    		parentform.commit()
    	END IF
    	
    	tbl = table.current() 
    	p.text= tbl.Notes
    	
    	tbl.change_begin()
    	
    	'Save the note
    	tbl.Notes = ptrNotesVar.text
    		
    	tbl.change_end(.t.)
    	Notes.refresh()
    	topparent.commit()
    	
    	'maybe add a catch here to make sure the commit went through
    	
    	ptrNotesVar.text = ""
    END IF
    I used an xdialog startup event to set the cursor and had to change the xdialog field to a pointer as per the documentation

    https://documentation.alphasoftware...._.SET_CURSOR()

  7. #7
    Member
    Real Name
    Mark Williams
    Join Date
    Dec 2005
    Posts
    313

    Default Re: Alternative method to enter/edit Memo field

    Quote Originally Posted by mgallardo View Post
    Don't think I've done that one before but I'll give it a go:
    Code:
    DIM tbl as P
    DIM NotesVar as C
    DIM ptrNotesVar as P
    DIM ptrNotesVar.Object as P
    DIM ptrNotesVar.text as C
    tbl = table.current()
    'NotesVar = tbl.NOTES
    ptrNotesVar.text = tbl.NOTES
    
    
    DIM SHARED DialBox as C
    ok_button_label = "&OK"
    cancel_button_label = "&Cancel"
    
    dlgTitle = "Enter Internal Notes"
    DialBox = ui_dlg_box(dlgTitle,<<%dlg%
    {startup=loadingXdlg}
    {region}
    Notes:| [%mw%.60,8ptrNotesVar];
    {endregion};
    {line=1,0};
    {region}
    <*15=ok_button_label!OK> <15=cancel_button_label!CANCEL>
    {endregion};
    %dlg%,<<%code%
    if a_dlg_button = "loadingXdlg" then
    	a_dlg_button = ""
    	ui_dlg_ctl_goto(dlgTitle,"ptrNotesVar")
    	ptrNotesVar.Object.set_cursor(len(ptrNotesVar.text)+1)
    end if
    %code%)
    
    If Dialbox = "Cancel"
    	ptrNotesVar.text = ""
    	end
    End If
    
    If ptrNotesVar.text = ""
    	end 
    ELSE
    	Dim P as P
    	DIM SHARED Test AS C
    	
    	vMode = parentform.mode_get()
    	
    	IF vMode = "CHANGE" .or. vMode = "ENTER"
    		parentform.commit()
    	END IF
    	
    	tbl = table.current() 
    	p.text= tbl.Notes
    	
    	tbl.change_begin()
    	
    	'Save the note
    	tbl.Notes = ptrNotesVar.text
    		
    	tbl.change_end(.t.)
    	Notes.refresh()
    	topparent.commit()
    	
    	'maybe add a catch here to make sure the commit went through
    	
    	ptrNotesVar.text = ""
    END IF
    I used an xdialog startup event to set the cursor and had to change the xdialog field to a pointer as per the documentation

    https://documentation.alphasoftware...._.SET_CURSOR()
    Nicely done, Marco!

    One last question (I hope)...

    If there is existing text in the memo field and I delete it all, it should delete all the existing text. Instead, it ends the script. Any suggestions on a fix for that?

    Thanks again!

  8. #8
    Member
    Real Name
    Marco Gallardo
    Join Date
    Sep 2016
    Posts
    33

    Default Re: Alternative method to enter/edit Memo field

    Sure.


    Just remove or comment out this If Block from you code

    Code:
    If ptrNotesVar.text = ""
    	end 
    ELSE
    
    <Keep the code between the Else and End if>
    
    END IF

  9. #9
    Member
    Real Name
    Mark Williams
    Join Date
    Dec 2005
    Posts
    313

    Default Re: Alternative method to enter/edit Memo field

    Quote Originally Posted by mgallardo View Post
    Sure.


    Just remove or comment out this If Block from you code

    Code:
    If ptrNotesVar.text = ""
    	end 
    ELSE
    
    <Keep the code between the Else and End if>
    
    END IF
    Works perfectly - thanks again - it's really appreciated!

  10. #10
    VAR
    Real Name
    Bill Parker
    Join Date
    Apr 2000
    Location
    Dallas, TX
    Posts
    1,696

    Default Re: Alternative method to enter/edit Memo field

    Gregg,
    Are you saying you switched to sql from dbf, or that you are pairing a sql table to handle the notes with your existing dbf table. If the latter, please give more details.

    Bill.

  11. #11
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,245

    Default Re: Alternative method to enter/edit Memo field

    My intent was to switch, but the desktop form has so many conditional controls that I
    paired them up.

    I use the recno() from dbf to match the exact record, as empID to match up with the employee (this gives me more options).
    I also take advantage of using grid and dialog components to display/receive data entry.

  12. #12
    VAR
    Real Name
    Bill Parker
    Join Date
    Apr 2000
    Location
    Dallas, TX
    Posts
    1,696

    Default Re: Alternative method to enter/edit Memo field

    So using a desktop form with an embedded web component to show the memo? Is this done via OnFetch event to retrieve the memo for each dbf record displayed? Or are you putting an active link table in a set with a dbf table?

  13. #13
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,245

    Default Re: Alternative method to enter/edit Memo field

    I actually have them click a button, but of the options you provided, I would use the onFetch event as my
    experience with active link tables was that they were horribly slow.

  14. #14
    "Certified" Alphaholic MoGrace's Avatar
    Real Name
    Robin
    Join Date
    Mar 2006
    Location
    Los Angeles
    Posts
    3,584

    Default Re: Alternative method to enter/edit Memo field

    Hi Ron,
    I use something similar but have not tried to trap the save button in the memo editor. The only thing I would do different since the WOfix table is already open via the form, is use table.open_session() to do the enter. I am going to try your script and see how it works.
    Robin

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

  15. #15
    Member
    Real Name
    Mark Williams
    Join Date
    Dec 2005
    Posts
    313

    Default Re: Alternative method to enter/edit Memo field

    Quote Originally Posted by mgallardo View Post
    Don't think I've done that one before but I'll give it a go:
    Code:
    DIM tbl as P
    DIM NotesVar as C
    DIM ptrNotesVar as P
    DIM ptrNotesVar.Object as P
    DIM ptrNotesVar.text as C
    tbl = table.current()
    'NotesVar = tbl.NOTES
    ptrNotesVar.text = tbl.NOTES
    
    
    DIM SHARED DialBox as C
    ok_button_label = "&OK"
    cancel_button_label = "&Cancel"
    
    dlgTitle = "Enter Internal Notes"
    DialBox = ui_dlg_box(dlgTitle,<<%dlg%
    {startup=loadingXdlg}
    {region}
    Notes:| [%mw%.60,8ptrNotesVar];
    {endregion};
    {line=1,0};
    {region}
    <*15=ok_button_label!OK> <15=cancel_button_label!CANCEL>
    {endregion};
    %dlg%,<<%code%
    if a_dlg_button = "loadingXdlg" then
    	a_dlg_button = ""
    	ui_dlg_ctl_goto(dlgTitle,"ptrNotesVar")
    	ptrNotesVar.Object.set_cursor(len(ptrNotesVar.text)+1)
    end if
    %code%)
    
    If Dialbox = "Cancel"
    	ptrNotesVar.text = ""
    	end
    End If
    
    If ptrNotesVar.text = ""
    	end 
    ELSE
    	Dim P as P
    	DIM SHARED Test AS C
    	
    	vMode = parentform.mode_get()
    	
    	IF vMode = "CHANGE" .or. vMode = "ENTER"
    		parentform.commit()
    	END IF
    	
    	tbl = table.current() 
    	p.text= tbl.Notes
    	
    	tbl.change_begin()
    	
    	'Save the note
    	tbl.Notes = ptrNotesVar.text
    		
    	tbl.change_end(.t.)
    	Notes.refresh()
    	topparent.commit()
    	
    	'maybe add a catch here to make sure the commit went through
    	
    	ptrNotesVar.text = ""
    END IF
    I used an xdialog startup event to set the cursor and had to change the xdialog field to a pointer as per the documentation

    https://documentation.alphasoftware...._.SET_CURSOR()
    Is it possible to change the font size in the dialog box? I believe it's defaulting to an 8 pt font and I'd like to change it to 10 pt.

    Thanks

  16. #16
    "Certified" Alphaholic
    Real Name
    John Koh
    Join Date
    Jan 2004
    Location
    Maryland, USA
    Posts
    1,062

    Default Re: Alternative method to enter/edit Memo field


  17. #17
    "Certified" Alphaholic Ronald Anusiewicz's Avatar
    Real Name
    Ronald Anusiewicz
    Join Date
    Oct 2000
    Location
    Southampton, MA
    Posts
    1,547

    Default Re: Alternative method to enter/edit Memo field

    Quote Originally Posted by MoGrace View Post
    Hi Ron,
    I use something similar but have not tried to trap the save button in the memo editor. The only thing I would do different since the WOfix table is already open via the form, is use table.open_session() to do the enter. I am going to try your script and see how it works.
    Interesting point Robin.
    This code is at least 15 years old and has been in use that long pretty much on a daily basis.
    It is a spin off on code written by Dr Peter Wayne. I'll have to check his books and see if I can
    find the original.
    Alpha Anywhere v3.5
    Version 12.3, Build 2999
    MySql56 & DBF's

    Alpha 4, 5, Anywhere

    Ron Anusiewicz

  18. #18
    "Certified" Alphaholic Ronald Anusiewicz's Avatar
    Real Name
    Ronald Anusiewicz
    Join Date
    Oct 2000
    Location
    Southampton, MA
    Posts
    1,547

    Default Re: Alternative method to enter/edit Memo field

    Robin,

    The original code was from Dr. Peter Wayne on his WEB site. The article was labeled: Memos that Work. His site no longer can been found.
    I've attached a working example that I used for testing purposes. I did all kinds of copying and pasting to see if I could corrupt the memo and I
    could not.

    I did do a change as you noted using table.open_session vs. table.open. I couldn't get it to fail using table.open() but I feel you are correct
    using table.open_session().

    Let me know what you think.

    Ron
    Attached Files Attached Files
    Alpha Anywhere v3.5
    Version 12.3, Build 2999
    MySql56 & DBF's

    Alpha 4, 5, Anywhere

    Ron Anusiewicz

Similar Threads

  1. Improvements to Memo Field Edit XDialog
    By rmcgaffic in forum Archived Wishlist
    Replies: 4
    Last Post: 05-26-2009, 12:38 PM
  2. Memo Field Edit Button - V??
    By snyhof in forum Alpha Five Version 9 - Desktop Applications
    Replies: 2
    Last Post: 05-04-2009, 07:40 AM
  3. How to display/edit memo field in a web form (dialog?)
    By jfh2005 in forum Application Server Version 9 - Web/Browser Applications
    Replies: 2
    Last Post: 12-13-2008, 11:25 PM
  4. v4.5 enter/exit memo field problems
    By bob muzik in forum Alpha Five Version 4
    Replies: 4
    Last Post: 03-17-2002, 04:16 PM
  5. v4.5 enter/exit memo field problems
    By bob muzik in forum Alpha Five Version 4
    Replies: 0
    Last Post: 03-11-2002, 03:34 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •