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

displaying record between two dates errors

Good Day Everyone,

Requesting for your expertise please, in my program the user has to enter the agent name and the from date and to date inorder to display the record. I have to use 2 conditions. First look for the record with the same agent and display all record for that agent but the date should be within the two dates enter. Below are my codes, when running i got the error message invalid data type.
In my database the PROD_ENTERED is date/time format and in the asp code i put a 2 text box where the use has to enter the 2 dates.

please help me. im not really good in asp i'm just a beginner.

thank you for any help or idea you can give.

********************************************

Set oCon = Server.CreateObject ("ADODB.Connection")
oCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("webprs_db.mdb") & ";"

Set Rec = Server.CreateObject ("ADODB.Recordset")


search = request.querystring("search")
agent = request.form("listagent")
fdate = request.form("txtfdate")
tdate = request.form("txttdate")


if agent <> "" then

SQL = "SELECT * FROM WEB_PRODUCTIVITYDONE WHERE PROD_USER like '%" & agent & "%' AND PROD_ENTERED BETWEEN '%" & fdate & "%' AND '%" & tdate & "%'"


else


SQL = "SELECT * FROM WEB_PRODUCTIVITYDONE ORDER BY " & sort
End if
Rec.Open SQL, oCon

if Rec.EOF OR Rec.BOF Then
response.write "<br><br>"

response.write "<p align=center><b>No Records Found ... </b></p>"

end if


Do While Not Rec.EOF
'AND DisplayNum < 5
r = n Mod 2
if r <> 0 then
'rowBColor = "#99CCFF"
rowBColor = "white"
else
'rowBColor = "#CCFFFF"
rowBColor = "#FFFFFF"
end if

If Rec("PROD_DATE") < Date-3 then
rowColor = "Red"
else If Rec("PROD_DATE") < Now()-2 then
rowColor = "Blue"
else
rowColor = "Green"
end if
end if

response.write("<tr>")
response.write("<td bgcolor="& rowBColor&">" & Rec("PROD_RECNO")& "</td>")
response.write("<td bgcolor="& rowBColor&">" & Rec("PROD_USER") & "</td>")
response.write("<td bgcolor="& rowBColor&">" & Rec("PROD_SENDER") & "</td>")
response.write("<td bgcolor="& rowBColor&">" & Rec("PROD_SENDERNAME") & "</td>")
response.write("<td bgcolor="& rowBColor&">" & Rec("PROD_REFDETAILS") & "</td>")
response.write("<td bgcolor="& rowBColor&">" & Rec("PROD_CONCERN") & "</td>")
response.write("<td bgcolor="& rowBColor&">" & Rec("PROD_DATE") & "</td>")
response.write("<td bgcolor="& rowBColor&">" & Rec("PROD_ENTERED") & "</td>")
response.write("<td bgcolor="& rowBColor&">" & "<a href=""prs_viewrec.asp?recnum=" & Rec("PROD_RECNO") & "&user="& rec("PROD_USER") &""">" & "<p align=center>" & " View " & "</td>")
Oct 7 '08 #1
8 4243
ck9663
2,878 Expert 2GB
Display the value of your variable SQL and see how your query looks like.I think the reason is your percent sign on your min and max value of your BETWEEN operator. Although SQL Server will explicitly convert the value of your textbox value to datetime/smalldatetime (depending on PROD_ENTERED's data type), the percent sign will give you a problem. Check the value of SQL anyway.

-- CK
Oct 7 '08 #2
may SQL is just

Dim SQL, tdate, fdate

On may access DB PROD_entered is date/time type.

How should declared the variable? please help and thank you
Oct 8 '08 #3
Use this:

SQL = String.Format(“SELECT * FROM WEB_PRODUCTIVITYDONE
WHERE PROD_USER like '%{0}%’
AND PROD_ENTERED BETWEEN '%{1}%’ AND ‘%{2}%’”, agent, fdate, tdate)
Oct 8 '08 #4
thank for the help but still i got and error.
Error Type:
Microsoft VBScript compilation (0x800A0408)
Invalid character
/prs/search_details.asp, line 91, column 20
SQL = String.Format(“SELECT * FROM WEB_PRODUCTIVITYDONE WHERE PROD_USER like '%{0}%’ AND PROD_ENTERED BETWEEN '%{1}%’ AND ‘%{2}%’”, sagent, fdate, tdate)
***********************
I really new on asp. if possible could you provide me a complete working script for asp that the user need to enter the agent name then enter the start date and end date and click search. aftet this it will seach the MSAccess database to display all the records for that agent between the two dates. just a simple plain codes, no need for designed justa a simple code. thank you very much God Bless and more power.

If not possible to post here please email me at rjlorenzo@yahoo.com

thank you
Oct 10 '08 #5
ck9663
2,878 Expert 2GB
Did you try asking the guys in VB or Access Forum?

Anyway, I'm not an expert with VB but I think single quote means comments. So I don't know how it will affect your string variable. Did you managed to display the value of your SQL variable? If you can display it, it means it's a valid string. Copy that string and paste it on your Access query builder and see if it returns any result set.

-- CK
Oct 10 '08 #6
thank you very much to all, i'm now able to run the query, see below.

SQL = "SELECT * FROM WEB_PRODUCTIVITYDONE WHERE PROD_USER like '%" & sagent & "%' AND PROD_ENTERED between #" & fdate & "# and #" & tdate & "#;"

the problem now is for example, i entered aug 1, 2008 and aug 3, 2008 then it only show the data for aug 1 and aug 2. what i need is to displayed aug 1 to 3. Because i'm using BETWEEN it only show aug 1 and aug 2. Is there any way i could solved it.

thank you
RJ
Oct 11 '08 #7
Delerna
1,134 Expert 1GB
add 1 to tdate before using it for the query

Expand|Select|Wrap|Line Numbers
  1. tdate=cdate(tdate)+1
  2.  
Oct 11 '08 #8
Thank you friend, Its work very well now.

Your the Man!

God Bless to All
Oct 12 '08 #9

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

Similar topics

1
by: Tim Graichen | last post by:
Good morning, I have a sub-form that displays records from a table as a continuous form. The table has several hundred records, but the subform only displays five or six records. The records do...
4
by: Joe User | last post by:
Hi all....I have a feeling this is going to be one of those twisted query questions, but here it goes anyways.... I want to generate a report that shows the chronology of events (represented by...
8
by: Mark | last post by:
When my form goes to a new record, I have a procedure that copies the last record added to the form's underlying table into the form. The intent is that a series of new records may have the same...
3
by: Lyn | last post by:
I need some guidance for a technique that will allow me to accomplish the following... I have a table in which each record contains a photograph. I would like to display in a form a thumbnail...
5
by: Helen | last post by:
Hi I'm using ASP.NET's standard validators to display error messages when people don't fill in required fields on my form. The error messages currently show as soon as the form is loaded, but...
9
by: Bosconian | last post by:
I must be having a brain freeze because I can't figure out how to display dates older than 1970. I have birth dates stored in MySQL as "date" data types (exp. 1955-04-06). I'd like to display as...
3
by: samdev | last post by:
I have a table that contains records that provide the following info: vehicle type route # start time travel time end time I need to display info for all records in a query and/or report...
5
by: sejal17 | last post by:
hello everyone, I have a problem with displaying records between two dates.Below is my designing page: start date: combobox of month(smonth) & combobox of year(syear) end date :...
9
by: LayneMitch via WebmasterKB.com | last post by:
Hello. Got another one for you folks. I'm working on this problem that wants me to 1. Prompt for name 2. Use pop-up box with name 3. Display current date on page in format "October 30, 2000."...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.