Results 1 to 6 of 6
  1. #1
    Join Date
    May 2004
    Posts
    2

    Unanswered: How to Define a Default Value for a Microsoft Access Field

    Hi everybody, i have a problem in Access 2000.
    I want to assign some field values to one field's default value.
    Ex : I have a table contain field A,B,C both is integer.
    Now i want default value of C = value of field A + value of field B.
    But all this assign in the design mode.
    Thank you

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    you cannot do that with default values (at least, i don't think so)

    instead create your table with only columns A and B

    then write this query:
    Code:
    select A, B, A+B as C from yourtable
    save this query with a name, and then from now on, query the query instead of the table
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    May 2004
    Posts
    2
    "you cannot do that with default values (at least, i don't think so)"

    the problem is that i have to do it with default values, by giving the value A+B to C (A,B and C belong to the same table)

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    homework assignment?


    did you by any chance happen to try the saved query? that is how access implements views, and a view is definitely what this calls for

    it is not a good idea to store redundant data
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Apr 2004
    Location
    Sydney Australia
    Posts
    369
    As r937 said, you do it from a query of your table.

    Another way to do it is in the query design and you will have

    Field A........FieldB dragged down from your table.

    You then create a new field (in one of the blank columns) by typing

    FieldC:[FieldA]+[FieldB]

  6. #6
    Join Date
    Dec 2003
    Location
    Dallas, TX
    Posts
    1,004
    I like to third that notion as well. You posed a question and got the correct answer for it. DEFAULTvalue means the Value of THAT particular field. What you are wanting is a CALCULATED FIELD and that is done either in your QUERY, FORM or REPORT by placing usually a Text field to hold that calculated value. Example of a Default Value is like in a Date field where you want the CurrentDate to be the default, and would do so by placing "Date()" in the DefaultValue field. Just remember, you CAN'T place a Calculated Field in your Table. Table only Hold the information for you. Queries and the such Display it and Calculate it for you.

    have a nice day
    Bud

Posting Permissions

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