Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2009

    Unanswered: adding values of 2 fields in a form

    Hi guys, I made a form for data entry, the forms datasource table is called Conference record. In the form the user enters in the data in the fields and it saves all the information on the table. My problem is i'm trying to add values of 2 fields on the form, land field and improvements field, and have the total be displayed in the Total field. I added this code =Sum([Land])+([Improvements]) but it adds up all the values for the land and improvements fields in the Conference record table, not just the values for the one specific record. So i need to add up only the "land" field and "improvements" field for each specific record and have it displayed in the "Total" field on the form. I also need the value of the Total to be saved to the Conference record table under the Totals column.

  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    you need to do this using a bit of VBA
    triggered by the forms on current event (to set the value when the current record changes)
    the controls on change or on lost focus events and arguably before update events

    the code should be, I'd suggest, in a function
    private sub updatetotals()
    dim localvar1 as string
    dim localvar2 as string
    dim numericvar as double
    localvar1=nz(control1.text,0) 'test to see if the control value is null if so use 0
    if isnumeric(localvar1) then numericvar=localvar1
    if isnumeric(localvar2) then numericvar=numericvar+localvar2
    control3.text = numericvar
    end sub

    then place a call to that function in each event

    you may not be abkle to use the on change events as these may well muck up the user interface

    btw you do not need to store this information anywhere, its composite data, it can be recreated whenever require.. so don't store it.
    when you need to use the total either add it as part of the query or part of the form or report
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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