473,326 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Access / SQL query

I'm trying to calculate, from a SQL statement, the count of days to a persons birthday.

I'm trying the following:
strSQL = "SELECT * FROM Employees WHERE (DateDiff('d', Date, (DateSerial(Month([DateOfBirth]),Day([DateOfBirth]),Year(Date))) BETWEEN 0 AND 5"

The [DateOfBirth] is a field in the Employees table. Yet, I always receive a 3061 runtime error... anybody got any idea what is wrong? Yes, there are records in the table satisfying the asked conditions.

Many many thanks in advance!
Sep 27 '06 #1
8 8691
tshvw
3
Hello,

well I don't know the answer but I always make a Query in DesignView in MSAccess and when it executes okay then I look at the SQL syntax that this query is using by selecting the 'SQL-view' option in this designview query.

regards,

Henk
Sep 27 '06 #2
CaptainD
135 100+
I'm trying to calculate, from a SQL statement, the count of days to a persons birthday.

I'm trying the following:
strSQL = "SELECT * FROM Employees WHERE (DateDiff('d', Date, (DateSerial(Month([DateOfBirth]),Day([DateOfBirth]),Year(Date))) BETWEEN 0 AND 5"

The [DateOfBirth] is a field in the Employees table. Yet, I always receive a 3061 runtime error... anybody got any idea what is wrong? Yes, there are records in the table satisfying the asked conditions.

Many many thanks in advance!
The datediff function uses 3 values separated by commas, you have more then that by the way you have the last date values entered. My guess is, that is what is throwing your error.

Why not just use "WHERE DateDiff("d",Format(DateOfBirth, "mmddyyyy"), Date) Between 0 and 5
Sep 27 '06 #3
The datediff function uses 3 values separated by commas, you have more then that by the way you have the last date values entered. My guess is, that is what is throwing your error.

Why not just use "WHERE DateDiff("d",Format(DateOfBirth, "mmddyyyy"), Date) Between 0 and 5
Thanks, I'm still tinkering with this though..

I'm currently trying
Expand|Select|Wrap|Line Numbers
  1. SQL = "SELECT * FROM Employees WHERE DateDiff('d', Format([DoB], 'General Date'), Format(Date, 'General Date') ) BETWEEN 0 AND 5;"
  2. Set rs = db.OpenRecordset(SQL, dbOpenDynaset)
  3.  
But that keeps reporting a (Excpected: 1) runtime error. Any clues?
Oct 29 '06 #4
Thanks, I'm still tinkering with this though..

I'm currently trying
Expand|Select|Wrap|Line Numbers
  1. SQL = "SELECT * FROM Employees WHERE DateDiff('d', Format([DoB], 'General Date'), Format(Date, 'General Date') ) BETWEEN 0 AND 5;"
  2. Set rs = db.OpenRecordset(SQL, dbOpenDynaset)
  3.  
But that keeps reporting a (Excpected: 1) runtime error. Any clues?
My guess is you're trying to find the employees with a birthday in the next five days... Try this:

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM Employees WHERE DateDiff('d', Format(now(), 'General Date'), Format([DoB], 'General Date') ) BETWEEN 0 AND 5;
This worked for me :)

Patrick Cullen, ZA
Nov 7 '06 #5
willakawill
1,646 1GB
My guess is you're trying to find the employees with a birthday in the next five days... Try this:

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM Employees WHERE DateDiff('d', Format(now(), 'General Date'), Format([DoB], 'General Date') ) BETWEEN 0 AND 5;
This worked for me :)

Patrick Cullen, ZA
Am I missing something obvious here? Surely this would return the number of days between the date they were born and now. i.e. more than 7,000 days. Unless, of course, you are looking for 5 day old employees :)
Nov 7 '06 #6
willakawill
1,646 1GB
Thanks, I'm still tinkering with this though..

I'm currently trying
Expand|Select|Wrap|Line Numbers
  1. SQL = "SELECT * FROM Employees WHERE DateDiff('d', Format([DoB], 'General Date'), Format(Date, 'General Date') ) BETWEEN 0 AND 5;"
  2. Set rs = db.OpenRecordset(SQL, dbOpenDynaset)
  3.  
But that keeps reporting a (Excpected: 1) runtime error. Any clues?
This gives me 4
Expand|Select|Wrap|Line Numbers
  1. DateOfBirth = #11/11/2006#
  2.     MsgBox DateDiff("d", Now, DateSerial(Year(Date), Month(DateOfBirth), Day(DateOfBirth)))
  3.  
It seems that you may have entered the DateSerial parameters in the wrong order.
Nov 7 '06 #7
This gives me 4
Expand|Select|Wrap|Line Numbers
  1. DateOfBirth = #11/11/2006#
  2.     MsgBox DateDiff("d", Now, DateSerial(Year(Date), Month(DateOfBirth), Day(DateOfBirth)))
  3.  
It seems that you may have entered the DateSerial parameters in the wrong order.
Whatever I try, I can't get it to work.

For example, I try:
[code
SQL = "SELECT * FROM Werknemers WHERE DateDiff('d', Format(DateSerial(Year(Now),Month(Geboortedatum),D ay(GeboorteDatum)), 'Short Date'), Format(Date, 'Short Date') ) BETWEEN 0 AND 5;"
[/code]

This keeps on giving error 3601... while I can't find any problem.. any clues?
Dec 5 '06 #8
try this


Expand|Select|Wrap|Line Numbers
  1.  
  2. SQL = "SELECT * FROM Werknemers WHERE month(now) = month(DateOfBirth) and day(DateOfBirth) - day(now) > -1 and  day(DateOfBirth) - day(now) < 6
  3.  
  4.  
Dec 5 '06 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Frnak McKenney | last post by:
Back when computer dinosaurs roamed the earth and the precursors to today's Internet were tiny flocks of TDMs living symbiotically with the silicon giants, tracking access to data processing...
1
by: Joris Kempen | last post by:
Hi people, I know that the question has come around sometimes: How to open an Access Report using ASP and export it to for example RTF. I'm trying to implement the first method of David...
14
by: Sean C. | last post by:
Helpful folks, Most of my previous experience with DB2 was on s390 mainframe systems and the optimizer on this platform always seemed very predictable and consistent. Since moving to a WinNT/UDB...
4
by: bhbgroup | last post by:
I have a query on one large table. I only add one condition, i.e. a date (the SQL reads like 'where date > parameterdate'. This query is rather quick if 'parameterdate' is either explicitly...
52
by: Neil | last post by:
We are running an Access 2000 MDB with a SQL 7 back end. Our network guy is upgrading to Windows Server 2003 and wants to upgrade Office and SQL Server at the same time. We're moving to SQL Server...
4
by: tt40 | last post by:
Anyone know how to prevent Access 2002 from automatically breaking all the incorrect joins in a query and then automatically saving the broken query? This is what I would call stupid design...
6
by: InnoCreate | last post by:
Hi everyone. I've recently written a classic asp website which uses an MS Access datasource. I know this is less than an ideal data source as it has limited functionality. I have a search form on...
3
by: mnjkahn via AccessMonster.com | last post by:
I'm running Access 2003, modifying a query that has over 45 fields. When I right click on the field name in Query Design View, and then click Build, Access crashes before the Build window...
6
by: jsacrey | last post by:
Hey everybody, got a secnario for ya that I need a bit of help with. Access 97 using linked tables from an SQL Server 2000 machine. I've created a simple query using two tables joined by one...
13
by: magickarle | last post by:
Hi, I got a pass-through query (that takes about 15 mins to process) I would like to integrate variables to it. IE: something simple: Select EmplID from empl_Lst where empl_lst.timestamp between...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.