Connecting Tech Pros Worldwide Help | Site Map

Date queries

  #1  
Old July 24th, 2008, 08:50 AM
Member
 
Join Date: Mar 2008
Location: Bangalore, India
Posts: 47
Hi,

Sorry to be reopening this thread. but i am still unable to get this solved. The code i have used is
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport "NameOfTheReport", acViewPreview, , Date - 3
I get an error message saying "Compile Error : Can't find project or library"

If this is closed out, i can deliver my project. Please help!!!

Thanks
Neo
  #2  
Old July 25th, 2008, 05:11 AM
puppydogbuddy's Avatar
Expert
 
Join Date: May 2007
Location: Florida
Posts: 1,915

re: Date queries


I think your problem is with Date - 3. If you are referring to the system date, the syntax should be as follows: Date() - 3
  #3  
Old July 25th, 2008, 05:41 AM
Member
 
Join Date: Mar 2008
Location: Bangalore, India
Posts: 47

re: Date queries


Quote:
Originally Posted by puppydogbuddy
I think your problem is with Date - 3. If you are referring to the system date, the syntax should be as follows: Date() - 3

When i tried doing that, the paranthesis () just disappeared. and it ended up being the way it is now. Am unable to change that.
  #4  
Old July 25th, 2008, 06:30 AM
Member
 
Join Date: Mar 2008
Posts: 69

re: Date queries


Since Access is looking for an SQL string clause without the "WHERE", I think you should try something like:

Expand|Select|Wrap|Line Numbers
  1. "DateFieldInQuery = #" & Date() - 3 & "#"
"DateFieldInQuery" is whatever is the name that you have assigned in the query to the date you want to test. The # before and after tells Access that the number returned by Date() - 3 should be teated as a date.
  #5  
Old July 25th, 2008, 07:01 AM
Member
 
Join Date: Mar 2008
Location: Bangalore, India
Posts: 47

re: Date queries


Quote:
Originally Posted by youmike
Since Access is looking for an SQL string clause without the "WHERE", I think you should try something like:

Expand|Select|Wrap|Line Numbers
  1. "DateFieldInQuery = #" & Date() - 3 & "#"
"DateFieldInQuery" is whatever is the name that you have assigned in the query to the date you want to test. The # before and after tells Access that the number returned by Date() - 3 should be teated as a date.
But would this not be a query? how do i insert this in the where clause in the code?
  #6  
Old July 25th, 2008, 07:42 AM
Expert
 
Join Date: Jan 2008
Posts: 365

re: Date queries


Quote:
Originally Posted by neosam
But would this not be a query? how do i insert this in the where clause in the code?
Expand|Select|Wrap|Line Numbers
  1. "SELECT * FROM Tablename WHERE Datefieldname =  # " & Date() - 3 & "#"
  2.  
  #7  
Old July 25th, 2008, 07:44 AM
Expert
 
Join Date: Jan 2008
Posts: 365

re: Date queries


The way that you would put that into your openreport command is as follows:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport "NameOfTheReport", acViewPreview, , "Datefieldname =  # " & Date() - 3 & "#"
  2.  
  #8  
Old July 25th, 2008, 09:11 AM
Member
 
Join Date: Mar 2008
Location: Bangalore, India
Posts: 47

re: Date queries


Quote:
Originally Posted by PianoMan64
The way that you would put that into your openreport command is as follows:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport "NameOfTheReport", acViewPreview, , "Datefieldname =  # " & Date() - 3 & "#"
  2.  
I still get the same error message. "Cannot find project or library" and the 'date' in the code is highlighted.
  #9  
Old July 25th, 2008, 12:59 PM
puppydogbuddy's Avatar
Expert
 
Join Date: May 2007
Location: Florida
Posts: 1,915

re: Date queries


try:
Format(Date(),"mm/dd/yyyy") - 3
  #10  
Old July 25th, 2008, 01:26 PM
Expert
 
Join Date: Jun 2007
Location: Derbyshire, UK
Posts: 344
Provided Answers: 5

re: Date queries


Hi

I have had this problem a few times over the years. It seems to be a referencing problem (perhaps when using A2000 on a DB created in A2003 but in A2000 format), and yes the parentheses do disappear when Date() is used. These only seem necessary in Query designer. I have never found a satisfactory answer to this, but in the past, in desperation, I have resorted to Int(Now()) in stead of Date !!


MTB
  #11  
Old July 25th, 2008, 04:56 PM
Moderator
 
Join Date: Feb 2008
Location: Beauly, near Inverness, Scotland
Posts: 1,573
Provided Answers: 7

re: Date queries


Hi. When Date() is no longer recognised as a valid function the problem seems to arise as a result of missing or incorrect project references for that installation, as MTB said. To trace which one it may be best to compare the project references for the 'problem' installation to those for a 'known good' PC running Access with no problems.

I experienced this on a laptop installation, and all the development databases I was working on failed on normal built-in functions - Date was just one of many that caused compile errors and other completely daft symptoms. There was a missing reference in my case, but in others I know of it was a conflicting reference (to the wrong version of a DLL). It's really annoying because there is actually nothing wrong with the underlying DBs or their code, and trying to trace non-existent errors is such a fruitless task.

-Stewart
  #12  
Old July 28th, 2008, 06:28 AM
Member
 
Join Date: Mar 2008
Location: Bangalore, India
Posts: 47

re: Date queries


Quote:
Originally Posted by Stewart Ross Inverness
Hi. When Date() is no longer recognised as a valid function the problem seems to arise as a result of missing or incorrect project references for that installation, as MTB said. To trace which one it may be best to compare the project references for the 'problem' installation to those for a 'known good' PC running Access with no problems.

I experienced this on a laptop installation, and all the development databases I was working on failed on normal built-in functions - Date was just one of many that caused compile errors and other completely daft symptoms. There was a missing reference in my case, but in others I know of it was a conflicting reference (to the wrong version of a DLL). It's really annoying because there is actually nothing wrong with the underlying DBs or their code, and trying to trace non-existent errors is such a fruitless task.

-Stewart
Well the int(Now()) command helps. Thanks guys......
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date queries.. neosam answers 5 June 27th, 2008 10:25 PM
date queries with portions of the date unknown bps4484 answers 5 February 14th, 2007 08:55 PM
A couple of date queries Dave Rado answers 15 May 22nd, 2006 03:45 PM
Date Queries Colin Mardell answers 4 November 13th, 2005 06:06 AM
Date Queries - #10/01/2004# - #1/10/2004# CLarkou answers 6 November 13th, 2005 04:49 AM