Results 1 to 3 of 3
  1. #1
    Thompyt is offline Expert
    Windows 10 Access 2016
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839

    Form Query field not updating table

    I am attempting to update the base table with a Form. where I reference tables the fields in the base table update. The fields where I have a bit of code in them do not update.
    Tbl_Consolidate fields not updating and stay as the default value if there is one assigned:
    Flight: IIf([SLeg]<>1,0,[FLCost])
    Bag: IIf([GNDTVL]=False And ([SLeg])=1,160,0)
    H2Air: IIf([Sleg]<>1 Or [GNDTVL]=True,0,([H2Airmiles]*0.56)*4)
    Taxi: IIf([SLeg]=1,150,0)
    Tolls: IIf([SLeg]=1,100,0)

    On the form the query works and the Qry_Test query works to update the fields

    I have tried the following with no errors, but still does not update the fields.
    Private Sub H2Air_AfterUpdate()
    TBL_Consolidate.H2AirM = Me.H2Air
    End Sub
    Private Sub H2Air_Change()
    TBL_Consolidate.H2AirM = Me.H2Air
    End Sub

    Travel_Testbed.zip


    What am I doing wrong? I think if 1 is solved the others can be solved int he same way.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Saving calculated values (data dependent on other data) is usually not necessary and can be risky. Calculate when needed. Your form RecordSource is doing this calculation. Your code is attempting to enter value into that field which is not possible because it is a calculated field. If you want to save value, then don't do calculation in query, just pull table field into RecordSource query.

    Qry_Test is just a SELECT query with calculations - it does not update anything, i.e. nothing in table is changed when this query is opened.

    I would probably not have this form RecordSource include lookup tables (simplify and just bind to Tbl_Consolidate). Alternative for displaying related lookup values is to have textboxes reference columns of comboboxes.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Thompyt is offline Expert
    Windows 10 Access 2016
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    Thanks June7, twice your explanations have set me on the right course.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 15
    Last Post: 12-08-2017, 09:56 AM
  2. Replies: 5
    Last Post: 12-26-2014, 11:04 AM
  3. Replies: 14
    Last Post: 09-13-2012, 01:15 PM
  4. Updating Yes/No field in a table via a query
    By immortal_dranzer in forum Queries
    Replies: 12
    Last Post: 03-22-2012, 12:32 AM
  5. Updating Table field from Form
    By Kunuk in forum Access
    Replies: 0
    Last Post: 02-26-2009, 11:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums