473,387 Members | 1,569 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,387 software developers and data experts.

date query

hi
i have a table conataining several fields one of which is date
i want to be able to search the table on the date field using code.
the code below generates the query from a form, however i get an error
message "Run time Error 2001" when this code is run. Can anyone please
tell me where i have gone wrong or how to stop this error message
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
Set db = CurrentDb
Set qdf = db.QueryDefs("qryArea")

strSQL = "SELECT DataTable.* " & _
"FROM DataTable " & _
"WHERE DataTable.Area='" & Me.cboDepartment.Value & "' "
& _
"AND DataTable.Dates>='" & Me.cboStartDate.Value & "'" &
_
"AND DataTable.Dates<='" & Me.cboEndDate.Value & "' " & _
"ORDER BY DataTable.opnumber;"
qdf.SQL = strSQL
DoCmd.OpenQuery "qryArea"
DoCmd.Close acForm, Me.Name
Set qdf = Nothing
Set db = Nothing

thanks in advance

kevin
Nov 13 '05 #1
6 2736
Shouldn't your date delimiter be # instead of a single quote?
Nov 13 '05 #2
On 6 Jul 2004 10:44:29 -0700, ke***@carter5711.freeserve.co.uk (kevin
carter) wrote:

To debug, I would set a breakpoint after strSQL is concatenated, and
paste the resulting string in a new query. Try to run that query, and
the parser may point out some problems.

One likely problem is that you didn't wrap the date fields with
#-signs.

To stop errors: On Error Resume Next :-)

-Tom.

hi
i have a table conataining several fields one of which is date
i want to be able to search the table on the date field using code.
the code below generates the query from a form, however i get an error
message "Run time Error 2001" when this code is run. Can anyone please
tell me where i have gone wrong or how to stop this error message
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
Set db = CurrentDb
Set qdf = db.QueryDefs("qryArea")

strSQL = "SELECT DataTable.* " & _
"FROM DataTable " & _
"WHERE DataTable.Area='" & Me.cboDepartment.Value & "' "
& _
"AND DataTable.Dates>='" & Me.cboStartDate.Value & "'" &
_
"AND DataTable.Dates<='" & Me.cboEndDate.Value & "' " & _
"ORDER BY DataTable.opnumber;"
qdf.SQL = strSQL
DoCmd.OpenQuery "qryArea"
DoCmd.Close acForm, Me.Name
Set qdf = Nothing
Set db = Nothing

thanks in advance

kevin


Nov 13 '05 #3
ke***@carter5711.freeserve.co.uk (kevin carter) wrote in message news:<2f**************************@posting.google. com>...
hi
i have a table conataining several fields one of which is date
i want to be able to search the table on the date field using code.
the code below generates the query from a form, however i get an error
message "Run time Error 2001" when this code is run. Can anyone please
tell me where i have gone wrong or how to stop this error message
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
Set db = CurrentDb
Set qdf = db.QueryDefs("qryArea")

strSQL = "SELECT DataTable.* " & _
"FROM DataTable " & _
"WHERE DataTable.Area='" & Me.cboDepartment.Value & "' "
& _
"AND DataTable.Dates>='" & Me.cboStartDate.Value & "'" &
_
"AND DataTable.Dates<='" & Me.cboEndDate.Value & "' " & _
"ORDER BY DataTable.opnumber;"
qdf.SQL = strSQL
DoCmd.OpenQuery "qryArea"
DoCmd.Close acForm, Me.Name
Set qdf = Nothing
Set db = Nothing

thanks in advance

kevin


Kevin,

This thread has everything you need in it already. Since you say you
are using a Date field, your problem stems from using single quotes
around your combobox dates rather than # symbols. In instances where
a function that returns a Date type is evaluated within the SQL
string, the #'s are not needed. Also, if possible, use date pickers.
Users love them and filling a text box from a date picker guarantees a
valid date. Maybe you could code the pickers so that they only allow
the dates that you were going to put in your combobox. But users do
like to know what dates are available for selection. I don't remember
if it's easy or not to change the background color of individual
dates.

James A. Fortune

Putting your knuckles in a line will give you a hint about which
months have 31 days. --- Anon.
Nov 13 '05 #4
Tom van Stiphout <no*************@cox.net> wrote in message news:<2n********************************@4ax.com>. ..
On 6 Jul 2004 10:44:29 -0700, ke***@carter5711.freeserve.co.uk (kevin
carter) wrote:

To debug, I would set a breakpoint after strSQL is concatenated, and
paste the resulting string in a new query. Try to run that query, and
the parser may point out some problems.

One likely problem is that you didn't wrap the date fields with
#-signs.

To stop errors: On Error Resume Next :-)

-Tom.

hi
i have a table conataining several fields one of which is date
i want to be able to search the table on the date field using code.
the code below generates the query from a form, however i get an error
message "Run time Error 2001" when this code is run. Can anyone please
tell me where i have gone wrong or how to stop this error message
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
Set db = CurrentDb
Set qdf = db.QueryDefs("qryArea")

strSQL = "SELECT DataTable.* " & _
"FROM DataTable " & _
"WHERE DataTable.Area='" & Me.cboDepartment.Value & "' "
& _
"AND DataTable.Dates>='" & Me.cboStartDate.Value & "'" &
_
"AND DataTable.Dates<='" & Me.cboEndDate.Value & "' " & _
"ORDER BY DataTable.opnumber;"
qdf.SQL = strSQL
DoCmd.OpenQuery "qryArea"
DoCmd.Close acForm, Me.Name
Set qdf = Nothing
Set db = Nothing

thanks in advance

kevin

thanks both for your reply , your suggestions resolved the issue,
however i now have a bigger problem

Given that i live in the UK the date format is in correct
Access always uses the American format #mm/dd/yy#
while in the UK our date is set to #dd/mm/yy#
this is giving me a problem. the records are stored in UK format and
the query is searching in US Format. Is there anyway i can force
access to search my date field in Uk Format and return the correct
records?

thanks
kevin
Nov 13 '05 #5
On 7 Jul 2004 05:10:44 -0700, kc******@ford.com (Kevin Carter) wrote:

Dates should be stored in fields with the date/time format, which is
some 8-byte format we don't need to know about.
For presentation reasons, you may need to apply a format, for example:
Format$(MyDateField, "mm/dd/yyyy")

-Tom.
Tom van Stiphout <no*************@cox.net> wrote in message news:<2n********************************@4ax.com>. ..
On 6 Jul 2004 10:44:29 -0700, ke***@carter5711.freeserve.co.uk (kevin
carter) wrote:

To debug, I would set a breakpoint after strSQL is concatenated, and
paste the resulting string in a new query. Try to run that query, and
the parser may point out some problems.

One likely problem is that you didn't wrap the date fields with
#-signs.

To stop errors: On Error Resume Next :-)

-Tom.

>hi
>i have a table conataining several fields one of which is date
>i want to be able to search the table on the date field using code.
>the code below generates the query from a form, however i get an error
>message "Run time Error 2001" when this code is run. Can anyone please
>tell me where i have gone wrong or how to stop this error message
>
>
> Dim db As DAO.Database
> Dim qdf As DAO.QueryDef
> Dim strSQL As String
> Set db = CurrentDb
> Set qdf = db.QueryDefs("qryArea")
>
> strSQL = "SELECT DataTable.* " & _
> "FROM DataTable " & _
> "WHERE DataTable.Area='" & Me.cboDepartment.Value & "' "
>& _
> "AND DataTable.Dates>='" & Me.cboStartDate.Value & "'" &
>_
> "AND DataTable.Dates<='" & Me.cboEndDate.Value & "' " & _
> "ORDER BY DataTable.opnumber;"
> qdf.SQL = strSQL
> DoCmd.OpenQuery "qryArea"
> DoCmd.Close acForm, Me.Name
> Set qdf = Nothing
> Set db = Nothing
>
>thanks in advance
>
>kevin

thanks both for your reply , your suggestions resolved the issue,
however i now have a bigger problem

Given that i live in the UK the date format is in correct
Access always uses the American format #mm/dd/yy#
while in the UK our date is set to #dd/mm/yy#
this is giving me a problem. the records are stored in UK format and
the query is searching in US Format. Is there anyway i can force
access to search my date field in Uk Format and return the correct
records?

thanks
kevin


Nov 13 '05 #6
Tom van Stiphout <no*************@cox.net> wrote in
news:j7********************************@4ax.com:
Dates should be stored in fields with the date/time format, which
is some 8-byte format we don't need to know about.
For presentation reasons, you may need to apply a format, for
example: Format$(MyDateField, "mm/dd/yyyy")


Or use DateSerial().

Or format in an unambiguous format.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #7

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

Similar topics

4
by: Russell | last post by:
I'm having a fit with a query for a range of dates. The dates are being returned from a view. The table/field that they are being selected from stores them as varchar and that same field also...
2
by: BlackFireNova | last post by:
I have an Access 2003 mdb which contains software records. I need to sort on a particular type of software, and then identify and count how many copies there are per each group of that type...
10
by: Kenneth | last post by:
I have a Query that consist of a lot of different sales data, and one of the colums are different date. The date goes from 1jan2003 til 31jan2003. in this Query I only want the salesdata for...
7
by: Nicolae Fieraru | last post by:
Hi All, I have a table tblProducts where I have four fields:\ Index, ProductName, EnterDate (as Date/Time - Medium Date), PurchaseDate (Date/Time - Medium Date) The EnterDate is automatically...
4
by: Peter Bailey | last post by:
I have a vba string taht dynamically creates the query which has two dates in it that it grabs off an open form as a string from the textbox. What I generate in vba is: SELECT DOSMBK.Date,...
12
by: Steve Elliott | last post by:
I have a query set up to gather together data between two specified dates. Shown in the query column as: Between #24/09/2004# And #01/10/2004# Is it possible to enter several different date...
3
by: manning_news | last post by:
Using A2K. I've been asked to modify a report currently requiring only one date parameter to now accept a date range. The main report has 2 subreports and is not bound to a table or query. The...
11
by: Dixie | last post by:
How can I programatically, take some Date/Time fields present in a table in the current database and change their type to text? dixie
10
by: Daniel | last post by:
In Microsoft Access I can write a query that includes the criteria: Between Date()-7 And Date() to retrieve the records from a table that fall within the last week. I'm trying to write a...
2
by: sixdeuce62 | last post by:
Hello, I am trying to create a query that will prompt me to enter the parameter value if beginning date and ending date. I have created everything I need in the query, but I have to manually go...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.