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

Data out of range error

3
I have a VB6 project with sql 2000 DB.Problem is when trying to run a report and i get this error "Conversion of a char data type resulted in an out-of-range datetime value"
How do i fix this error.Here is the code:(where code is in bold is where the error is)

Private Sub cmdEnter_Click()
Dim startdate As Date
Dim enddate As Date
Dim vehicle As String
Dim travelled_km As Integer

startdate = CDate(mskStartDate.Text)
enddate = CDate(mskEndDate.Text)
vehicle_reg = cbovehicle_reg.Text
serviceprovided = "fuel"
travelled_km = 0

If CDate(mskEndDate) > Date Then
MsgBox "PLEASE ENTER VALID END DATE", vbCritical
mskEndDate.SetFocus
Exit Sub

End If
Set rsFuel = New ADODB.Recordset
rsFuel.Open "select * from Logsheet where vehicle_reg ='" & cbovehicle_reg.Text & "'and date >=CDATE('" & startdate & "')and date <= CDATE('" & enddate & "')", cnConnect, adOpenDynamic, adLockOptimistic
If Not rsFuel.BOF Then
rsFuel.MoveFirst
End If

Do While Not rsFuel.EOF
travelled_km = travelled_km + rsFuel!travelled_km
rsFuel.MoveNext
Loop


DataEnvironment1.cmdFuelUsage startdate, enddate, vehicle_reg, serviceprovided
With rptFuelUsage
.Sections("Section4").Controls("lblreportheader"). Caption = " From " & " " & startdate & " " & " To " & enddate
.Sections("Section4").Controls("lblvehiclereg").Ca ption = cbovehicle_reg.Text
.Sections("Section5").Controls("lbltravelled_km"). Caption = travelled_km

End With

rptFuelUsage.Show
Unload DataEnvironment1
cbovehicle_reg = " "
Dec 14 '06 #1
3 2704
iburyak
1,017 Expert 512MB
Try to replace highlighted code with this:

[PHP]
rsFuel.Open "select * from Logsheet where vehicle_reg ='" & cbovehicle_reg.Text & "'and date >=convert(datetime,'" & startdate & "')and date <= convert(datetime,'" & enddate & "')", cnConnect, adOpenDynamic, adLockOptimistic
[/PHP]
Dec 14 '06 #2
cyberdwarf
218 Expert 100+
Hi Touch


Don't know if your problem has been solved yet, but...

If not, there may be a problem with the way SQL Server is translating your dates. I have seen this type of error when SQL sees dates as MM/DD/YY, then encounters a date like '31/01/06'.

HTH


Steve
Dec 15 '06 #3
iburyak
1,017 Expert 512MB
He has CDATE('date_here') inside SQL statement which is not MS SQL function he should use CONVERT(datetime, date_here') instead.
Dec 15 '06 #4

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

Similar topics

5
by: Jonny | last post by:
Hello, I have created a button on my form which when pressed does the following : 1) Run a pre-defined Macro, which is picking up a query and running my data to excel. However, I need the...
8
by: WindAndWaves | last post by:
Hi Gurus I have a query that contains reference to the following function: Public Function UserStatus() As Byte Const ProEro = 1: 'on error GoTo ERR '--- UserStatus = Nz(DLookup("", "", "!="...
9
by: Bob | last post by:
I have a sql command with a SearchDate parameter of type date. When I execute its stored procedure from Query Analyzer (to SS2K) with a date out of the valid datetime range, EXEC @SearchDate =...
11
by: bbasberg | last post by:
Hello, I have been struggling with this problem for DAYS and have googled my heart out as well as reading any books I could get my hands on but I cannot find any specific references to my problem....
7
by: semijoyful | last post by:
OS: Win XP SP2 Access version: 2003 Excel version: 2003 I am new at this, as I am sure you have gathered from this post title:) I am working on a form where users can input data in Access and...
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:
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: 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:
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.