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

Retrieving a range of dates from the Database

I am trying to retrieve dates from the database using a range.
This is the Code I am using which is giving me an error
Expand|Select|Wrap|Line Numbers
  1. Public AdVehDecp As ADODB.Connection
  2. Public RsQry As ADODB.Recordset
  3. Public StrSql As String
  4. Set AdVehDecp = New ADODB.Connection
  5. Set RsQry = New ADODB.Recordset
  6. AdVehDecp.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\VEHICLE_TRACKER.mdb;"
  7. AdVehDecp.Open
  8. AdVehDecp.CursorLocation = adUseClient
  9. StrSql = "SELECT txtVEHNO, dtmVLEXP FROM tblVEHLIC WHERE dtmVLEXP >= #" & IssDt & "# AND dtmVEHEXP <= #" & ExpDt & "#;"
  10.     Set RsQry = AdVehDecp.Execute(StrSql)
  11.  
the error occurs at Set RsQry = AdVehDecp.Execute(StrSql) saying
Run-time error '-2147217904(80040e10)';
No value given for one more required parameter
Jan 4 '07 #1
15 1627
hariharanmca
1,977 1GB
I am trying to retrieve dates from the database using a range.
This is the Code I am using which is giving me an error
Expand|Select|Wrap|Line Numbers
  1. Public AdVehDecp As ADODB.Connection
  2. Public RsQry As ADODB.Recordset
  3. Public StrSql As String
  4. Set AdVehDecp = New ADODB.Connection
  5. Set RsQry = New ADODB.Recordset
  6. AdVehDecp.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\VEHICLE_TRACKER.mdb;"
  7. AdVehDecp.Open
  8. AdVehDecp.CursorLocation = adUseClient
  9. StrSql = "SELECT txtVEHNO, dtmVLEXP FROM tblVEHLIC WHERE dtmVLEXP >= #" & IssDt & "# AND dtmVEHEXP <= #" & ExpDt & "#;"
  10.     Set RsQry = AdVehDecp.Execute(StrSql)
  11.  
the error occurs at Set RsQry = AdVehDecp.Execute(StrSql) saying
Run-time error '-2147217904(80040e10)';
No value given for one more required parameter


Which datatype you are using (String or dateTime) for Date
Jan 4 '07 #2
Killer42
8,435 Expert 8TB
I am trying to retrieve dates from the database using a range.
This is the Code I am using which is giving me an error
Expand|Select|Wrap|Line Numbers
  1. Public AdVehDecp As ADODB.Connection
  2. Public RsQry As ADODB.Recordset
  3. Public StrSql As String
  4. Set AdVehDecp = New ADODB.Connection
  5. Set RsQry = New ADODB.Recordset
  6. AdVehDecp.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\VEHICLE_TRACKER.mdb;"
  7. AdVehDecp.Open
  8. AdVehDecp.CursorLocation = adUseClient
  9. StrSql = "SELECT txtVEHNO, dtmVLEXP FROM tblVEHLIC WHERE dtmVLEXP >= #" & IssDt & "# AND dtmVEHEXP <= #" & ExpDt & "#;"
  10.     Set RsQry = AdVehDecp.Execute(StrSql)
  11.  
the error occurs at Set RsQry = AdVehDecp.Execute(StrSql) saying
Run-time error '-2147217904(80040e10)';
No value given for one more required parameter
At a guess, you might need to enforce mm/dd/yyyy format on the dates you're inserting in the string. What is the data type of IssDt and ExpDt?
Jan 4 '07 #3
hariharanmca
1,977 1GB
At a guess, you might need to enforce mm/dd/yyyy format on the dates you're inserting in the string. What is the data type of IssDt and ExpDt?

No, In Format(value,"mm/dd/yyyy") mm->minute so we have to use Uppercase for Month like Format(dateValue,"MM/dd/yyyy")
Jan 4 '07 #4
Which datatype you are using (String or dateTime) for Date
Its Datatime
Jan 4 '07 #5
At a guess, you might need to enforce mm/dd/yyyy format on the dates you're inserting in the string. What is the data type of IssDt and ExpDt?
the dates have already been formated before being stored.
This is the code for IssDt and ExpDt
Expand|Select|Wrap|Line Numbers
  1. IssDt = Text3(0) + "/" + Text3(1) + "/" + Text3(2)
  2. ExpDt = Text3(3) + "/" + Text3(4) + "/" + Text3(5)
  3. IssDt = Format(IssDt, "DD/MM/YYYY")
  4. ExpDt = Format(ExpDt, "DD/MM/YYYY")
  5.  
Jan 4 '07 #6
hariharanmca
1,977 1GB
Its Datatime

Ok ,
then Just Try this

StrSql = "SELECT txtVEHNO, dtmVLEXP FROM tblVEHLIC WHERE dtmVLEXP >= #" & Format(IssDt,"MM/dd/yyyy") & "# AND
dtmVEHEXP <= #" & Format(ExpDt,"MM/dd/yyyy") & "#;"
Set RsQry = AdVehDecp.Execute(StrSql)
Jan 4 '07 #7
hariharanmca
1,977 1GB
Ok ,
then Just Try this

StrSql = "SELECT txtVEHNO, dtmVLEXP FROM tblVEHLIC WHERE dtmVLEXP >= #" & Format(IssDt,"MM/dd/yyyy") & "# AND
dtmVEHEXP <= #" & Format(ExpDt,"MM/dd/yyyy") & "#;"
Set RsQry = AdVehDecp.Execute(StrSql)
check IssDt and ExpDt are same data Type if it's Not then convert it
CDate(IssDt )
Jan 4 '07 #8
Killer42
8,435 Expert 8TB
check IssDt and ExpDt are same data Type if it's Not then convert it CDate(IssDt )
I think the critical point is simply that your dates must be formatted in U.S. format, with the month first (thanks for catching the minutes thing, hariharanmca).

So, if you are placing them in a string variable, you probably need to use MM/dd/yyyy format then. If it's a date variable, apply the format when inserting it into the SQL. Either way, SQL always expects American format in a #-delimited date literal.
Jan 4 '07 #9
hariharanmca
1,977 1GB
the dates have already been formated before being stored.
This is the code for IssDt and ExpDt
Expand|Select|Wrap|Line Numbers
  1. IssDt = Text3(0) + "/" + Text3(1) + "/" + Text3(2)
  2. ExpDt = Text3(3) + "/" + Text3(4) + "/" + Text3(5)
  3. IssDt = Format(IssDt, "DD/MM/YYYY")
  4. ExpDt = Format(ExpDt, "DD/MM/YYYY")
  5.  

in SQL Server you have to use like this

StrSql = "SELECT txtVEHNO, dtmVLEXP FROM tblVEHLIC WHERE dtmVLEXP >= ' " & Format(IssDt,"MM/dd/yyyy") & " ' AND
dtmVEHEXP <= ' " & Format(ExpDt,"MM/dd/yyyy") & " ' ;"
Set RsQry = AdVehDecp.Execute(StrSql)

in MS access can Execute


StrSql = "SELECT txtVEHNO, dtmVLEXP FROM tblVEHLIC WHERE dtmVLEXP >= #" & Format(IssDt,"MM/dd/yyyy") & "# AND
dtmVEHEXP <= #" & Format(ExpDt,"MM/dd/yyyy") & "#;"
Set RsQry = AdVehDecp.Execute(StrSql)
Jan 4 '07 #10
Killer42
8,435 Expert 8TB
in SQL Server you have to use like this ...
Is the delimiter (# -vs- ') the only difference there?

Anyway, I found the thread I wanted to refer to earlier. See Literal DateTimes and Their Delimiters (#).
Jan 4 '07 #11
hariharanmca
1,977 1GB
Is the delimiter (# -vs- ') the only difference there?

Anyway, I found the thread I wanted to refer to earlier. See Literal DateTimes and Their Delimiters (#).

Yes Sql Server will Consider the date time format into string so we have to use - > '

in MSAccess will have Separate the date/Time and string so we have to use
- > #
Jan 4 '07 #12
Killer42
8,435 Expert 8TB
Yes Sql Server will Consider the date time format into string so we have to use - > '

in MSAccess will have Separate the date/Time and string so we have to use
- > #
Ok, thanks. I'll try to remember that. (I'll bet it's in that post from NeoPa that I referred to - I probably should read it. :o)
Jan 4 '07 #13
[RESOLVED]
The issue has been resolved by changing
Expand|Select|Wrap|Line Numbers
  1. StrSql = "SELECT txtVEHNO, dtmVLEXP FROM tblVEHLIC WHERE dtmVLEXP >= #" & IssDt & "# AND 
  2. dtmVEHEXP <= #" & ExpDt & "#;"
  3.     Set RsQry = AdVehDecp.Execute(StrSql)
  4.  
to

Expand|Select|Wrap|Line Numbers
  1. RsQry.Open "SELECT txtVEHNO, dtmVLEXP FROM tblVEHLIC WHERE dtmVLEXP >= #" & IssDt & "# AND 
  2. dtmVLEXP <= #" & ExpDt & "#;", AdVehDecp, adOpenDynamic, adLockPessimistic
  3.  
Jan 4 '07 #14
hariharanmca
1,977 1GB
[RESOLVED]
The issue has been resolved by changing
Expand|Select|Wrap|Line Numbers
  1. StrSql = "SELECT txtVEHNO, dtmVLEXP FROM tblVEHLIC WHERE dtmVLEXP >= #" & IssDt & "# AND 
  2. dtmVEHEXP <= #" & ExpDt & "#;"
  3.     Set RsQry = AdVehDecp.Execute(StrSql)
  4.  
to

Expand|Select|Wrap|Line Numbers
  1. RsQry.Open "SELECT txtVEHNO, dtmVLEXP FROM tblVEHLIC WHERE dtmVLEXP >= #" & IssDt & "# AND 
  2. dtmVLEXP <= #" & ExpDt & "#;", AdVehDecp, adOpenDynamic, adLockPessimistic
  3.  

that's good,

this kind of problem is Difficult to answer if you don't send proper explanation
Jan 4 '07 #15
Killer42
8,435 Expert 8TB
The issue has been resolved by changing ...
So correct me if I'm wrong here - what changed was not the SQL or the date format, but going from Execute to Open? Just want to check that I'm clear on what the resolution was.
Jan 4 '07 #16

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

Similar topics

4
by: Jorey Bump | last post by:
I can retrieve today's date: mysql> SELECT CURDATE() AS begin; +------------+ | begin | +------------+ | 2005-06-01 | +------------+ 1 row in set (0.00 sec)
5
by: Dennis M. Marks | last post by:
After reading section 15.9.1.1 the ECMAScript Language Specifications I see that the date range for the Date function is +/- 100,000,000 days from 01 Jan 1970. This is called an extrapolated...
24
by: PromisedOyster | last post by:
Is there a way that I can get a resultset that contains unique dates in a given date range without the need to have a temporary table and a cursor? perhaps something like: declare @start_date...
4
by: Mark | last post by:
Hi I have been trying to convert the week number to a range of dates that I can use. It should be fairly simple for you guru's out there but for us mere mortals it is beyond our grasp. I know...
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...
7
by: tfsmag | last post by:
Okay, i have a datagrid that I want to populate with invoices that are due on the month shown on the calendar, so what i need to do is retrieve the current 'shown' month and create a couple of...
3
by: jen2007 | last post by:
I have several ranges of dates (2007-03-15 - 2007-03-21, format YYYY,MM,DD) and I need to list all of the dates in the range and not sure how to do this. I wrote an OnLoad procedure that should run...
3
by: Matt Brown - identify | last post by:
Hello, I'm trying to figure out a method to look up by a range of dates, entries in a database. The format of the date in the database is "M\D \yyyy HH:MM:SS". What i need to do is take the...
2
by: =?Utf-8?B?U2FpbXZw?= | last post by:
Hi and Hello. Good Day. I have a problem in retrieving time in database. I have Table name "SAMPLE" and have field name "DATES" DATES -------------------------------------| 5/9/2008...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
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...

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.