Link to home
Start Free TrialLog in
Avatar of Jim Dorans
Jim Dorans

asked on

Export to Excel using Classic .asp

I had this question after viewing Export data to Excel from Classic ASP page.

My question is similar, and I had trouble with the line
Set rstSearch = cnnSearch.Execute(strSQL)

Open in new window

...which returned the error message "Object required: ''

I understand roughly how the code works, but I simply cannot get it to work for me, after modifying it to suit my example.

So, to show what I'm trying to achieve (a simple export to Excel), I've made the simplest possible example to return the 3 rows in a small table, and I'd like to be able to click a button to export this to Excel (I know the "form" section does this).

Here is my code in its simplest form :  
<!--#include file="inc_dbconn.asp"-->
<!--#include file="adovbs_inc.asp"-->

<html>
<body>
<%

      set rs = Server.CreateObject("ADODB.recordset")
       sql = "SELECT ID, Firstname, Surname FROM JIM_Test1"
	    rs.Open sql, conn
	     if not rs.EOF then
%>
<table border="1px">
<tr>
<td>ID</td><br>
<td>Firstname</td><br>
<td>Surname</td><br>
</tr>
<%
    	  do until rs.EOF
%>
<tr> 
<td><%Response.Write(rs.Fields("ID").value)%></td>
<td><%Response.Write(rs.Fields("Firstname").value)%></td>
<td><%Response.Write(rs.Fields("Surname").value)%></td>
</tr>
<%
  rs.movenext
   loop
    end if
     rs.close
      conn.close
       set conn=nothing
        set rs=nothing
%>
</table>

</body>
</html>

Open in new window

, and this is the SQL to create the data (if you need to) :
IF OBJECT_ID('JIM_Test1') IS NOT NULL DROP TABLE JIM_Test1

CREATE TABLE JIM_Test1
 (  
  ID INT,
  Firstname nvarchar(20), 
  Surname nvarchar(10) 
 )

 INSERT INTO JIM_Test1 VALUES (1, 'Fred', 'Jones');
 INSERT INTO JIM_Test1 VALUES (2, 'Joe', 'Wilson');
 INSERT INTO JIM_Test1 VALUES (3, 'Andy', 'Smith');

Open in new window

This should be something that is easy to do, but for some reason I'm doing something wrong.
Any help much appreciated!

Thanks

Jim
Avatar of Big Monty
Big Monty
Flag of United States of America image

at first glance, your code looks ok. can you explain "whats not working"?
Avatar of Jim Dorans
Jim Dorans

ASKER

Big Monty, the code above "works" in that it displays the 3 data rows to the web page. There is no code there to export to an Excel file.

When I put the lines of code in, as suggested in the other thread [  https://www.experts-exchange.com/questions/28180082/Export-data-to-Excel-from-Classic-ASP-page.html ] , I get an error, namely "Object required'', which is what happens when it reads this line :

 Set rstSearch = cnnSearch.Execute(strSQL)

Open in new window

As far as I can tell, the lines which trigger the Excel output are :

Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "filename=""Excel Export.xls"""

Open in new window


Sorry for the confusion, but I thought it would make more sense to show just my basic code , and a reference to the key lines in the other thread [ https://www.experts-exchange.com/questions/28180082/Export-data-to-Excel-from-Classic-ASP-page.html ] to avoid pages and pages of code attached to my question.

So, the code chunk I posted just before your reply works, but only outputs to the web page. I'm looking for the means to click on a button to also do an export to Excel.

Could you add lines to my code above, to do this?

Sorry, I tried to make things as simple and uncluttered as possible for people to read, but it looks like that idea might have backfired!

Jim
nope, it didn't backfire at all, I just needed a bit of clarification :) and +1 points for creating a test example!

can you post the example code with the code that you came up with to export it to excel? I have to run to a meeting but will get back to this later today.
Hi Monty,

This is my code :
 <!--#include file="inc_dbconn.asp"-->
<!--#include file="adovbs_inc.asp"-->

<%If Request("ACT")="xls" Then
  'Build & Execute Your SQL Command
  strSQL = "SELECT ID, Firstname, Surname FROM JIM_Test1"
  Set rstSearch = cnnSearch.Execute(strSQL)

  'Set the HTTP Header
  Response.ContentType = "application/vnd.ms-excel"
  Response.AddHeader "Content-Disposition", "filename=""Excel Export.xls"""

  'Output Table %>
  
  <table border="1" cellspacing="0" cellpadding="5">
   <tr>
    <th>Header 1</th><th>Header 2</th><th>Header 3</th>
     </tr><% Do While Not rstSearch.EOF %>
   <tr>
    <td><%=rstSearch(0)%></td><td><%=rstSearch(1)%></td><td><%=rstSearch(2)%></td>
     </tr>
	
	<% rstSearch.MoveNext : Loop %>

  </table>

  <%
  'Stop Processing Page Now
  Response.End
End If%>

<form action="?" method="post" target="_blank">
 <input type="hidden" name="ACT" value="xls">
 <input type="hidden" name="ID" value="<%=Request("ID")%>">
 <input type="hidden" name="Firstname" value="<%=Request("Firstname")%>">
 <input type="hidden" name="Surname" value="<%=Request("Surname")%>">
 <input type="submit" value="Export To Excel">
</form>

Open in new window

... and this is the error message after clicking the "Export to Excel" button :
Microsoft VBScript runtime error '800a01a8'
Object required: 'cnnSearch'
/localhost-test-export-excel-monty.asp, line 7

If you remember the other thread I post on recently : [ https://www.experts-exchange.com/questions/29017643/classic-asp-edit-a-data-field-returned-by-a-sql-server-query.html ] , all I am trying do is add an Excel Export button to each section - hence the very simple sample code here to save to save space.

Thanks

Jim
usually that error means you are referencing an object incorrectly, or one that doesn't exist. I think you need to change this line

Set rstSearch = cnnSearch.Execute(strSQL)

to use the connection object declared in your include file, which I believe is conn. so it would be:

Set rstSearch = conn.Execute(strSQL)
Hi Monty,

Yes, your fix above worked just fine, thanks.

Now, I have tried to apply the coding to the live system, and I have a problem. Basically, my SQL statement in the export section needs to contain a parameter for the PupilID, and I can't seem to get this to work. I get the error "SYNTAX ERROR OR ACCESS VIOLATION".

It refers to the paramBuilder.NextParameter(intID) on line 20 of the main SELECT statement.

In the second SELECT statement on line 58, if I use this paramBuilder.NextParameter(intID), then I get the error  "SYNTAX ERROR OR ACCESS VIOLATION" , and I'm not sure how to get round this. So, in order to get the export to work at all, I've have to remove the parameter, with the result that all pupil records are exported, instead of just the current one. Also, the export is picking up some data from the previous section, and I can't figure out why (see attachment).

I'm wondering if it would be easier just to have a separate code page for the export, triggered by a button?

Thanks

<!--#include file="../../system/includes/inc_security.asp"-->
<!--#include file="../../system/includes/inc_theme.asp"-->

<!--------------------------------------------------------------------->
<!---------------- SHOW THE SUBJECT REPORTS --------------------------->
<!--------------------------------------------------------------------->
  
  <br><br>
  
  <table border="1px" width="100%">
   <tr><td valign="middle" style="width:70px;">  <b>Subject Reports</b></td></tr>
    </table>
  
  <br>
   <table border="1px" width="100%">
   <tr><td>Subject</td><td>Teacher</td><td>Report</td></tr>

<% 

 sql = "SELECT DISTINCT txtSchoolID, txtID, SubjectTeacher, AltTutor, txtCommentID, txtComment FROM CAN_Tbl_UCAS_Reports WHERE intReportType = 1 AND txtCommentID IS NOT NULL AND txtSchoolID = " & paramBuilder.NextParameter(intID) & " ORDER BY txtID"
  Set rsRecord = Database.GetRs(sql, conn, paramBuilder.Parameters)
   if not rsRecord.EOF then
 	do until rsRecord.EOF

	' First we need to create our Variables
      ConID    = rsRecord("txtCommentID")
      Com      = rsRecord("txtComment")
      Alt      = rsRecord("AltTutor")
	  SchoolID = rsRecord("txtSchoolID")
%>
   <tr>
    <td><%Response.Write(rsRecord.Fields("txtID").value)%></td>
    <td><%Response.Write(rsRecord.Fields("SubjectTeacher").value)%></td>
    <td>
     <form action="updateform.asp" method="post">
      <input type="hidden" name="ID" value="<%=ConID%>" />
       <textarea rows="6" cols="225" name="comment"><%=Com%></textarea>
        <input type="hidden" name="SchoolID" value="<%=SchoolID%>" />
		 <br>
		  <input type="submit" name="Submit" value="Save" /> 
           </form>
            </td>
   </tr>
      
<%
  rsRecord.Movenext 
   loop
    end if
     rsRecord.close
      set rsRecord = nothing 
%>
</table>

<!-----21-08-2017 START Jim testing Excel export---------------------->

<%If Request("ACT")="xls" Then
  'Build & Execute Your SQL Command
  SQL = "SELECT DISTINCT SubjectTeacher, txtID, txtComment FROM CAN_Tbl_UCAS_Reports WHERE intReportType = 1 AND txtCommentID IS NOT NULL ORDER BY txtID"

     Set rstSearch = conn.Execute(SQL)

  'Set the HTTP Header
  Response.ContentType = "application/vnd.ms-excel"
  Response.AddHeader "Content-Disposition", "filename=""Excel Export.xls"""

  'Output Table 
  %>
  <br><br><br>

  <table border="1" cellspacing="0" cellpadding="5">
<tr>
    <th>Teacher</th><th>Subject</th><th>Subject Report</th>
     </tr>
   <% Do While Not rstSearch.EOF %>
   
   <tr>
    </td><td><%=rstSearch(0)%><td><%=rstSearch(1)%></td><td><%=rstSearch(2)%>
     </tr>
		
	<% rstSearch.MoveNext : Loop %>
</table>  

  <%
  'Stop Processing Page Now
  Response.End
End If%>
<br>
<form action="?" method="post">
 <input type="hidden" name="ACT" value="xls">
 <input type="submit" value="Export To Excel">
</form>
   
<!--21-08-2017 END Jim testing Excel export  ---------------------------------------->   

Open in new window

monty-experts-exchange-export.JPG
ok good, the original problem has been resolved, correct?

what is paramBuilder.NextParameter()? I don't recognize this as classic asp syntax, but rather, it looks like pure JAVA, which would explain the error. Do you have a link to any documentation that explains what it is?
Hi Monty,

Yes, the original problem was resolved.

About the paramBuilder.NextParameter() , I'm afraid I'm at a loss here. All I know is that it is the txtSchoolID, in other words the Pupil ID which is selected from the left-hand-side "tree" in the application. When a pupil name is clicked, it opens up the viewstudent.asp page, and the code samples I posted above are from this page. So, somehow this parameter is passed across and used in viewstudent.asp, but that's all I know.

The whole system is called "iSAMS" (a big education software package), and I've looked through the entire code directory for this parameter function, but all I can find are more occurrences of its use, but not the root function itself. The only documentation for the package is at user level, not coding level, unfortunately.

I'm wondering if there's any other way to do this export - perhaps use a temp table in the SQL string, so that we don't have to worry about re-using the parameter again? Or, is there any way to export the data after the data has been displayed on the page? I'm having a look around to see.

Thanks again for your time.

Jim
can you post the full message you get, or a screenshot? also, is the PupilID stored somewhere else, like maybe a query string variable or a posted form value? if we can get that piece of data elsewhere, we can work around the paramBuilder.NextParameter() issue. have you looked in all of the include files in the pages where paramBuilder.NextParameter() works for clues to what it may be?
Hi Monty,

My bad, sorry. I had missed out a very important part of the code I posted (it was even staring me in the face!), so here it is : it goes right above the "SHOW THE SUBJECT REPORTS " line :

<% 'viewstudent-test.asp-v111-11-09-2017 --Includes Export to Excel

	'txtModule="iSAMS_SCHOOLDIRECTORY"
	'txtContext="SDSTUDENT"
	
	intID = request.querystring("id")
%>

Open in new window



The intID is what contains the value for the PupilID, and if you do a
Response.Write(intID)

Open in new window

on line 53, it lists it.

However, if you use it on the SQL statement on line 58 in the WHERE clause of the Export section, it doesn't produce an error, but returns no data - so I'm still doing something wrong.

Hope that helps.

Jim
ok we can work with this :)

what do you get written out to the screen if you do:

 sql = "SELECT DISTINCT txtSchoolID, txtID, SubjectTeacher, AltTutor, txtCommentID, txtComment FROM CAN_Tbl_UCAS_Reports WHERE intReportType = 1 AND txtCommentID IS NOT NULL AND txtSchoolID = " & request.querystring("id") & " ORDER BY txtID"
Response.Write sql
Response.End

do you get the full sql statement, with the included ID value?
Monty, no - the ID value was not written to the screen, just a " (two single quote marks, just before the ORDER BY) :

SELECT DISTINCT txtSchoolID, txtID, SubjectTeacher, AltTutor, txtCommentID, txtComment FROM CAN_Tbl_UCAS_Reports WHERE intReportType = 1 AND txtCommentID IS NOT NULL AND txtSchoolID = '' ORDER BY txtID      

So, the value
intID

Open in new window

, or its equal
request.querystring("id")

Open in new window

(evaluated at the beginning), is not being pulled through to the Export section, by the looks of things.
can you post the full source code of the page?
Sure ...this is what I used, and includes your little debug, and my comment  :

<!--#include file="../../system/includes/inc_security.asp"-->
<!--#include file="../../system/includes/inc_theme.asp"-->

<% 'viewstudent-test.asp-v111-11-09-2017 --Includes Export to Excel

	'txtModule="iSAMS_SCHOOLDIRECTORY"
	'txtContext="SDSTUDENT"
	
	intID = request.querystring("id")
%>

<body class="page padded">

<!-------------------------------------------------------->
<!----------------- SHOW THE SUBJECT REPORTS ------------->
<!-------------------------------------------------------->

   <table border="1px" width="100%">
    <tr>
     <td>Subject</td>
     <td>Subject Report</td>
    </tr>

<% 
sql = "SELECT DISTINCT txtSchoolID, txtID, txtCommentID, txtComment FROM CAN_Tbl_UCAS_Reports WHERE intReportType = 1 AND txtSchoolID = " & paramBuilder.NextParameter(intID) & " ORDER BY txtID"
  Set rsRecord = Database.GetRs(sql, conn, paramBuilder.Parameters)

 if not rsRecord.EOF then
	  		do until rsRecord.EOF
   ' First we need to create our Variables
      SchoolID = rsRecord("txtSchoolID")
      ConID = rsRecord("txtCommentID")
      Com = rsRecord("txtComment")
%>
   <tr>
    <td style="text-align:center; vertical-align:top; height:10px"><%Response.Write(rsRecord.Fields("txtID").value)%></td>
    <td style="text-align:center">
      <form action="updateform.asp" method="post">
       <input type="hidden" name="ID" value="<%=ConID%>" />
       <input type="hidden" name="SchoolID" value="<%=SchoolID%>" /> 
        <textarea rows="3" cols="180" name="comment"><%=Com%></textarea>
      </form>
    <td>
   </tr>
<%
	rsRecord.Movenext 
  loop
   end if
    rsRecord.close
     set rsRecord = nothing 
%>
</table>

<!-- Jim says : if you put Monty's debug code in here, then it will display the actual StudentID, but it doesn't do that when used further down-->

<br>
<!--EXCEL EXPORT-------------------------------->
<!--EXCEL EXPORT-------------------------------->
<%If Request("ACT")="xls" Then
  'Build & Execute Your SQL Command
 
' START BIG MONTY TEST 13-09-2017
  sql = "SELECT DISTINCT txtSchoolID, txtID, SubjectTeacher, AltTutor, txtCommentID, txtComment FROM CAN_Tbl_UCAS_Reports WHERE intReportType = 1 AND txtCommentID IS NOT NULL AND txtSchoolID = '" & request.querystring("id") & "' ORDER BY txtID"
Response.Write sql
Response.End
' END BIG MONTY TEST 13-09-2017
 
Set rstSearch = conn.Execute(SQL)
    'Set the HTTP Header
  Response.ContentType = "application/vnd.ms-excel"
  Response.AddHeader "Content-Disposition", "filename=""Excel Export.xls"""

  'Output Table %>
  
  <table border="1" cellspacing="0" cellpadding="5">
   <tr>
    <th>Header 1</th><th>Header 2</th><th>Header 3</th>
     </tr><% Do While Not rstSearch.EOF %>
   <tr>
    <td><%=rstSearch(1)%></td><td><%=rstSearch(3)%></td>
     </tr>
  	<% rstSearch.MoveNext : Loop %>
   </table>
<%
  'Stop Processing Page Now
   Response.End
    End If
%>

<form action="?" method="post">
 <input type="hidden" name="ACT" value="xls">

 <input type="submit" value="Export To Excel">
</form>
  </body>

</html>
<!--#include file="../../system/connections/inc_dbconnclose.asp"-->

Open in new window

instead of using 2 recordsets, why not just use rsRecord as your data set, and simply add your SubjectTeacher and AltTutor columns to the select statement? You would need to comment out lines 49 and 50, and add a rsRecord.MoveFirst before doing your excel output, but it should be pretty straightforward:

<!--#include file="../../system/includes/inc_security.asp"-->
<!--#include file="../../system/includes/inc_theme.asp"-->

<% 'viewstudent-test.asp-v111-11-09-2017 --Includes Export to Excel

	'txtModule="iSAMS_SCHOOLDIRECTORY"
	'txtContext="SDSTUDENT"
	
	intID = request.querystring("id")
%>

<body class="page padded">

<!-------------------------------------------------------->
<!----------------- SHOW THE SUBJECT REPORTS ------------->
<!-------------------------------------------------------->

   <table border="1px" width="100%">
    <tr>
     <td>Subject</td>
     <td>Subject Report</td>
    </tr>

<% 
sql = "SELECT DISTINCT txtSchoolID, txtID, txtCommentID, txtComment FROM CAN_Tbl_UCAS_Reports WHERE intReportType = 1 AND txtSchoolID = " & paramBuilder.NextParameter(intID) & " ORDER BY txtID"
  Set rsRecord = Database.GetRs(sql, conn, paramBuilder.Parameters)

 if not rsRecord.EOF then
	  		do until rsRecord.EOF
   ' First we need to create our Variables
      SchoolID = rsRecord("txtSchoolID")
      ConID = rsRecord("txtCommentID")
      Com = rsRecord("txtComment")
%>
   <tr>
    <td style="text-align:center; vertical-align:top; height:10px"><%Response.Write(rsRecord.Fields("txtID").value)%></td>
    <td style="text-align:center">
      <form action="updateform.asp" method="post">
       <input type="hidden" name="ID" value="<%=ConID%>" />
       <input type="hidden" name="SchoolID" value="<%=SchoolID%>" /> 
        <textarea rows="3" cols="180" name="comment"><%=Com%></textarea>
      </form>
    <td>
   </tr>
<%
	rsRecord.Movenext 
  loop
  rsRecord.MoveFirst
   end if
  '  rsRecord.close
    ' set rsRecord = nothing 
	
%>
</table>

<!-- Jim says : if you put Monty's debug code in here, then it will display the actual StudentID, but it doesn't do that when used further down-->

<br>
<!--EXCEL EXPORT-------------------------------->
<!--EXCEL EXPORT-------------------------------->
<%If Request("ACT")="xls" Then
  'Build & Execute Your SQL Command
 
' START BIG MONTY TEST 13-09-2017
 ' sql = "SELECT DISTINCT txtSchoolID, txtID, SubjectTeacher, AltTutor, txtCommentID, txtComment FROM CAN_Tbl_UCAS_Reports WHERE intReportType = 1 AND txtCommentID IS NOT NULL AND txtSchoolID = '" & request.querystring("id") & "' ORDER BY txtID"
'Response.Write sql
'Response.End
' END BIG MONTY TEST 13-09-2017
 
'Set rstSearch = conn.Execute(SQL)
    'Set the HTTP Header
  Response.ContentType = "application/vnd.ms-excel"
  Response.AddHeader "Content-Disposition", "filename=""Excel Export.xls"""

  'Output Table %>
  
  <table border="1" cellspacing="0" cellpadding="5">
   <tr>
    <th>Header 1</th><th>Header 2</th><th>Header 3</th>
     </tr><% Do While Not rsRecord.EOF %>
   <tr>
    <td><%=rsRecord(1)%></td><td><%=rsRecord(3)%></td>
     </tr>
  	<% rsRecord.MoveNext : Loop %>
   </table>
<%
  'Stop Processing Page Now
   Response.End
    End If
%>

<form action="?" method="post">
 <input type="hidden" name="ACT" value="xls">

 <input type="submit" value="Export To Excel">
</form>
  </body>

</html>
<!--#include file="../../system/connections/inc_dbconnclose.asp"-->

Open in new window

Thanks, but unfortunately that did not work. The error was  :

ERROR CATEGORY: MICROSOFT OLE DB PROVIDER FOR SQL SERVER
ERROR TYPE: ROWSET POSITION CANNOT BE RESTARTED.
ERROR SOURCE: ERROR LINE: 48

... which refers to
rsRecord.MoveFirst

Open in new window


I'm wondering if it would be possible to write each record to a file, in addition to it writing to the html table as it loops through the recordset?
looks like you have a forward only cursor for your recordset, no problem, since it's the same recordset data, we can just put the exported data into a string, then write it to the file when ready. check out the exportToExcelString variable I created to see what I did:

<!--#include file="../../system/includes/inc_security.asp"-->
<!--#include file="../../system/includes/inc_theme.asp"-->

<% 'viewstudent-test.asp-v111-11-09-2017 --Includes Export to Excel

	'txtModule="iSAMS_SCHOOLDIRECTORY"
	'txtContext="SDSTUDENT"
	
	intID = request.querystring("id")
%>

<body class="page padded">

<!-------------------------------------------------------->
<!----------------- SHOW THE SUBJECT REPORTS ------------->
<!-------------------------------------------------------->

   <table border="1px" width="100%">
    <tr>
     <td>Subject</td>
     <td>Subject Report</td>
    </tr>

<% 
sql = "SELECT DISTINCT txtSchoolID, txtID, txtCommentID, txtComment, AltTutor FROM CAN_Tbl_UCAS_Reports WHERE intReportType = 1 AND txtSchoolID = " & paramBuilder.NextParameter(intID) & " ORDER BY txtID"
  Set rsRecord = Database.GetRs(sql, conn, paramBuilder.Parameters)
dim exportToExcelString
 if not rsRecord.EOF then
	  		do until rsRecord.EOF
   ' First we need to create our Variables
      SchoolID = rsRecord("txtSchoolID")
      ConID = rsRecord("txtCommentID")
      Com = rsRecord("txtComment")
	  exportToExcelString = exportToExcelString & "<tr><td>" & rsRecord("txtID") & "</td><td>" & rsRecord("AltTutor") & "</td></tr>"
%>
   <tr>
    <td style="text-align:center; vertical-align:top; height:10px"><%Response.Write(rsRecord.Fields("txtID").value)%></td>
    <td style="text-align:center">
      <form action="updateform.asp" method="post">
       <input type="hidden" name="ID" value="<%=ConID%>" />
       <input type="hidden" name="SchoolID" value="<%=SchoolID%>" /> 
        <textarea rows="3" cols="180" name="comment"><%=Com%></textarea>
      </form>
    <td>
   </tr>
<%
	rsRecord.Movenext 
  loop
  rsRecord.MoveFirst
   end if
  '  rsRecord.close
    ' set rsRecord = nothing 
	
%>
</table>

<!-- Jim says : if you put Monty's debug code in here, then it will display the actual StudentID, but it doesn't do that when used further down-->

<br>
<!--EXCEL EXPORT-------------------------------->
<!--EXCEL EXPORT-------------------------------->
<%If Request("ACT")="xls" Then
  'Build & Execute Your SQL Command
 
' START BIG MONTY TEST 13-09-2017
 ' sql = "SELECT DISTINCT txtSchoolID, txtID, SubjectTeacher, AltTutor, txtCommentID, txtComment FROM CAN_Tbl_UCAS_Reports WHERE intReportType = 1 AND txtCommentID IS NOT NULL AND txtSchoolID = '" & request.querystring("id") & "' ORDER BY txtID"
'Response.Write sql
'Response.End
' END BIG MONTY TEST 13-09-2017
 
'Set rstSearch = conn.Execute(SQL)
    'Set the HTTP Header
  Response.ContentType = "application/vnd.ms-excel"
  Response.AddHeader "Content-Disposition", "filename=""Excel Export.xls"""

  'Output Table %>
  
  <table border="1" cellspacing="0" cellpadding="5">
   <tr>
    <th>Header 1</th><th>Header 2</th><th>Header 3</th>
     </tr>
	 <%= exportToExcelString %>
   </table>
<%
  'Stop Processing Page Now
   Response.End
    End If
%>

<form action="?" method="post">
 <input type="hidden" name="ACT" value="xls">

 <input type="submit" value="Export To Excel">
</form>
  </body>

</html>
<!--#include file="../../system/connections/inc_dbconnclose.asp"-->

Open in new window

Hi Monty,

I see your string worked, but unfortunately we have the same problem as before. I can Response.Write your string to the screen, but for some reason it seems to lose its value when it gets to the export stage.

How about I do you a very simple script to create a small database with only a few records, and skeleton code, so you simulate the problem for yourself? If you've had enough of this, don't be afraid to say!

Thanks!

Jim
Had enough? Ha! I'm too much a glutton for punishment I suppose :)

Sure, if you can set up a test package, I'll be able to diagnose the problem much easier.
Hi Monty,

Sorry for the delay.

Here is a self-contained script which will reproduce the data which we were trying to export. Using your code example above, if you use this data you should be able to see what's happening. You just need to make your own connection string / include file.

Thanks!

CREATE DATABASE MONTY_TEST

USE MONTY_TEST

IF OBJECT_ID('CAN_Tbl_UCAS_Reports')  IS NOT NULL DROP TABLE CAN_Tbl_UCAS_Reports

CREATE TABLE CAN_Tbl_UCAS_Reports
 (  
  txtSchoolID NVARCHAR(10),
  txtID NVARCHAR(10),
  SubjectTeacher NVARCHAR(10),
  AltTutor NVARCHAR(10),
  txtCommentID NVARCHAR(10),
  txtComment NVARCHAR(1000)
 )

INSERT INTO CAN_Tbl_UCAS_Reports VALUES ('1325552844', 'French', 'CFG', 'SWE', '15443',
'Will always engage and show interest in the topic. He works methodically through problems and his answers show a growing use of the detail required.')

INSERT INTO CAN_Tbl_UCAS_Reports VALUES ('1325294544', 'Maths', 'SWE', 'FHT', '15173', 
'She is a positive and kind member of the group. She is very able and often produces very accomplished work. She is an art scholar and takes responsibility')

INSERT INTO CAN_Tbl_UCAS_Reports VALUES ('1234465544', 'English', 'SWE', 'FER', '24173',
'A competent mathematician who is able to understand and use new concepts and techniques very quickly indeed, with much success')

INSERT INTO CAN_Tbl_UCAS_Reports VALUES ('3244465544', 'Art', 'DER', 'HTR', '74662',
'Able to analyse large, extended problems and break them down in to smaller, more manageable tasks.')

INSERT INTO CAN_Tbl_UCAS_Reports VALUES ('1386244654', 'French', 'DWE', 'AQW', '51467',
'Able to see the links and make the connections between various parts of the subject and is keen to know how these apply to real-life situations.')

INSERT INTO CAN_Tbl_UCAS_Reports VALUES ('6356244654', 'German', 'AQE', 'HEU', '96754',
'Has grown in confidence a huge amount during the course and is now able to apply a wide variety of techniques.')

--SELECT * FROM CAN_Tbl_UCAS_Reports

Open in new window

i'll see if i can set this up in the next day or so
Jim, I apologize for letting this slip through again, do you still need a solution?

If so, I'll set up a test page today.
Monty, yes I still need a solution. Thanks for offering.
ASKER CERTIFIED SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, Wayne! I'm going to try this shortly.

Jim
It's Josh, but close enough :)
gave a working example that I tested on my end