Results 1 to 4 of 4

Thread: Question about Access fields[RESOLVED]

  1. #1

    Thread Starter
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 2002
    Location
    Karachi
    Posts
    1,308

    Question about Access fields[RESOLVED]

    Hi,

    I have six fields in an access table, ID, num1, num2, num3, num4 and sum where ID is the primary key and all the other fields are intergers.

    In last field sum, I want to store the sum of corresponding values of fields num1, num2, num3 and num4. This is an example, I have to do something like this, I just want to know how a calculated amount of different fields can be stored in a new field.

    Thanks
    Last edited by usamaalam; Jan 17th, 2003 at 04:47 PM.

  2. #2
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    I don't think you could get an automatic way of doing it. However, you can write your INSERT/UPDATE statements such that they calculate the sum and store it in the last field, or write it in your AddNew or Edit code.

    An example would be:

    [code]
    rs.AddNew
    rs.Fields(0) = NewID
    rs.Fields(1) = X1
    rs.Fields(2) = X2
    rs.Fields(3) = X3
    rs.Fields(4) = X4
    rs.Fields(5) = X1 + X2 + X3 + X4
    rs.Update
    [/Highlight]

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  3. #3

    Thread Starter
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 2002
    Location
    Karachi
    Posts
    1,308
    I am doing the same thing uptill now, but someone told me that for doing this, you have to write a complex SQL query but I don't know the query and where to use it.

    Looking for someone to solve this problem.

    Thanks

  4. #4
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    It's not realy a complex quety:
    Leave your fields as is ; ID, Num1, Num2, Num3, Num4 take out Sum. (By the way: do not call your field "Sum', it's name for aggregate function)

    So next time when you are need to display data from your table just use sql statement:
    Code:
    SELECT *, ([Num1]+[Num2]+[Num3]+[Num4]) AS TotalSum FROM
    TableName
    
    txtTotal.Text=Recordset.Fields("TotalSum")

Posting Permissions

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



Click Here to Expand Forum to Full Width