473,396 Members | 2,011 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.

Display Projects by Month

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.
Feb 17 '08 #1
10 1544
markrawlingson
346 Expert 100+
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.

Expand|Select|Wrap|Line Numbers
  1. sSQL = "SELECT * FROM tblProjects WHERE dCompleted BETWEEN 1/1/2008 AND 1/31/2008 OR dCompleted = 1/1/2008 OR dCompleted = 1/31/2008;"
  2.  
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
Feb 18 '08 #2
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.
Feb 18 '08 #3
markrawlingson
346 Expert 100+
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...

Expand|Select|Wrap|Line Numbers
  1. sSQL = "SELECT * FROM tblProjects WHERE dCompleted BETWEEN " & Request.Form("dFrom") & " AND " & Request.Form("dTo") & " OR dCompleted = " & Request.Form("dFrom") & " OR dCompleted = " & Request.Form("dTo")
  2.  
Sincerely,
Mark
Feb 18 '08 #4
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.
Expand|Select|Wrap|Line Numbers
  1. <% 
  2. Dim Conn
  3. Dim strSQL
  4. Dim RS
  5. Dim strFDates
  6. Dim strTDates
  7.  
  8. Dim strCount
  9. strCount=0
  10.  
  11. strFDates         = trim(Request("FDates")) 
  12. strTDates         = trim(Request("TDates"))
  13. strEngineer     = trim(Request("Engineer"))
  14. strWorkType     = trim(Request("WorkType"))
  15.  
  16. Set Conn = Server.CreateObject("ADODB.Connection") 
  17. Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("Database.mdb")& "; Jet OLEDB:Database Password=yourpassword" 
  18.  
  19. strSQL = "SELECT * FROM TableProject WHERE CompleteDate BETWEEN " & strFDates & " AND " & strTDates & " OR CompleteDate = " & strFDates & " OR CompleteDate = " & strTDates & ""
  20.  
  21. RS.Open strSQL, Conn
  22.  
  23. If (RS.EOF) Then 
  24.     Response.Redirect ("SearchReports.asp?error=Sorry ... Please try again.  Thanks.") 
  25. End If 
  26. %>
Feb 21 '08 #5
markrawlingson
346 Expert 100+
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
%>
Feb 21 '08 #6
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.
Feb 21 '08 #7
DrBunchman
979 Expert 512MB
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
Feb 21 '08 #8
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.
Expand|Select|Wrap|Line Numbers
  1. <% 
  2. Dim Conn
  3. Dim strSQL
  4. Dim RS
  5. Dim strFDates
  6. Dim strTDates
  7.  
  8. strFDates         = trim(Request("FDates")) 
  9. strTDates         = trim(Request("TDates"))
  10. strEngineer     = trim(Request("Engineer"))
  11. strWorkType     = trim(Request("WorkType"))
  12.  
  13. Set Conn = Server.CreateObject("ADODB.Connection") 
  14. Set RS = Server.CreateObject("ADODB.RecordSet")
  15.  
  16. Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("Database.mdb")& "; Jet OLEDB:Database Password=yourpassword" 
  17.  
  18. strSQL = "SELECT * FROM TableProject WHERE CompleteDate BETWEEN '" & strFDates & "' AND '" & strTDates & "' OR CompleteDate = '" & strFDates & "' OR CompleteDate = '" & strTDates & "'"
  19.  
  20. RS.Open strSQL, Conn, adOpenStatic, adLockOptimistic, adCmdText
  21.  
  22. If (RS.EOF) Then 
  23.     Response.Redirect ("SearchReports.asp?error=Sorry ... Please try again.  Thanks.") 
  24. End If 
  25. %>
Feb 21 '08 #9
DrBunchman
979 Expert 512MB
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
Feb 21 '08 #10
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.
Expand|Select|Wrap|Line Numbers
  1. 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.
Feb 22 '08 #11

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

Similar topics

2
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...
11
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"...
7
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...
2
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...
0
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...
3
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...
4
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...
3
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...
12
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...
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
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...
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
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...
0
agi2029
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,...

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.