Results 1 to 6 of 6
  1. #1
    ssturges is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    5

    Help with adding to a date type as default field

    Hey guys, I'm really new to access and I'm not sure if what I am asking is even possible.



    I have a table, and I want to add a date, to an integer to get a new date. In excel, I would just use Date(year(cell),Month(cell) + etc), I'm not sure what the syntax for Access is for this task.

    I want one of my fields to be equal to Date of one field, plus number of months to add to that date to get a new Date.

    I've been looking around, I see that this is normally done with queries. I am trying to to do with one of my table.

    Thanks for the help.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    You can just add a number to a date value. The default unit is day so: Date() + 4 will add 4 days to current date. Use DateAdd function to specify calculation for other units.

    Calculations can be done in table only in a Calculated datatype field and it appears that DateAdd function is not available. You could do: [your field name] + 60 to add 60 days to the date. Or DateSerial is available.

    Can use DateAdd function in a query or textbox ControlSource on form or report.

    Here is a reference for functions available in Access, see the DateTime category http://office.microsoft.com/en-us/ac...959.aspx?CTT=3
    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
    ssturges is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    5
    So I tried: [my field name] + [another field name] and access keeps giving me the error "The database engine does not recognize either the field 'my field name' in a validation expression, or the default value in the table 'My table name'.

    The only function that seems to work is the: Date() + (some constant).
    for example: I have a starting date, and I have a integer months, and I want to add them to get the end date.
    is this even possible with using the default value property?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Sorry, I missed the point that you wanted this in DefaultValue property. Why would you want a calculation of two fields there? Saving calculated data is usually a bad idea. This calculated data should not be saved to table. Save the raw data and do the calculation 'on-the-fly' when needed. Also, DefaultValue only works when record is initiated, so if either term's value is not there when the record is initiated, the default value would not calculate.
    Last edited by June7; 11-18-2012 at 11:03 AM.
    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.

  5. #5
    ssturges is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    5
    Ah, you're right. (That's the Excel part of me trying to do everything one place)So instead of trying to calculate the date, in the table field, I think it would be a better ideal to do this in a Query. I will play more around with this until I get stuck again. Thanks for your help

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Probably why Access 2010 introduced the Calculated field so that some calculations can be shown in table without having to use query or textbox ControlSource expression. These calculated fields can be used just like any native raw data field and is what I initially thought you were trying to do.

    However, use of this datatype field can make the db incompatible with Access 2007 and more difficult to convert to even older versions.
    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.

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

Similar Threads

  1. Adding the day of the week to a date field
    By cschieff in forum Reports
    Replies: 2
    Last Post: 10-24-2012, 02:47 PM
  2. Set default export file type for queries
    By Lady_Jane in forum Import/Export Data
    Replies: 1
    Last Post: 03-29-2012, 04:53 PM
  3. Replies: 1
    Last Post: 08-07-2011, 07:58 AM
  4. Replies: 5
    Last Post: 07-18-2011, 06:07 PM
  5. Replies: 10
    Last Post: 04-21-2010, 01:16 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