You code makes an assumption that you will always get records when you execute
Code:
strSQL5 = "SELECT * FROM timetable WHERE timesheet_No = '"+TimeSheetNo+"'"
This may be valid from a business point of view but it apparently is not from a data point of view.
To protect yourself from this you can try the following
Set pwcoRecordset5 = pwcoConnection.Execute(strSQL5)
Code:
strSQL5 = "SELECT * FROM timetable WHERE timesheet_No = '"+TimeSheetNo+"'"
if(not(pwcoRecordset5.EOF)) then
' process the record
T_StaffName = pwcoRecordset5("staff_name")
Department = pwcoRecordset5("department")
T_Position = pwcoRecordset5("t_position")
else
Response.Write("The following query returned zero rows")
Response.Write(strSQL5)
end if
of course this assumes that if you have multiple rows returned you only want to process the first one and that you want to see when you have a problem in your data.
Anyway, the above should be able to give you enough information to find the root cause of your problem.