Hi All,
I am not trying to convert ASP to MS Access style but I used to have a MS Access database that will query completed projects (not NULL), by month. Let's say, if I click on the query, I have to enter the begining of the month such as 1/1/2008 and the end of the month 1/31/2008 and it will give me a list of projects completed within the month of January.
Can someone please advise if this is a DOABLE feature using ASP? Thanks for your help.
10 1544
This is doable.
For this I would have a field in the database table, called dCompleted which will represent the date the project was completed.
The second part focuses on the SQL query itself using the BETWEEN keyword. -
sSQL = "SELECT * FROM tblProjects WHERE dCompleted BETWEEN 1/1/2008 AND 1/31/2008 OR dCompleted = 1/1/2008 OR dCompleted = 1/31/2008;"
-
This will return all records where the date the project was completed is between the 1st and 31st of the month of January 2008.
Note the "OR dCompleted = 1/1/2008 OR dCompleted = 1/31/2008" - this is a fix because the SQL BETWEEN keyword will only return records literally BETWEEN the two values. So in the above example "BETWEEN 1/1/2008 AND 1/31/2008" records with a value of 1/1/2008 or 1/31/2008 will not be returned.
Hope this helps.
Sincerely,
Mark
Hi Mark,
Thanks for your outstanding support. Question for you. I guess instead of using the FIXED month as listed above I can ENTER the month (example: field A for begining of the month and field B for the end of the month) that I want? Thanks.
Yep.
I have two calender controls on one of the sites I work with that does just this. It's a tool so people can refine their search to results that were posted between 2 dates. EG: Search for posts from [date] to [date]
Just modify the code replacing the fixed 'fake' dates I put in with the information coming from your form submission... -
sSQL = "SELECT * FROM tblProjects WHERE dCompleted BETWEEN " & Request.Form("dFrom") & " AND " & Request.Form("dTo") & " OR dCompleted = " & Request.Form("dFrom") & " OR dCompleted = " & Request.Form("dTo")
-
Sincerely,
Mark
Hi Mark,
Can you please tell me if you see an issue with the following code? Keep getting Microsoft VBScript runtime error '800a01a8'
Object required: ''
Please note that CompleteDate is a Text field in the MS Access Database.
Thanks once again for your outstanding support. - <%
-
Dim Conn
-
Dim strSQL
-
Dim RS
-
Dim strFDates
-
Dim strTDates
-
-
Dim strCount
-
strCount=0
-
-
strFDates = trim(Request("FDates"))
-
strTDates = trim(Request("TDates"))
-
strEngineer = trim(Request("Engineer"))
-
strWorkType = trim(Request("WorkType"))
-
-
Set Conn = Server.CreateObject("ADODB.Connection")
-
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("Database.mdb")& "; Jet OLEDB:Database Password=yourpassword"
-
-
strSQL = "SELECT * FROM TableProject WHERE CompleteDate BETWEEN " & strFDates & " AND " & strTDates & " OR CompleteDate = " & strFDates & " OR CompleteDate = " & strTDates & ""
-
-
RS.Open strSQL, Conn
-
-
If (RS.EOF) Then
-
Response.Redirect ("SearchReports.asp?error=Sorry ... Please try again. Thanks.")
-
End If
-
%>
Hmmm, that could be a problem. I'm not sure how the BETWEEN keyword works on strings, I wouldn't imagine it will at all :P
Why are you entering a date into a text field? This is really bad practice, I would strongly advice you to use the data types according to the type of information that will be inserted into them.
You need to wrap single quotes around any data that you pass through a text field in your database. So start with your SQL statement, but if that doesn't work I would also advise throwing in some ADO constants when you open your recordset..
RS.Open strSQL, Conn, adOpenStatic, adLockOptimistic, adCmdText
OR
RS.Open strSQL, Conn, 3, 3 (If you don't have the ado constants defined anywhere.)
I would advise you to use ado constants though rather than the numbers. The numbers might look easier to type but - what do they mean? :P
Give that a shot, but if the between keyword works at all on text input - it will probably act eradically. If that's the case, change the field to datetime and see how the code works.
Also, whenever you get an error it's very difficult to diagnose unless we know the line which is throwing the error - so please identify the line which is throwing the error in the future, so that we can assist you better.
Sincerely,
Mark
Hi Mark,
Can you please tell me if you see an issue with the following code? Keep getting Microsoft VBScript runtime error '800a01a8'
Object required: ''
Please note that CompleteDate is a Text field in the MS Access Database.
Thanks once again for your outstanding support.
<%
Dim Conn
Dim strSQL
Dim RS
Dim strFDates
Dim strTDates
Dim strCount
strCount=0
strFDates = trim(Request("FDates"))
strTDates = trim(Request("TDates"))
strEngineer = trim(Request("Engineer"))
strWorkType = trim(Request("WorkType"))
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("Database.mdb")& "; Jet OLEDB:Database Password=yourpassword"
strSQL = "SELECT * FROM TableProject WHERE CompleteDate BETWEEN " & strFDates & " AND " & strTDates & " OR CompleteDate = " & strFDates & " OR CompleteDate = " & strTDates & ""
RS.Open strSQL, Conn
If (RS.EOF) Then
Response.Redirect ("SearchReports.asp?error=Sorry ... Please try again. Thanks.")
End If
%>
Hi Mark,
Thanks for your quick response. I changed the CompleteDate in the MS Access database to DateTime. Put single quote (') around like
strSQL = "SELECT * FROM TableProject WHERE CompleteDate BETWEEN '" & strFDates & "' AND '" & strTDates & "' OR CompleteDate = '" & strFDates & "' OR CompleteDate = '" & strTDates & "'"
GOT an ERROR on the line below:
Microsoft VBScript runtime error '800a01a8'
Object required: ''
RS.Open strSQL, Conn, adOpenStatic, adLockOptimistic, adCmdText
Hope this helps and thanks once again for your help sir.
Hi Hotflash,
Have you actually created your recordset object? I can't see this line in your code anywhere:
Set RS = Server.CreateObject("ADODB.RecordSet")
Try putting that line in before you open your recordset.
Hope this helps,
Dr B
Hi Dr. B,
I did what you recommended and getting the following here.
Below is the code that I currently trying.
ADODB.Recordset error '800a0bb9'
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
/Reports/DisplayReports.asp, line 23
The line 23 here is RS.Open strSQL, Conn, adOpenStatic, adLockOptimistic, adCmdText.
Any other recommendations? Thanks once again for your help. - <%
-
Dim Conn
-
Dim strSQL
-
Dim RS
-
Dim strFDates
-
Dim strTDates
-
-
strFDates = trim(Request("FDates"))
-
strTDates = trim(Request("TDates"))
-
strEngineer = trim(Request("Engineer"))
-
strWorkType = trim(Request("WorkType"))
-
-
Set Conn = Server.CreateObject("ADODB.Connection")
-
Set RS = Server.CreateObject("ADODB.RecordSet")
-
-
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("Database.mdb")& "; Jet OLEDB:Database Password=yourpassword"
-
-
strSQL = "SELECT * FROM TableProject WHERE CompleteDate BETWEEN '" & strFDates & "' AND '" & strTDates & "' OR CompleteDate = '" & strFDates & "' OR CompleteDate = '" & strTDates & "'"
-
-
RS.Open strSQL, Conn, adOpenStatic, adLockOptimistic, adCmdText
-
-
If (RS.EOF) Then
-
Response.Redirect ("SearchReports.asp?error=Sorry ... Please try again. Thanks.")
-
End If
-
%>
The reason for the error is you haven't defined the ADO constants that you are using (adOpenStatic, adLockOptimistic, adCmdText) anywhere.
These constants are defined in the file adovbs.inc which you need to include in your page. There is an excellent tutorial here: http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=123
For the time being though I suggest you replace the line
RS.Open strSQL, Conn, adOpenStatic, adLockOptimistic, adCmdText
with this one
RS.Open strSQL, Conn, 3, 3
as MarkRawlingson suggested earlier in this thread. Give that a try and it should stop your page from erroring.
Let us know how you get on.
Dr B
NeoPa 32,556
Expert Mod 16PB
...
Note the "OR dCompleted = 1/1/2008 OR dCompleted = 1/31/2008" - this is a fix because the SQL BETWEEN keyword will only return records literally BETWEEN the two values. So in the above example "BETWEEN 1/1/2008 AND 1/31/2008" records with a value of 1/1/2008 or 1/31/2008 will not be returned.
I think there must be some confusion here Mark. SQL "X Between A And B returns records with values of X such that A <= X <= B.
Dates can sometimes be confusing as they sometimes have time elements within them - giving the impression that they're actually equal to the upper limit in a Between construct, whereas they are actually above it.
Assume today is 22 Feb 2008. - WHERE [DateField] Between #2/1/2008# And #2/22/2008#
fails to return records for today if the field is populated using Now() as the date (and time) is actually greater than the date literal.
PS. HotFlash, please remember to use the [ CODE ] tags provided (the # button). You're a regular visitor and we should be able to expect you to follow the posting guidelines.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Simon Wigzell |
last post by:
My client has an annual calendar of events consisting of a record for each
event, key field is the event date saved as a date type field. They would
like the display to start with the current...
|
by: Jim |
last post by:
I have been using the javascript below on a web page since last August to
show the "Site updated" month only minus a month, which has been very
successful, but January is showing a "undefined 2004"...
|
by: DavidM |
last post by:
Hello -- I would like to display a different logo on my website for
different seasons of the month.
I currently have a logo for Halloween, Thanksgiving, and December.
Can someone tell me what...
|
by: bb |
last post by:
any way to prevent displaying the previous and next months in the
calendar control?
i have tried just blanking the text out in the dayrender IsOtherMonth
and also dynamically changing the...
|
by: M. David Johnson |
last post by:
I cannot get my OleDbDataAdapter to update my database
table from my local dataset table. The Knowledge Base
doesn't seem to help - see item 10 below.
I have a Microsoft Access 2000 database...
|
by: remya1000 |
last post by:
i'm using ASP with MSAccess as database.
i have two buttons and two textbox in my page.
when i press my first button (First month) i need to display the current month in one textbox and last one...
|
by: abstractj |
last post by:
I found the below script that will display an image based on certain date. I would like to add an additional function that will display the images when it is referred by a certain URL. IE. if users...
|
by: JCCDEVEL |
last post by:
Hello,
I'm writing a basic query in Sql Server Mgmt Studio 2005. Basically, I'm trying to query a table to get all "issues" reported in a month by "Project Category". The query is working fine...
|
by: petter |
last post by:
Hi!
I have two questions: one question that regards the COUNT-function, and one about how to display a month even if I don’t have any data for that month.
I have an Access database where I want...
|
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...
|
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
|
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...
|
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: 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...
|
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: 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: 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: 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,...
| |