Hi,
What do I have to add to my asp code shown below so that when the recordset pulls data from the excel file it will do it in READONLY mode, then I could open the excel file and make changes to it while the asp code is showing data from it? Right now when the asp code is pulling data from the excel file I can't open the excel file because it is locked by the asp code.
Any help is appreciated, Thanks to all that reply.
My Code is Shown Below
<%@ LANGUAGE="VBSCRIPT" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=http://www.w3.org/1999/xhtml>
<!--start of head tag that contains under it scripts and css style codes-->
<head>
<title>ROW IT Inventory Search</title>
<link href="row_stylesheet.css" rel="stylesheet" type="text/css" media="screen" />
<!--start and closing of css style codes to give appearance to other elements on page-->
<style type="text/css">
a:active {outline:none;}
a:focus {outline:none;}
a:focus {-moz-outline-style:none;}
/* Hyperlinks Default Format */
a:link {
color: #B40000;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #B40000;
}
a:hover {
text-decoration: underline;
color: #000097;
}
a:active {
text-decoration: none;
}
/* Table Records Format */
.tds {
text-transform: capitalize;
color: #000000;
height: 25px;
letter-spacing: 1px;
text-align: center;
vertical-align: middle;
font-family: Arial;
font-size: 12px;
font-weight: regular;
}
/* Sortable tables */
.sortable thead {
background-color:#eee;
color:#666666;
font-weight: bold;
cursor: hand;
}
</style>
<!--start and closing of script code for sorting recordset data in a table - linked to another file-->
<script src="sorttable.js"></script>
<!--start and closing of javascript codes - will check if search text box is empty then display message-->
<script type="text/javascript">
function checkForm()
{
if(document.search_btn.search.value.length==0) {
alert("Please Enter Property ID or Short Description or User Name and press Submit");
document.search_btn.search.focus();
return false;
} else {
return true;
}
}
//-->
<!--
function MM_goToURL() { //v3.0
var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
</script>
<!--closing head tag that contains above it scripts and css style codes-->
</head>
<!--start of html body code with back to top anchor-->
<body bgcolor="#EDEDED" onload="document.search_btn.search.focus();"><a name="top" style="visibility:hidden">top</a>
<!--recordset code to connect, pull data from one excel spreadsheet, and display, sort, bold searched results-->
<%
Dim Results
Dim iRecordCount
iRecordCount = 0
Set dbGlobalWeb = Server.CreateObject("ADODB.Connection")
dbGlobalWeb.Open "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};"&_
"DBQ=" & Server.MapPath("inventory-09.xlsx") & ";"
Results = "SELECT * FROM [assets by end user for 84-01$]"
Results = Results & " WHERE property_id+name+short_desc LIKE '%" & Request.Form("search") & "%' order by property_id ASC;"
Set rsGlobalWeb = Server.CreateObject("ADODB.Recordset")
rsGlobalWeb.Open Results, dbGlobalWeb, 3,3
dim newSearch
newSearch = request.form("search")
private function makeBold(FieldString, SearchString)
dim FieldStringLength
dim SearchStringLength
dim newString
dim TempString
dim StartStringLength
dim EndStringLength
dim StartBoldStyle
dim EndBoldStyle
dim BoldStyleLength
newString = ""
StartBoldStyle = "<span style='color:#990000; font-weight:bold;'>"
EndBoldStyle = "</span>"
BoldStyleLength = len(StartBoldStyle) + len(EndBoldStyle)
FieldStringLength = len(FieldString)
SearchStringLength = len(SearchString)
StartLocation = instr(LCase(FieldString), LCase(SearchString))
if(StartLocation <> 0) then
if(StartLocation <> 1) then
StartStringLength = StartLocation - 1
newString = newString & Left(FieldString, StartStringLength)
end if
TempString = StartBoldStyle & Mid(FieldString, StartLocation, SearchStringLength) & EndBoldStyle
newString = newString & TempString
if(len(newString) < (FieldStringLength + BoldStyleLength)) then
EndStringLength = FieldStringLength - (len(newString) - BoldStyleLength)
newString = newString & Right(FieldString, EndStringLength)
end if
else
newString = FieldString
end if
makeBold = newString
end function
%>
<!--div used to wrap around all contents on page-->
<div id="wrapper" align="center" style="position:absolute; width:100%; top:0px; visibility: visible;">
<!--div hyperlink to go to right of way home site-->
<div align="left" style="margin-left:10px; margin-top:5px;"><a href="http://rowsrv002/" title="Go to Right of Way Home Site"><< Return to Right of Way Home</a></div>
<!--title of asp page-->
<h2 align="center" style="margin-top:10px; text-transform: capitalize; font-family:Verdana; font-weight:bold; font-size:18px; text-decoration: none; color:#0066CC;">ROW IT Inventory Search</h2>
<!--instructions that explain how to use search to find excel data-->
<h2 align="center" style="margin-top:-10px; font-family:Arial; font-size:13px; font-weight:600; color:#313131; #0000B0#;">Enter <u>Property ID</u> or <u>Short Description</u> or <u>User Name</u> and press Submit<br> (example: <u>72000111</u> or <u>printer</u> or <u>john</u> )</h2>
<!--form code text box and submit button to start recordset findings of matched data from search values-->
<form action="search_row-it_inventory.asp" target="_self" method="post" name="search_btn" id="search_btn" style="width:150px;" onsubmit="return checkForm(this);">
<input name="search" type="text" id="search" style="background-color:#fff; margin-left:-50px; height:18px; width:250px; border-style:solid; border-width:1px; border-color:"#000000" title="Please Enter Information as Stated Above" maxlength="25" autocomplete="off">
<input type="button" style="display:; margin-top:5px" value="Reset" title="Reset Page to Default" onClick="parent.location='http://localhost:80/search_row-it_inventory.asp'">
<input type="submit" style="display:; margin-top:5px" value="Submit" title="Click to Search for Inventory Records">
</form>
<!--mail to address code for users to contact help about this asp page-->
<h2 align="center" style="margin-top:5px; font-family:Arial; font-size:11px; font-weight:600; color:#0000B0;">Need Help? <u><a href="mailto:rowhelpdesk@mdot.state.ms.us&cc=spatel@mdot.state.ms.us?subject=Need Help with ROW IT Inventory Search" onMouseOver="window.status='Contact ROW Help Desk';return true" onMouseOut="window.status='';return true">Click Here</a></u></h2>
<!--start if clause to display data if found or else display message-->
<%If rsGlobalWeb.BOF and rsGlobalWeb.EOF Then%>
<!--recordset display 0 records if no matched is found in excel data-->
<h2 align="center" style="margin-top:30px; font-family:Arial; text-transform:capitalize; font-size:16px; font-weight:bold; color:#FE0000;">No Records Found: <u><%response.write(rsGlobalWeb.RecordCount)%></u></h2>
<!--determines what to do next if records are found in excel spreadsheet-->
<%Else%>
<!--recordset display total number of records if match is found in excel data-->
<%If Not rsGlobalWeb.BOF Then%>
<h2 align="center" style="margin-top:30px; font-family:Arial; font-size:16px; font-weight:600; color:#0000B0;">Total Records: <u><%response.write(rsGlobalWeb.RecordCount)%></u></h2>
<!--table display format - linkable to a sorting code stated above-->
<table class="sortable" width="98%" align="center" border="0" cellspacing="1" cellpadding="2" bgcolor="#FFFFFF" style="margin-top:0px;">
<!--table headers display format - clickable to sort records in each column -->
<tr align="center" title="Click Header to Sort Column" bgcolor="#4F81BD" style="margin-top:8px; font-family:Arial; font-size:14px; font-weight:bolder; text-transform:capitalize; color:#FFFFFF; letter-spacing:1px;">
<th onMouseover="this.style.textDecoration='underline';" onMouseout="this.style.textDecoration='none';">Property <br>ID</th>
<th onMouseover="this.style.textDecoration='underline';" onMouseout="this.style.textDecoration='none';">Short <br>Description</th>
<th onMouseover="this.style.textDecoration='underline';" onMouseout="this.style.textDecoration='none';">SubLocation <br>Code</th>
<th onMouseover="this.style.textDecoration='underline';" onMouseout="this.style.textDecoration='none';">User <br>Name</th>
<th onMouseover="this.style.textDecoration='underline';" onMouseout="this.style.textDecoration='none';">Manufacturing <br>Date</th>
<th onMouseover="this.style.textDecoration='underline';" onMouseout="this.style.textDecoration='none';">Model <br>Number</th>
<th onMouseover="this.style.textDecoration='underline';" onMouseout="this.style.textDecoration='none';">Serial <br>Number</th>
<th onMouseover="this.style.textDecoration='underline';" onMouseout="this.style.textDecoration='none';">Price</th>
</tr>
<!--recordset processing how many records are in the excel spreadsheet to display-->
<%Do While Not rsGlobalWeb.EOF%>
<!--record count display and table row alternate color format-->
<%If iRecordCount Mod 2=0 Then%>
<tr bgcolor="#BBCCE4">
<%Else%>
<tr bgcolor="#BBCCE4">
<%End If%>
<!--recordset display excel data in table cells-->
<td class="tds"><%=makeBold(rsGlobalWeb("property_id"),newSearch)%></td>
<td class="tds"><%=makeBold(rsGlobalWeb("short_desc"),newSearch)%></td>
<td class="tds"><%=rsGlobalWeb("sublocation_code")%></td>
<td class="tds"><%=makeBold(rsGlobalWeb("name"),newSearch)%></td>
<td class="tds"><%=rsGlobalWeb("manufacturing date")%></td>
<td class="tds"><%=rsGlobalWeb("model number")%></td>
<td class="tds"><%=rsGlobalWeb("serial number")%></td>
<td class="tds"><%=rsGlobalWeb("price")%></td>
</tr>
<!--record count and looping through excel data to display in table-->
<%
iRecordCount=iRecordCount + 1
rsGlobalWeb.MoveNext
Loop
%>
<!--closing tag for table code-->
</table>
<!--back to top anchor link - takes users back to top of page-->
<center style="font-family:Arial; font-size:12px;"><a href="#top" onMouseOver="window.status='Go Back To Top';return true" onMouseOut="window.status='';return true">Back to Top</a><br><span style="font-size:10px; font-weight:bold;">Copyright © 2010 Right of Way Division, MDOT.</span></center>
<!--closing if clauses of matched records from search-->
<%End If%>
<%End If%>
<!--closing recordset connection to excel spreadsheet-->
<%
rsGlobalWeb.Close
dbGlobalWeb.Close
%>
<!--closing tags for div wrapper, body and html codes-->
</div>
</body>
</html>