Results 1 to 9 of 9
  1. #1
    RuNu1 is offline Novice
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    2

    Date that is 7 days greater or less than another date.

    Hi all,
    this is my first thread so thanks in advance to anyone who can help out.


    I am trying to code a field in MS Access 2003 query that shows a 1 when a date is either 7 days [or more] before or after the progress date [progress date is a field with the db]. Can anyone please show me the required syntax/function as have tried DateAdd, DateDiff etc and am having no luck.
    Thanks again.

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,540
    Hi

    what is the name of your date field?
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    xpertoffice is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    4

    Smile Calculated Date Field

    Enter below in query field box:

    MyCalcField: IIF(DateAdd('d', 7, [ProgressDate]) > Now(),0,1)

    returns 1 or 0

    Should set the Format property of MyCalcField to GeneralNumber but will work anyway.


    xpertOffice...

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,540
    Hi

    I could be wrong, but (there's always a but) I think the solution posted by xpertofice will only return the required value of 1 when the "ProgressDate" is more than 7 days from now. My understanding is that the value of 1 should also be returned if the "ProgressDate" is more than 7 days before now.

    If that is correct you may like to try this instead:

    Code:
     
    MyCalcField: IIF(DateAdd('d', 7, [ProgressDate]) > Now(),0,1) + 
    IIF(DateAdd('d', 7, [ProgressDate]) < Now(),0,1)
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    RuNu1 is offline Novice
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    2
    Thanks Gents for the replies. What I need is to highlight where the date in my progress_date field is either 7 or more days before or after the progress date. For example progress date is the 10/05/2011 and the date in the created_date field is on or brefore 03/05/2011 then 1 and also if created_date on or after 17/05/2011 then 1. In other words there is a window of acceptance of 14 days from the progress_date that the created_date can be in.

    Thanks again

  6. #6
    xpertoffice is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    4

    Smile Ouooops!

    Yes, I think Bob read it better than me.

    But I think you need to change the > to => and < to =< to catch the 7 day state, as was requested (now I've read it forensically!)


    xpertOffice....

  7. #7
    xpertoffice is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    4

    Thumbs down Ouooops! Ouooops!

    Where's this CreatedDate suddenly appeared from; your original post just said the 'Date', we assumed that meant the date you run the query; ie Now().

    So taking what has been said so far, change the Now() for [created_
    date].

    I'm off to get my big toe nail sorted..

    xpertOffice...

  8. #8
    pervezjan is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2012
    Posts
    12
    I need help in vba code.

    I am facing problem to validate the date the syntax I am writing in date field is as under (field name is date)

    If date > +7 or date< -7 then
    Msgbox "wrong"
    end if
    I mean If date is greater than 1 week or less thab one week then I need a message

  9. #9
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,540
    "Date" is a reserved word in Access (see: http://allenbrowne.com/AppIssueBadWord.html) so change the name of the text box to "MyDate" and try:
    Code:
    If Me.[MyDate] >= Me.[MyDate] +7 OR Me.[MyDate] <= Me.[MyDate] -7 then
      Msgbox "wrong"
    End if
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

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

Similar Threads

  1. Replies: 5
    Last Post: 06-13-2011, 01:30 PM
  2. Greater than or equal to date
    By stryder09 in forum Access
    Replies: 1
    Last Post: 04-14-2011, 03:54 PM
  3. Greater than date
    By I-am-me in forum Queries
    Replies: 1
    Last Post: 08-18-2009, 05:21 AM
  4. Replies: 2
    Last Post: 07-31-2009, 06:56 AM
  5. Replies: 1
    Last Post: 12-09-2005, 10:29 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