NEExt
09-08-2004, 04:27 PM
I will try to keep this succinct, yet still explain the problem.
I was charged with approving OCT NOV and DEC vacation days for 160 people based on requested day off and seniority. Basically, the oldest person here gets the day off. No problem. I write an Access database and set up a query that does it fine.
I decide to port the lookup aspect of it to the web so that I can show off whiling honing my virtually non-existant ASP skills. I've accomplished alot, and the script works nicely (even though its ugly) - but the problem is (i think - I'm still not sure) that I have rs.movenext in the inner loop, so that it hits the EOF and gives an exception error. I cannot figure out how to rewrite my loops which work exactly like I want in every other respect.
<%
Dim adoCon, rs, strSQL, strSQL2
Dim i, style
Dim strDate
dim pctOff
Set adoCon = Server.CreateObject("ADODB.connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("fpdb/leave.mdb")
Set rs = Server.CreateObject("ADODB.Recordset")
strSQL2 = "SELECT vacation.day_off, vacation.status, e_info.e_name, e_info.e_email, e_info.e_eod, e_info.stop, m_info.m_name, m_info.m_phone, m_info.m_email FROM (m_info RIGHT JOIN e_info ON m_info.stop = e_info.stop) RIGHT JOIN vacation ON e_info.e_seid = vacation.e_seid WHERE (((vacation.day_off) = # 01/05/2005 #)) ORDER BY vacation.day_off, e_info.e_eod;"
rs.CursorType = 2
rs.LockType = 3
rs.Open strSQL2, adoCon
i = "0"
strDate = "9/30/2004"
intStaffing = 160
Response.Write ("<div align='center'>")
Response.Write ("<h1>Requests for 10/01/2004 through 01/07/2005</h1>")
Response.Write ("<h2>Rows in yellow are approved leave")
Response.Write (" ")
Do While not rs.EOF 'outer loop
if strDate = rs("day_off") then 'Done so days with no one scheduled off will not show
Response.Write ("<h2>" & rs("day_off") & "</h2>")
Response.Write ("<table align='center' border='1' width='75%'><tr><th>Number</th><th>Employee</th><th>Eod</th><th>Stop</th><th>Manager</th><th>Phone</th></tr>")
Do While rs("day_off") = strDate 'populates the table for a particular day
if strDate = "12/27/2004" then 'different percentages allowed for certain days
pctOff = .7
Elseif strDate = "12/28/2004" then
pctOff = .7
Elseif strDate = "12/29/2004" then
pctOff = .7
Elseif strDate = "12/30/2004" then
pctOff = .7
Elseif strDate = "11/22/2004" then
pctOff = .3
Elseif strDate = "11/23/2004" then
pctOff = .4
Elseif strDate = "11/24/2004" then
pctOff = .6
elseif strDate = "11/26/2004" then
pctOff = .6
elseif strDate = "12/20/2004" then
pctOff = .55
elseif strDate = "12/21/2004" then
pctOff = .6
elseif strDate = "12/22/2004" then
pctOff = .6
elseif strDate = "12/23/2004" then
pctOff = .75
end if
i = i + 1
if i > (intStaffing * pctOff) then 'if to set style and approved/not approved flag in DB
style = "white;"
approved = False
end if
Response.Write ("<tr style='background-color:" & style & "'>" & "<td align='left'>" & i & "</td>")
Response.Write ("<td><a href='mailto:" & rs("e_email") & "'>" & rs("e_name") & "</a>" & "</td>")
Response.Write ("<td>" & rs("e_eod") & "</td>")
Response.Write ("<td>" & rs("stop") & "</td>")
Response.Write ("<td><a href='mailto:" & rs("m_email") & "'>" & rs("m_name") & "</a>" & "</td>")
Response.Write ("<td>" & rs("m_phone") & "</td></tr>")
if approved = true then 'updates DB with approved or not approved
rs.FIELDS("status") = True
Else
rs.FIELDS("status") = False
End if
rs.movenext ' this is where the problem is
Loop
Response.Write ("</table><br>")
Response.Write ("<h3>" & 160*pctOff & " CRs can be allowed off on this day</h3><hr><hr>")
end if
'Reset all inner loop variables
i = "0"
style = "yellow;"
approved = True
pctOff = .1
strDate = DateAdd("d",1,strDate)
Loop
rs.Close
Set rs = Nothing
Set adoCon = Nothing
%>
I apologize for the messy code, I'm pretty new at this and it is a complex project for me. And lastly, this is just a page that only *I* have access to. When I push this out, I will build seperate pages for employee access - ones that DON'T update the DB.
Thank you for any help you can provide.
-NEExt
I was charged with approving OCT NOV and DEC vacation days for 160 people based on requested day off and seniority. Basically, the oldest person here gets the day off. No problem. I write an Access database and set up a query that does it fine.
I decide to port the lookup aspect of it to the web so that I can show off whiling honing my virtually non-existant ASP skills. I've accomplished alot, and the script works nicely (even though its ugly) - but the problem is (i think - I'm still not sure) that I have rs.movenext in the inner loop, so that it hits the EOF and gives an exception error. I cannot figure out how to rewrite my loops which work exactly like I want in every other respect.
<%
Dim adoCon, rs, strSQL, strSQL2
Dim i, style
Dim strDate
dim pctOff
Set adoCon = Server.CreateObject("ADODB.connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("fpdb/leave.mdb")
Set rs = Server.CreateObject("ADODB.Recordset")
strSQL2 = "SELECT vacation.day_off, vacation.status, e_info.e_name, e_info.e_email, e_info.e_eod, e_info.stop, m_info.m_name, m_info.m_phone, m_info.m_email FROM (m_info RIGHT JOIN e_info ON m_info.stop = e_info.stop) RIGHT JOIN vacation ON e_info.e_seid = vacation.e_seid WHERE (((vacation.day_off) = # 01/05/2005 #)) ORDER BY vacation.day_off, e_info.e_eod;"
rs.CursorType = 2
rs.LockType = 3
rs.Open strSQL2, adoCon
i = "0"
strDate = "9/30/2004"
intStaffing = 160
Response.Write ("<div align='center'>")
Response.Write ("<h1>Requests for 10/01/2004 through 01/07/2005</h1>")
Response.Write ("<h2>Rows in yellow are approved leave")
Response.Write (" ")
Do While not rs.EOF 'outer loop
if strDate = rs("day_off") then 'Done so days with no one scheduled off will not show
Response.Write ("<h2>" & rs("day_off") & "</h2>")
Response.Write ("<table align='center' border='1' width='75%'><tr><th>Number</th><th>Employee</th><th>Eod</th><th>Stop</th><th>Manager</th><th>Phone</th></tr>")
Do While rs("day_off") = strDate 'populates the table for a particular day
if strDate = "12/27/2004" then 'different percentages allowed for certain days
pctOff = .7
Elseif strDate = "12/28/2004" then
pctOff = .7
Elseif strDate = "12/29/2004" then
pctOff = .7
Elseif strDate = "12/30/2004" then
pctOff = .7
Elseif strDate = "11/22/2004" then
pctOff = .3
Elseif strDate = "11/23/2004" then
pctOff = .4
Elseif strDate = "11/24/2004" then
pctOff = .6
elseif strDate = "11/26/2004" then
pctOff = .6
elseif strDate = "12/20/2004" then
pctOff = .55
elseif strDate = "12/21/2004" then
pctOff = .6
elseif strDate = "12/22/2004" then
pctOff = .6
elseif strDate = "12/23/2004" then
pctOff = .75
end if
i = i + 1
if i > (intStaffing * pctOff) then 'if to set style and approved/not approved flag in DB
style = "white;"
approved = False
end if
Response.Write ("<tr style='background-color:" & style & "'>" & "<td align='left'>" & i & "</td>")
Response.Write ("<td><a href='mailto:" & rs("e_email") & "'>" & rs("e_name") & "</a>" & "</td>")
Response.Write ("<td>" & rs("e_eod") & "</td>")
Response.Write ("<td>" & rs("stop") & "</td>")
Response.Write ("<td><a href='mailto:" & rs("m_email") & "'>" & rs("m_name") & "</a>" & "</td>")
Response.Write ("<td>" & rs("m_phone") & "</td></tr>")
if approved = true then 'updates DB with approved or not approved
rs.FIELDS("status") = True
Else
rs.FIELDS("status") = False
End if
rs.movenext ' this is where the problem is
Loop
Response.Write ("</table><br>")
Response.Write ("<h3>" & 160*pctOff & " CRs can be allowed off on this day</h3><hr><hr>")
end if
'Reset all inner loop variables
i = "0"
style = "yellow;"
approved = True
pctOff = .1
strDate = DateAdd("d",1,strDate)
Loop
rs.Close
Set rs = Nothing
Set adoCon = Nothing
%>
I apologize for the messy code, I'm pretty new at this and it is a complex project for me. And lastly, this is just a page that only *I* have access to. When I push this out, I will build seperate pages for employee access - ones that DON'T update the DB.
Thank you for any help you can provide.
-NEExt