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

ASP Code Help

Hi All

I am not an ASP expert but some kind soul gave me this code to create a
visual display for the dates stored in a table. It works fine except I now
want to modify it to have the Name and department of the users displayed and
not display the user id field.

The field names in the table are

FirstName
LastName
Department

Can anyone help please?

Thanks a lot.

Regards

Jas
<%@ Language=vbScript %>
<%
dim iMth, iYr, dStart,dEnd,arDates(),arData,cn,rs
dim iDays, iStartDay, iEndDay
dim lCurUser, lNewUser
dim i, j, dHolStart, dHolEnd,k
const cUser = 0
const cFrom = 1
const cTo = 2
const cHoliday = "yellow"
const cWorkday = "white"

iMth=request.form("mth")
if len(iMth) = 0 then iMth = 7
iYr=request.form("yr")
if len(iYr) = 0 then iYr = 2003

'validate them, then
dStart=dateserial(iYr,iMth,1)
dEnd=dateadd("m",1,dStart)
dEnd= dateadd("d",-1,dEnd)
iDays = Day(dEnd)
Redim arDates(iDays)
'this is effectively a one-based array - we will ignore the
'zero element in later code

set cn=server.CreateObject("adodb.connection")

cn.Open "provider=microsoft.jet.oledb.4.0;data source=" & _
server.MapPath("Includes\holidays.mdb")
set rs=server.createobject("adodb.recordset")
strSQL = "SELECT UserID, FDate, TDate FROM Holidays "
strSQL = strSQL & " WHERE (TDate Between #" & dStart & "# and #" & dEnd &
"#) "
strSQL = strSQL & " and (FDate Between #" & dStart & "# and #" & dEnd & "#)
"

response.write strSql & "<br>"

cn.qGetHolidays dStart,dEnd, rs
if not rs.eof then
arData=rs.Getrows
end if
rs.close
set rs=nothing
cn.close
set cn=nothing
if not isArray(arData) then
response.write "No records returned"
else
' stop
' for i=0 to ubound(arData,2)
' for j=0 to ubound(arData,1)
' Response.Write arData(j,i) & "; "
' next
' Response.Write "<BR>"
' next
' Response.End
'pass arDates and dStart to a sub that creates your
'table heading
CreateHeading arDates, dStart
lCurUser = arData(cUser,0)
for i = 1 to iDays
arDates(i) = cWorkday
next
for i = 0 to ubound(arData,2)
lNewUser = arData(cUser,i)
if lCurUser <> lNewUser then
'pass arDates and lCurUser to a sub that creates the
'table row for the user
CreateUserRow arDates,lCurUser
lCurUser = lNewUser
for j = 1 to iDays
arDates(j) = cWorkday
next
end if
dHolStart = CDate(arData(cFrom,i))
iStartDay = Day(dHolStart)
dHolEnd= CDate(arData(cTo,i))
iEndDay= Day(dHolEnd)
if dHolEnd <= iStartDay then iStartDay =1
For j = iStartDay to iEndDay
arDates(j) = cHoliday
next
next
CreateUserRow arDates,lCurUser
response.write "</table>"
erase arData
erase arDates
end if

Sub CreateHeading(pAr,pStart)
dim i
response.write "<br><br>"
response.write "<div align=""center"">" & _
"<center>"

response.write "<TABLE border=1 style=""border-collapse:collapse"">" & _
"<TR><TH colspan="
response.write ubound(pAr) + 1
response.write " align = center>Holidays for "
response.write monthname(month(pStart)) & " " & year(pStart)
response.write "</TH></TR><TR><TH>"
response.write "User ID" & "</TH>"
for i = 1 to ubound(pAr)
response.write "<TH width=15>" & i & "</TH>"
next
response.write "</TR>"
end sub

sub CreateUserRow(pAr, pUser)
dim i
response.write "<tr><th>" & pUser & "</th>"
for i = 1 to ubound(pAr)
response.write "<td bgcolor= "
response.write pAr(i)
response.write ">&nbsp;&nbsp;</td>"
next
response.write "</tr>"
end sub

%>
Jul 19 '05 #1
3 2217
J P Singh wrote:
Hi All

I am not an ASP expert but some kind soul gave me this code to create
a visual display for the dates stored in a table. It works fine
except I now want to modify it to have the Name and department of the
users displayed and not display the user id field.

This was for Access, right?
The field names in the table are

FirstName
LastName
Department
I guess I have to assume that these are in the Holidays table and not some
other related table ... ?

<snip>
strSQL = "SELECT UserID, FDate, TDate FROM Holidays "


Change this to:
strSQL = "SELECT " & _
"FirstName & ' ' & LastName & ' - ' & Department As [User], " & _
"FDate, TDate FROM Holidays "
HTH,
Bob Barrows
Jul 19 '05 #2
Hi Bob

I remember you wrote the code initially.

You are right the database is access.

The Firstname, LastName and Department do come from a different table

This is how it is made up

EmpProfile(Table)

EmployeeNumber
FirstName
LastName
Department

Holidays(Table)

UserId
Fdate
TDate

If possible can I email you the database. The code actually works perfectly
well and all I want to do it to display the name of the person instead of
the employee number

Cheers

Jas
"Bob Barrows" <re*******@yahoo.com> wrote in message
news:uZ**************@TK2MSFTNGP12.phx.gbl...
J P Singh wrote:
Hi All

I am not an ASP expert but some kind soul gave me this code to create
a visual display for the dates stored in a table. It works fine
except I now want to modify it to have the Name and department of the
users displayed and not display the user id field.


This was for Access, right?
The field names in the table are

FirstName
LastName
Department


I guess I have to assume that these are in the Holidays table and not some
other related table ... ?

<snip>
strSQL = "SELECT UserID, FDate, TDate FROM Holidays "


Change this to:
strSQL = "SELECT " & _
"FirstName & ' ' & LastName & ' - ' & Department As [User], " & _
"FDate, TDate FROM Holidays "
HTH,
Bob Barrows

Jul 19 '05 #3
No, I don't need the database, assuming that the two tables can be joined by
the userid and employeenumber fields. The query should be changed to this:

Select FirstName & ' ' & LastName & ' - ' & Department As [User],
FDate, TDate FROM Holidays h INNER JOIN EmpProfile e
ON h.UserID = e.EmployeeNumber
WHERE ...

Test this in Access to see the result.

HTH,
Bob Barrows

J P Singh wrote:
Hi Bob

I remember you wrote the code initially.

You are right the database is access.

The Firstname, LastName and Department do come from a different table

This is how it is made up

EmpProfile(Table)

EmployeeNumber
FirstName
LastName
Department

Holidays(Table)

UserId
Fdate
TDate

If possible can I email you the database. The code actually works
perfectly well and all I want to do it to display the name of the
person instead of the employee number

Cheers

Jas
"Bob Barrows" <re*******@yahoo.com> wrote in message
news:uZ**************@TK2MSFTNGP12.phx.gbl...
J P Singh wrote:
Hi All

I am not an ASP expert but some kind soul gave me this code to
create
a visual display for the dates stored in a table. It works fine
except I now want to modify it to have the Name and department of
the users displayed and not display the user id field.


This was for Access, right?
The field names in the table are

FirstName
LastName
Department


I guess I have to assume that these are in the Holidays table and
not some other related table ... ?

<snip>
strSQL = "SELECT UserID, FDate, TDate FROM Holidays "


Change this to:
strSQL = "SELECT " & _
"FirstName & ' ' & LastName & ' - ' & Department As [User], " & _
"FDate, TDate FROM Holidays "
HTH,
Bob Barrows

Jul 19 '05 #4

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

Similar topics

4
by: Shufen | last post by:
Hi, I'm a newbie that just started to learn python, html and etc. I have some questions to ask and hope that someone can help me on. I'm trying to code a python script (with HTML) to get...
1
by: ChrisR | last post by:
Hi everyone I have a 2002 Access MDB, which uses a HTML page with bookmarks in it, as a Help File. The problem is not accessing the help file, but opening it to the proper bookmark. I use...
6
by: Mark Reed | last post by:
Hi all, I am trying to learn a little about programming (I know next to nothing so far) and have found some code which hides the toolbars. However, this bit of code is a little too effective and...
8
by: jquest | last post by:
Hi Again; I have had help from this group before and want to thank everyone, especially PCDatasheet. My database includes a field called HomePhone, it uses the (xxx)xxx-xxx format to include...
18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
19
by: Swaregirl | last post by:
Hello, I would like to build a website using ASP.NET. I would like website visitors to be able to download code that I would like to make available to them and that would be residing on my...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
16
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and...
13
by: gonzlobo | last post by:
Greetings, and happyNewYear to all. I picked up Python a few weeks ago, and have been able to parse large files and process data pretty easily, but I believe my code isn't too efficient. I'm...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.