Alpha Video Training
Results 1 to 6 of 6

Thread: OnWroteField Event

  1. #1
    Member
    Real Name
    Walter
    Join Date
    Jun 2003
    Location
    South Africa
    Posts
    456

    Default OnWroteField Event

    Hi all,

    Is it possible to create a script in the table "onwrotefield" event to update another field value in the same table.

    This is what i want to do.
    I have a browse of tbl_1, as soon as the user enter or change a value in field_1, I want field_2 to update to today's date.

    Maybe there is another way, but it's one of those days again-stupidity all over the palce !

    Thanks
    Walter

  2. #2
    Member
    Real Name
    Walter
    Join Date
    Jun 2003
    Location
    South Africa
    Posts
    456

    Default RE: OnWroteField Event

    I got it,
    In the field_1 onwrotefield event i put,

    tbl = table.current()
    tbl.field_2 = Date()

    simple...

  3. #3
    Former Alpha Employee JerryBrightbill's Avatar
    Real Name
    Jerry Brightbill
    Join Date
    Apr 2000
    Posts
    5,173

    Default RE: OnWroteField Event

    Walter

    One of the best ways to test the action of an event is to test it and see if the effect is what you want. Your idea should work fine. If you table is named "Mytable" and the field that has the date is named "EditDate", you could try this in the event for the first field

    Mytable-"EditDate = date()

    Some people may suggest you use a calculated field for the date that calculates the date to the current date, but this would change the date anytime the record is saved, not just when that one field is written.

    Jerry

  4. #4
    "Certified" Alphaholic
    Real Name
    Cal Locklin
    Join Date
    Mar 2000
    Location
    S.E. Michigan
    Posts
    5,763

    Default RE: OnWroteField Event

    Walter,

    Your method will work fine.

    For anyone else that wants to do something like this, here's what I've found....

    Most of my tables now contain a field called Change_dtf which I want to update every time the user specifically changes something in the record but not for global updates, etc.

    I found that the following works every time when put in the CanSave event:
    tc = table.current()
    tc.change_dtf = date()

    However, the following does NOT work reliably in the CanSave event even though this type of construction will work from most other scripts:
    table.current().change_dtf = date()

    The advantage of this method over something like:
    MyTableName->FieldName = date()
    is that it is completely universal and I can cut-and-paste or, in my case, use a keyboard macro to enter the whole thing with just a couple keystrokes.

    Also, the advantage of using something like this in the CanSave event, as pointed out by Jerry, is that it only works when the user changes something. A global update or a Re-evaluate Field Rules will not reset my Change_dtf field.

    Cal Locklin
    www.aimsdc.net

  5. #5
    Former Alpha Employee JerryBrightbill's Avatar
    Real Name
    Jerry Brightbill
    Join Date
    Apr 2000
    Posts
    5,173

    Default RE: OnWroteField Event

    Cal

    I use both approaches, but I prefer not even doing it in field rules. I prefer creating the code on any data entry form and using form events. The reason is simple. If you use

    t = table.current()

    to get a pointer, that will fail in a set where the current table is not in the first slot, but exists as a child in the set. Using

    MyTableName-"FieldName

    works even in a set as long as the table is not opened more than once and is using an alias. They you might need

    MyTableName1-"FieldName.

    I much prefer just doing it on a form where the object names are fixed or the slot position for table.current() is known.

    Jerry

  6. #6
    "Certified" Alphaholic
    Real Name
    Cal Locklin
    Join Date
    Mar 2000
    Location
    S.E. Michigan
    Posts
    5,763

    Default RE: OnWroteField Event

    Jerry,

    Logically I would agree with you - Table.current() should refer to the parent table normally. However, for some reason this particular script in the CanSave event seems to work even in a set. I just checked it again tonight to be sure nothing had changed in the most recent v5 version. (I haven't verified it in v6 yet.)

    I went to an old app where I have a set with Chk_Acct as the parent and Transact as the 1:M child table. I modified the Chk_Acct table to add the new field and the CanSave script. I then opened the form based on this set and edited one of the Transact records and the Change_dtf field was correctly updated. In this case, the parent table doesn't even have a Change_dtf field so it should have issued an error if Table.current() found the parent table.

    I know this is counter-intuitive but it seems to work. I can only guess that it is because the Table.current() function is in the field rules of that specific table.

    Cal Locklin
    www.aimsdc.net

Similar Threads

  1. which event?
    By Zod Mansour in forum Alpha Five Version 6
    Replies: 16
    Last Post: 03-14-2005, 08:49 PM
  2. event id 26
    By Trixie dela Cena in forum Alpha Five Version 5
    Replies: 3
    Last Post: 10-14-2004, 07:41 PM
  3. Which Event?
    By Schulzie in forum Alpha Five Version 4
    Replies: 1
    Last Post: 09-02-2003, 03:44 PM
  4. Tab event
    By John Magno in forum Alpha Five Version 5
    Replies: 1
    Last Post: 01-04-2003, 08:53 AM
  5. Event Definitions?
    By Louis Nickerson in forum Alpha Five Version 5
    Replies: 3
    Last Post: 09-27-2002, 11:17 AM

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
  •