ASP code not working Vbscript Return function

C

Colin Graham

Im working on some asp code using vbscript but i cant seem to get the
following code to work. I can get the result from the database but im
having to joy returning the value to the html code in order to open a
specific document. any help appreciated.

I dont get an error message but i get a blank screen. The problem
seems to be with the Return Value of the function - i may not be using
this correctly.

<td>
<%Response.write(GetPDFPath())%>
</td></form>

</TABLE>
</form>
</body></TR></TBODY></TABLE></FORM>




<%
Function GetPDFPath()

Dim oRS, strSQL, txt_ClientCode, strPDFName
dim pdfname
txt_ClientCode = "AA3"

If len(txt_ClientCode)>0 Then

strSQL = "Select ClientCode, PDFName From tbl_PaymentProtectionPDF
Where ClientCode = '" & txt_ClientCode & "'"

Set oRS = Server.CreateObject("ADODB.RecordSet")

on error resume next
oRS.Open strSQL,Application("ConnectionString"),adOpenKeyset,adLockBatchOptimistic

if err.number <> 0 then
response.write "Error: " & err.description
response.end

end if

If Not (oRS.EOF And oRS.BOF) Then
oRS.MoveFirst
strPDFName = oRS(1).value

GetPDFPath = "<iframe height=100% width=100% frameborder=no
src=http://" & Request.ServerVariables("SERVER_NAME") &
"/OAD_XML/documents/" & strPDFName & ".pdf" & " </iframe>"


oRS.Delete
oRS.Update
end if
oRS.Close
Set oRS = Nothing
Response.End
End If
End Function

%>


</BODY>
</HTML>
 
L

larrybud2002

Colin said:
Im working on some asp code using vbscript but i cant seem to get the
following code to work. I can get the result from the database but im
having to joy returning the value to the html code in order to open a
specific document. any help appreciated.

I dont get an error message but i get a blank screen. The problem
seems to be with the Return Value of the function - i may not be using
this correctly.

<td>
<%Response.write(GetPDFPath())%>
</td></form>

</TABLE>
</form>
</body></TR></TBODY></TABLE></FORM>




<%
Function GetPDFPath()

Dim oRS, strSQL, txt_ClientCode, strPDFName
dim pdfname
txt_ClientCode = "AA3"

If len(txt_ClientCode)>0 Then

strSQL = "Select ClientCode, PDFName From tbl_PaymentProtectionPDF
Where ClientCode = '" & txt_ClientCode & "'"

Set oRS = Server.CreateObject("ADODB.RecordSet")

on error resume next
oRS.Open strSQL,Application("ConnectionString"),adOpenKeyset,adLockBatchOptimistic

if err.number <> 0 then
response.write "Error: " & err.description
response.end

end if

If Not (oRS.EOF And oRS.BOF) Then
oRS.MoveFirst
strPDFName = oRS(1).value

GetPDFPath = "<iframe height=100% width=100% frameborder=no
src=http://" & Request.ServerVariables("SERVER_NAME") &
"/OAD_XML/documents/" & strPDFName & ".pdf" & " </iframe>"


oRS.Delete
oRS.Update
end if
oRS.Close
Set oRS = Nothing
Response.End
End If
End Function

%>


</BODY>
</HTML>


So where's your <HTML> open tag, why do you have two closing </body>
tags?? Your HTML is very malformed.
 
M

Morris

Colin said:
Im working on some asp code using vbscript but i cant seem to get the
following code to work. I can get the result from the database but im
having to joy returning the value to the html code in order to open a
specific document. any help appreciated.

I dont get an error message but i get a blank screen. The problem
seems to be with the Return Value of the function - i may not be using
this correctly.

<td>
<%Response.write(GetPDFPath())%>
</td></form>

</TABLE>
</form>
</body></TR></TBODY></TABLE></FORM>




<%
Function GetPDFPath()

Dim oRS, strSQL, txt_ClientCode, strPDFName
dim pdfname
txt_ClientCode = "AA3"

If len(txt_ClientCode)>0 Then

strSQL = "Select ClientCode, PDFName From tbl_PaymentProtectionPDF
Where ClientCode = '" & txt_ClientCode & "'"

Set oRS = Server.CreateObject("ADODB.RecordSet")

on error resume next
oRS.Open strSQL,Application("ConnectionString"),adOpenKeyset,adLockBatchOptimistic

if err.number <> 0 then
response.write "Error: " & err.description
response.end

end if

If Not (oRS.EOF And oRS.BOF) Then
oRS.MoveFirst
strPDFName = oRS(1).value

GetPDFPath = "<iframe height=100% width=100% frameborder=no
src=http://" & Request.ServerVariables("SERVER_NAME") &
"/OAD_XML/documents/" & strPDFName & ".pdf" & " </iframe>"


oRS.Delete
oRS.Update
end if
oRS.Close
Set oRS = Nothing
Response.End
End If
End Function

%>


</BODY>
</HTML>

Get rid of "on error resume next", and you should get an error message,
which will probably help you pin down the problem.

Morris
 
I

io

G'day Colin,

Why do you need Response.End after you succsessfully done your job? This is
why you're getting blank screen

........................
........................
........................
oRS.Delete
oRS.Update
end if
oRS.Close
Set oRS = Nothing
Response.End '???
End If
End Function

I'd say, it is not good practice to have Response.End in a function at all.
You expect your function to return value, not to stop output alltogether. As
you can see you fell into this trap yourself now.


Cheers,
Igor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top