473,657 Members | 2,592 Online
Bytes | Software Development & Data Engineering Community
+ 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.Abse nceDate,
tblAbsence.Abse nceReason, FROM tblemp INNER JOIN tblAbsence ON tblemp.ID =
tblAbsence.ID WHERE (((tblAbsence.A bsenceDate) Between " & Datefrom & " And
" & Dateto & " AND ((tblemp.DateOf Leaving) 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 1648
Whenever I'm using Dates in a query like this, I usually surround them with
#, like this:

"SELECT tblemp.Surname, tblemp.Forename , tblAbsence.Abse nceDate,
tblAbsence.Abse nceReason, FROM tblemp INNER JOIN tblAbsence ON tblemp.ID =
tblAbsence.ID WHERE (((tblAbsence.A bsenceDate) Between #" & Datefrom & "#
And
#" & Dateto & "# AND ((tblemp.DateOf Leaving) Is Null));"

Hope that helps,

cheers,
Matt.
"Deano" <ma************ @hotmail.com> wrote in message
news:wY******** ***********@war ds.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.Abse nceDate,
tblAbsence.Abse nceReason, FROM tblemp INNER JOIN tblAbsence ON tblemp.ID =
tblAbsence.ID WHERE (((tblAbsence.A bsenceDate) Between " & Datefrom & " And " & Dateto & " AND ((tblemp.DateOf Leaving) 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.Abse nceDate,
tblAbsence.Abse nceReason, FROM tblemp INNER JOIN tblAbsence ON
tblemp.ID = tblAbsence.ID WHERE (((tblAbsence.A bsenceDate) Between #"
& Datefrom & "# And
#" & Dateto & "# AND ((tblemp.DateOf Leaving) 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.Abse nceDate,
tblAbsence.Abse nceReason, FROM tblemp INNER JOIN tblAbsence ON
tblemp.ID = tblAbsence.ID WHERE ((tblAbsence.Ab senceDate) Between #"
& Datefrom & "# And
#" & Dateto & "# AND ((tblemp.DateOf Leaving) Is Null));"
Nov 12 '05 #3
"Deano" <ma************ @hotmail.com> wrote in message news:<wY******* ************@wa rds.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.Abse nceDate,
tblAbsence.Abse nceReason, FROM tblemp INNER JOIN tblAbsence ON tblemp.ID =
tblAbsence.ID WHERE (((tblAbsence.A bsenceDate) Between " & Datefrom & " And
" & Dateto & " AND ((tblemp.DateOf Leaving) 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.Abse nceDate,
tblAbsence.Abse nceReason, FROM tblemp INNER JOIN tblAbsence ON tblemp.ID =
tblAbsence.ID WHERE (((tblAbsence.A bsenceDate) Between #" & Me.Datefrom & "# And
#" & Me.Dateto & "# AND ((tblemp.DateOf Leaving) 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
3859
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 identified as parameters so that the date range can be found without causing an error. So far so good, report works as it should. Here's the problem. There are several reports that need to be printed at the end of month that use the same...
4
2087
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 the date selected. Here's the problem: The report that the crosstab query feeds was initially created to show all the dates and thus, all 26 columns. However, since I modified the crosstab query to only return up to what is selected on the...
5
2321
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 an unbound text box, with the format set to 'dd/mm/yyyy'. In the SQL code generated in the report_open event, I set the dates in the WHERE clause to: strDates = Forms!.cboDateField.Column(1) & " BETWEEN CONVERT(DATETIME, '" &...
1
3237
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 converted my dates in serial increments of 6 hours intervals. I verified that these serial dates have the expected values. I run into repeated syntax error in the adapted Query.
4
2330
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 problem - I'd done plenty of that sort of thing before, but, to cut a long story short, my usual (component-less) upload scripts generated a multitude of errors I'd never seen before, and a number of other component-less scripts I tried to use all...
1
2759
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 have a table containing records for each job done, the records contain date, employee name, job done (a code representing the type of job), cost code (another code), regular hours, and overtime hours. The tricky part is that more than one job can...
9
4015
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 my fields. When I try to run it I get #errors in my RunTot column. I'm kinda new to this. Not sure if maybe I mistyped something wrong or is there a better way to do this? I have pasted the code. Any help would be greatly appreciated....
12
2100
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 issue. My DB consists of hundreds of unique pieces of information (in atomic tables of course). However, I have many multiple queries that are required to compile information and conduct various calculations to put it in a workable format for...
16
3488
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 renaming the duplicate records? My thinking was to take the results of the duplicate query, and somehow have it number each line where there is a duplicate (tried a groups query, but "count" won't work), then do an update query to change the duplicate to...
0
8425
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8743
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8522
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7355
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5647
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1736
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.