473,396 Members | 1,987 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.

objRS.Filter problem

I am trying to create an events calendar with a complete month view. I
want to be able to get all the events for a particular month, using only
one recordset on the page then be able to loop through each day of that
month and output the events for a particular day for each day without
having to open up 28 to 31 different recordsets.

The problem that I am having is with the objRS.Filter on line #12 of the
asp code below. I can not figure out how to write it so that it finds
events like "Event 4", in the *** SQL SERVER RESULTS ***, which is an
event that spans multiple days, so it should appear on the calendar on
the following days: 11, 12, 13, 14, 15. As the objRS.Filter is written
now the event will only appear on the 11th and the 15th. Another problem
I see with the way the filter is that events like "Event 7" will not
appear properly on the calendar. Event 7 starts on May 29th and ends on
June 3, so how do I tell the filter to ignore May 3 and just display
records for the 29th, 30th and 31st?

=========================
Here is my SQL Statement:
=========================
SELECT EventId, dtStartDate, dtEndDate, datepart(d, dtStartDate) as
nDayStart, datepart(d, dtEndDate) as nDayEnd, EventTitle
FROM Events
WHERE (dtStartDate BETWEEN '5/1/2005' AND '5/31/2005') or (dtEndDate
BETWEEN '5/1/2005' AND '5/31/2005')
ORDER BY datepart(d, dtStartDate), datepart(d, dtEndDate),
CAST(dtStartTime as smalldatetime);
**** SQL SERVER RESULTS ****

EventId dtDate dtEndDate nDayStart
nDayEnd EventTitle
-------- ---------------------- --------------------- ----------
-------- -----------
134 2005-05-05 00:00:00 2005-05-05 00:00:00 5 5
Event 1
207 2005-05-07 00:00:00 2005-05-07 00:00:00 7 7
Event 2
163 2005-05-10 00:00:00 2005-05-10 00:00:00 10 10
Event 3
172 2005-05-11 00:00:00 2005-05-15 00:00:00 11 15
Event 4
185 2005-05-12 00:00:00 2005-05-12 00:00:00 12 12
Event 5
152 2005-05-25 00:00:00 2005-05-25 00:00:00 25 25
Event 6
120 2005-05-29 00:00:00 2005-06-03 00:00:00 29 3
Event 7

(7 row(s) affected)
=========================
Here is my ASP Statement
that builds the month view
of the calendar:
=========================
dtDate = Now()

1. set objRS = objConn.execute(strSQL)
2. do until (Month(dtDate) <> CInt(nMonth))
3. if Weekday(dtDate) = 1 or Weekday(dtDate) = 7 then
4. 'Sunday or Saturday so color them differently than the regular
weekdays
5. Response.Write "<td width='" & CellWidth & "' class='weekenddays'
valign='top'>"
6. else 'weekday
7. Response.Write "<td width='" & CellWidth & "' class='days'
valign='top'>"
8. end if
9. Response.Write "<font class='daynumbers'><b>"& Day(dtDate) &
"</b></font><br>"
10.
11. if not objRS.EOF then
12. objRS.Filter = "(nDay = " & DatePart("d", dtDate) & ") OR
(nDayEnd = " & DatePart("d", dtDate) & ")"
13.
14. if not objRS.EOF then
15. do while not objRS.EOF
16. Response.Write "<a href='" & SiteURL &
"/events.asp?EventId=" & objRS("EventId") & "&nDate=" &
server.urlencode(month(dtDate) & "/" & day(dtDate) & "/" & year(dtDate))
& "' class='CalEventLinks'>" & revnewstr(objRS("EventTitle")) &
"</a><br><br>"
17. objRS.MoveNext
18. loop
19. else
20. response.write("<img src='" & SiteURL & "/images/spacer.gif'
height='50' width='25' border=0>")
21. end if
22. objRS.Filter = ""
23. else
24. response.write("<img src='" & SiteURL & "/images/spacer.gif'
height='50' width='25' border=0>")
25. end if
26.
27. Response.Write "</td>" & vbCR
28.
29. if WeekDay(dtDate) = 7 then
30. Response.Write "</tr>" & vbCrLf & vbCRLF & "<tr>"
31. end if
32. 'add one day for next time around in loop
33. dtDate = DateAdd("d", 1, dtDate)
34. dtFullDate = DateAdd("d", 1, dtFullDate)
35. loop
36. objRS.close
37. Set objRS = Nothing

Any input is greatly appreciate!

Thanks,

Ed

*** Sent via Developersdex http://www.developersdex.com ***
Jul 22 '05 #1
1 2369
Edward Burns wrote:
I am trying to create an events calendar with a complete month view. I
want to be able to get all the events for a particular month, using
only one recordset on the page then be able to loop through each day
of that month and output the events for a particular day for each day
without having to open up 28 to 31 different recordsets.


First of all, create and populate a Calendar table:

create table Calendar
(calDate datetime primary key clustered)
declare @i int
set @i = 1
while @i < 366
begin
insert into calendar values (dateadd(d,@i,'20041231'))
set @i = @i + 1
end

You will find other uses for this table, believe me (such as adding a column
to indicate whether or not the day is a working day, or a column to indicate
the week_of_month number, in the case of a fiscal period calendar).

Then, generate the events for the month:

select caldate,datepart(dw,caldate) DayOfWeek,
eventid,eventtitle
from events e right join calendar c
on c.caldate between e.dtStartdate and e.dtEndDate
where caldate between '20050501' and '20050531'
order by caldate, eventid

Looping through these results should be a little easier for you. I don't
really have time to analyze your code to figure out how you want the results
to look, so i can't get too specific here.

Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: CSDunn | last post by:
Hello, I have a problem with field filtering between an Access 2000 Project form (the application is called CELDT), and the report that shows the results of the filter. Both the form and the...
3
by: Richard | last post by:
Hi, I have a form based on a table. When I filter the form I want to run a report based on the same table with the same filter as the form. No problem until I want to filter a combo box where...
2
by: Salad | last post by:
I have a log file with a list of records. The log file can be unfiltered or filtered. I have a command button to call a data entry form from the log. At first I was only going to present the...
2
by: Mike Sweetman | last post by:
I have a form Form1 which when the Advanced Filter/Sort is used creates a form(maybe) with a title 'Form1Filter1 : Filter'. When I apply the filter to Form1 it is applied, but the value of...
2
by: Lenin Torres | last post by:
Hi everybody I have an Union Query that works fine. I used this query as the RecordSource for a Form. That Form is used as a subform in another form. Everything works fine, except for the "Filter...
3
by: Brad | last post by:
I have a response filter which injects "standard" html into my pages. The filter works fine when the initial stream is small enough not to buffer...or....if I have a large unbuffered stream (i.e. I...
1
by: new214 | last post by:
Hey all, got abit of a problem. Ive got a database where ive got 2 tables. I want to create a command which selects * from table 1 and if the same values are in table2 - it updates otherwise adds. ...
6
by: bammo | last post by:
MS Access 2003, Windows XP SP2, VBA I have a continuous form that allows edits and filters, but not deletions or additions. I filter the form based on combining selections the user makes in...
2
by: Matthew Wells | last post by:
Hi there. I am a programmer for a living, but this problem has my whole team stumped. I have a subform based on a query. I'm not using the "LinkMaster/ChildFields" properties ( I have my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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.