If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > cannot create link using response.write

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-18-04, 00:37
newbieasp newbieasp is offline
Registered User
 
Join Date: Oct 2004
Posts: 43
cannot create link using response.write

I have this code I got from microsoft which I changed a little bit. The code works as far as it is supposed to but the problem I am having is the last line of code where it writes a link for the page I get the following error:

Error Type:
Microsoft VBScript compilation (0x800A0408)
Invalid character
/doneweb/createexcel.asp, line 64, column 16
link="<A HREF="/?scid=%26+fileexcel+%26">Open Excel</a>"

cant figure out why I am getting error. The first part of the code actually executes and it creates the excel file in wwwroot, the problem is just with creating the link to that file and being able to execute it.

Here is the code from the page:


<%
'Create a randome Filename
nRandom = Int((1000000 - 1 + 1) * Rnd + 1000000)
fileExcel = "t" & CStr(nRandom) & ".xls"

'Replace 'MyWeb' with your virtual directory name or just the
'slash if it is at the wwwroot.
filePath= Server.mapPath("\")
filename=filePath & "\" & fileExcel

'Create the File with extension .xls using the FileSytemObject
'If the file does not exist, the TRUE parameter will allow it
'to be created. Make sure the user* impersonated has write
'permissions to the directory where the file is being created.

Set fs = Server.CreateObject("Scripting.FileSystemObject")
Set MyFile = fs.CreateTextFile(filename, True)

'Open the connection and retrieve data from the database
Set cn = Server.CreateObject("ADODB.Connection")

'The following open line assumes you have set up a System
'DataSource by the name of Pubs pointing to the Pubs database.
'You must change User UID=<username> and
'PWD=<strong password> to the correct values before you run
'this code. Make sure that UID has the appropriate permissions to
'perform this operation on the database and select permissions
'on the Authors Table.
'If you do not have SQL Server, see notes below for how to modify
'sample to work with an Access database

cn.Open "DSN=Employees"


Set rs = cn.Execute("Select * from Borrowers Where LeadDate > #" & Request.Form("date") & "#")

strLine="" 'Initialize the variable for storing the filednames


For each x in rs.fields
'Separate field names with tab so that these appear in
'different columns in Excel
strLine= strLine & x.name & chr(9)
Next
'Write this string into the file
MyFile.writeline strLine

'Retrieve the values from the database and write into the database
Do while Not rs.EOF
strLine=""
for each x in rs.Fields
strLine= strLine & x.value & chr(9)
next
MyFile.writeline strLine
rs.MoveNext
Loop

'Clean up
MyFile.Close
Set MyFile=Nothing
Set fs=Nothing

'Show a link to the Excel File.
link="<A HREF="/?scid=%26+fileexcel+%26">Open Excel</a>"
Response.write link


%>
Reply With Quote
  #2 (permalink)  
Old 11-18-04, 19:12
Seppuku Seppuku is offline
Useless...
 
Join Date: Jul 2003
Location: SoCal
Posts: 721
Try this:

link="<A HREF=""/?scid=%26+fileexcel+%26"">Open Excel</a>"
__________________
That which does not kill me postpones the inevitable.
Reply With Quote
  #3 (permalink)  
Old 11-19-04, 16:40
newbieasp newbieasp is offline
Registered User
 
Join Date: Oct 2004
Posts: 43
Thanks that worked it was able to write the link, but if i click on the link it takes me to my default home page not to the excel file. How can I fix this?
Reply With Quote
  #4 (permalink)  
Old 11-19-04, 17:04
Seppuku Seppuku is offline
Useless...
 
Join Date: Jul 2003
Location: SoCal
Posts: 721
sounds like an issue with the link.. you're pointing to "/?scid=&+fileexcel+&". This will automatically direct the request to your default index file.. and pass that parameter..
__________________
That which does not kill me postpones the inevitable.
Reply With Quote
  #5 (permalink)  
Old 11-19-04, 18:58
newbieasp newbieasp is offline
Registered User
 
Join Date: Oct 2004
Posts: 43
How do I get it to point to the excel file that was created ?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On