Alpha Video Training
Results 1 to 4 of 4

Thread: .update() question

  1. #1
    Member
    Real Name
    Andrew Brown
    Join Date
    Nov 2007
    Location
    Twin Cities, MN
    Posts
    58

    Default .update() question

    I tired using this code in AfterValidate...

    DIM emp_tbl as P
    DIM emp_qry as P

    emp_tbl = table.open("emp_info",FILE_RW_SHARED)
    query.filter = "Dept = \"" + CurrentForm.Controls.UD_Dept.Value + "\""
    query.order = ""
    query.options = ""
    emp_qry = emp_tbl.query_create()
    if emp_qry.records_get() <> 0 then
    update.fields = 1
    update.field1 = "Dept"
    update.expr1 = alltrim(CurrentForm.Controls.Dept_Name.Value)
    emp_tbl.update()
    end if

    When it runs I get the error:
    Errors in: event.AfterValidate code:
    Variable update.expr1 references a non-existent field 1101-CMI SORT.

    What am I missing here? Should I just switch to a while-loop for updating records in large amounts?

    .....

    Never mind.

    update.expr1 = "'" + alltrim(CurrentForm.Controls.Dept_Name.Value) + "'"

    Worked for me.
    Last edited by cy_uab2007; 11-24-2007 at 09:10 AM. Reason: Figured it out

  2. #2
    Volunteer Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,842

    Default Re: .update() question

    I think its your syntax at update.expr1. The expression on the right side of the equal sign needs to be quoted. It appears to be taking the value of control, rather than that value in quotes. Putting quote() around the entire right hand expression should work, but I did not test this.
    Steve Wood
    Join the ALPHA DEVELOPERS NETWORK
    There is no Cloud. It's just someone else's computer.
    Web - Mobile - Hosting - Products - Frameworks - Developer Resources
    AlphaToGo | IADN (100% Alpha Anywhere Websites)

  3. #3
    Member
    Real Name
    Erik Midtskogen
    Join Date
    Sep 2007
    Location
    New York
    Posts
    32

    Default Re: .update() question

    I have had no luck getting the <tbl>.Update() function to work.

    What works for me is to use an alternate method:
    <tbl>.change_begin(.t.) '(Set the argument to .T. if you want constraints enforced)
    <tbl>.my_first_field = "whatever"
    <tbl>.my_second_field = "more whatever"
    .
    .
    <tbl>change_end(.t.) '(Set the argument to .t. to commit, or .f. to rollback the changes)

    I don't know why there are two different ways of updating a table or what the pros and cons of each way are.

    Hope this helps.
    --Erik

  4. #4
    Member
    Real Name
    Andrew Brown
    Join Date
    Nov 2007
    Location
    Twin Cities, MN
    Posts
    58

    Default Re: .update() question

    Steve, you really seem to be everywhere at once and right on the money every time. Thank you very much for your contribution to the community.

    And thanks for the alternate method, Erik. That's the direction I was thinking of going, until I got the whole quotes thing settled.

    For me the pros and cons are less lines of code, no logic loops to screw up, and somewhat cleaner looking code flow(at least to me). I think hardware wise, the update() method might allow the engine to cut down on HDD activity a little bit (one big commit instead of a buncha small ones) so you'll see a speed improvement when dealing with large numbers of records... or maybe the syntax is just easier.

    Maybe Steve knows!?

    Thanks again, guys.

Similar Threads

  1. Calendar Ad-In update question
    By Dick Krause in forum Alpha Five Version 5
    Replies: 2
    Last Post: 02-12-2004, 12:24 PM
  2. Field Update Question?
    By Keith Hubert in forum Alpha Five Version 5
    Replies: 4
    Last Post: 02-26-2003, 07:27 AM
  3. update question?
    By eeetee in forum Alpha Five Version 5
    Replies: 2
    Last Post: 01-16-2003, 01:44 PM
  4. Simple Update Question
    By Phil Rolf in forum Alpha Five Version 5
    Replies: 6
    Last Post: 11-14-2002, 06:34 PM
  5. update question
    By Mike Reed in forum Alpha Five Version 4
    Replies: 2
    Last Post: 05-08-2000, 09:13 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
  •