473,472 Members | 2,155 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

A2k - Query error, concerning dates (quick fix i'm sure)

Ta for looking.

I am setting this SQL to the recordsource of a report but it's complaining
about a syntax error.

"SELECT tblemp.Surname, tblemp.Forename, tblAbsence.AbsenceDate,
tblAbsence.AbsenceReason, FROM tblemp INNER JOIN tblAbsence ON tblemp.ID =
tblAbsence.ID WHERE (((tblAbsence.AbsenceDate) Between " & Datefrom & " And
" & Dateto & " AND ((tblemp.DateOfLeaving) Is Null));"

I'm hoping to cover a date range as specified by the user - i have captured
these dates in the variables Dateform and Dateto.

As I say my raw SQL is bad so any help much appreciated, deadline looming (:

thanks
Martin
Nov 12 '05 #1
3 1639
Whenever I'm using Dates in a query like this, I usually surround them with
#, like this:

"SELECT tblemp.Surname, tblemp.Forename, tblAbsence.AbsenceDate,
tblAbsence.AbsenceReason, FROM tblemp INNER JOIN tblAbsence ON tblemp.ID =
tblAbsence.ID WHERE (((tblAbsence.AbsenceDate) Between #" & Datefrom & "#
And
#" & Dateto & "# AND ((tblemp.DateOfLeaving) Is Null));"

Hope that helps,

cheers,
Matt.
"Deano" <ma************@hotmail.com> wrote in message
news:wY*******************@wards.force9.net...
Ta for looking.

I am setting this SQL to the recordsource of a report but it's complaining
about a syntax error.

"SELECT tblemp.Surname, tblemp.Forename, tblAbsence.AbsenceDate,
tblAbsence.AbsenceReason, FROM tblemp INNER JOIN tblAbsence ON tblemp.ID =
tblAbsence.ID WHERE (((tblAbsence.AbsenceDate) Between " & Datefrom & " And " & Dateto & " AND ((tblemp.DateOfLeaving) Is Null));"

I'm hoping to cover a date range as specified by the user - i have captured these dates in the variables Dateform and Dateto.

As I say my raw SQL is bad so any help much appreciated, deadline looming (:
thanks
Martin

Nov 12 '05 #2
Matt. wrote:
Whenever I'm using Dates in a query like this, I usually surround
them with #, like this:

"SELECT tblemp.Surname, tblemp.Forename, tblAbsence.AbsenceDate,
tblAbsence.AbsenceReason, FROM tblemp INNER JOIN tblAbsence ON
tblemp.ID = tblAbsence.ID WHERE (((tblAbsence.AbsenceDate) Between #"
& Datefrom & "# And
#" & Dateto & "# AND ((tblemp.DateOfLeaving) Is Null));"

Hope that helps,

cheers,
Matt.


Thanks Matt, I included your amendments and then finally cracked it by
taking a leading bracket out just after the WHERE clause;

"SELECT tblemp.Surname, tblemp.Forename, tblAbsence.AbsenceDate,
tblAbsence.AbsenceReason, FROM tblemp INNER JOIN tblAbsence ON
tblemp.ID = tblAbsence.ID WHERE ((tblAbsence.AbsenceDate) Between #"
& Datefrom & "# And
#" & Dateto & "# AND ((tblemp.DateOfLeaving) Is Null));"
Nov 12 '05 #3
"Deano" <ma************@hotmail.com> wrote in message news:<wY*******************@wards.force9.net>...
Ta for looking.

I am setting this SQL to the recordsource of a report but it's complaining
about a syntax error.

"SELECT tblemp.Surname, tblemp.Forename, tblAbsence.AbsenceDate,
tblAbsence.AbsenceReason, FROM tblemp INNER JOIN tblAbsence ON tblemp.ID =
tblAbsence.ID WHERE (((tblAbsence.AbsenceDate) Between " & Datefrom & " And
" & Dateto & " AND ((tblemp.DateOfLeaving) Is Null));"

I'm hoping to cover a date range as specified by the user - i have captured
these dates in the variables Dateform and Dateto.

As I say my raw SQL is bad so any help much appreciated, deadline looming (:

thanks
Martin

Martin,
you have to wrap the date fields in Date delimiters (#)

"SELECT tblemp.Surname, tblemp.Forename, tblAbsence.AbsenceDate,
tblAbsence.AbsenceReason, FROM tblemp INNER JOIN tblAbsence ON tblemp.ID =
tblAbsence.ID WHERE (((tblAbsence.AbsenceDate) Between #" & Me.Datefrom & "# And
#" & Me.Dateto & "# AND ((tblemp.DateOfLeaving) Is Null));"
HTH,
Pieter
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Michael DeLawter | last post by:
Using Access 2002. I have a chart in a report that is currently based on a query in which the user enters the start and end date for the chart to display. Both the start and end dates have been...
4
by: No Spam | last post by:
Dear Access 2000 users, I have a crosstab query that puts together certain information perfectly. It has a criteria that is based on a form that limits how many columns are returned based on...
5
by: tim.pascoe | last post by:
I'm running into a problem using dates in a query which supplied data to a report. The WHERE clause of the query is dynamically generated, based on selections made on a form. Users enter dates in...
1
by: u473 | last post by:
I am scratching my head with the required quotes and parentheses. I started with an existing working Query with Running Total by date. Now I need to produce a running total by quarter day, so I...
4
by: sparky | last post by:
I've been working on an ASP driven website, on a client's web hosting space. One of the project requirements was the ability for the client to be able to upload files through an HTTP form. No...
1
by: Rob Woodworth | last post by:
Hi, I'm having serious problems getting my report to work. I need to generate a timesheet report which will contain info for one employee between certain dates (one week's worth of dates). I...
9
by: JJM0926 | last post by:
I'm trying to create a running totals query in access 97. I have followed the directions on how to do it from Microsofts website article id 138911. I took their code they had and replaced it with...
12
by: bhipwell via AccessMonster.com | last post by:
Hello, I have hit the "Cannot open any more databases" and "System resource exceeded" errors. Knew this was coming, but as I got closer to finishing the database, I hoped it wouldn't be an...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.