Solved

automatically print redirected to the specified Page

Posted on 2004-04-26
8
768 Views
Last Modified: 2007-12-19
Hi,

i am usin w2k  service pack 3 and explorer  ver.5.

I have an search page. when user enter search id and submit the result will be printed automaticaly without any print dialo box to appear. the code is workin fine. Here i want to return to search.asp automatically after printin or bein displayed the searchresult.asp page for some time and printin. when i use "response.redirect" anywhere in the searchresult.asp, when user click submit from search.asp, s/he cannot print the result.  It is just redirected to search.asp wihtout printin. if not usin response.redirect then the result will be printed out automatically. how can return to the serach.asp after printin or even the result is displayed there for a while and bein printed.

searchResult.asp.

<html>
<head>
<script language="VBScript">
SUB Print()
    OLECMDID_PRINT = 6
    OLECMDEXECOPT_DONTPROMPTUSER = 2
    OLECMDEXECOPT_PROMPTUSER = 1
    document.body.focus()
    on error resume next
    call IEWB.ExecWB (OLECMDID_PRINT, -1)
    if err.number <> 0 then
        alert "Nothing Printed"
    end if
END SUB
</script>

<%set con = server.createObject ("connection")
con.open "studentsList"

set rst = server.createobject("adodb.recordset")
rst.open "select * from student where id='" &Request ("txtID")& "'",con

</head>
     <body onload="print()">
          <object id="IEWB" width="0" height="0" classid="clsid:8856F961-340A-11D0-A96B-00C04FD705A2">
          </object>
          <table><tr><td>Name</td><td><rst("Name")%></td>
<td>School</td><td><%rst("school")%></td></tr></table>
     </body>
</html>
0
Comment
Question by:ayha1999
  • 4
  • 4
8 Comments
 
LVL 11

Expert Comment

by:Slimshaneey
ID: 10917661
Im not entirely sure I understand your question, but you could put a sleep function in your code to make the page wait before redirecting:

function tsp_sleep(var)
Dim MaxSleep
'Sleep for 20 seconds
MaxSleep = 20
    if var < 1 then
    var = 1
    elseif var > MaxSleep then
    var = MaxSleep
    end if
    dim x
    x = timer
    do until x + var = timer
    ' sleep
    loop
 end function


Then in your Print Func, put the sleep at  the end to make the page wait.

SUB Print()
    OLECMDID_PRINT = 6
    OLECMDEXECOPT_DONTPROMPTUSER = 2
    OLECMDEXECOPT_PROMPTUSER = 1
    document.body.focus()
    on error resume next
    call IEWB.ExecWB (OLECMDID_PRINT, -1)
    if err.number <> 0 then
        alert "Nothing Printed"
    end if
'Make it wait 10 seconds
tsp_sleep(10)
END SUB
</script>

0
 
LVL 7

Author Comment

by:ayha1999
ID: 10919423
Hi Slimshaaney,

, but you could put a sleep function in your code to make the page wait before redirecting:

what i want is, once user click submit from search.asp page, the searchresult.asp page shoud be printed out and then redirected to search.asp.

could you please check tsp_sleep function whcih show me script error. and where can i put response.redirect "search.asp".  

<html>
<head>
<@ language="VBScript">
<SCRIPT LANGUAGE=javascript>

function tsp_sleep(var)
Dim MaxSleep
'Sleep for 20 seconds
MaxSleep = 20
    if var < 1 then
    var = 1
    elseif var > MaxSleep then
    var = MaxSleep
    end if
    dim x
    x = timer
    do until x + var = timer
    ' sleep
    loop
 end function      
      //-->
</SCRIPT>


<script language="VBScript">
SUB Print()
    OLECMDID_PRINT = 6
    OLECMDEXECOPT_DONTPROMPTUSER = 2
    OLECMDEXECOPT_PROMPTUSER = 1
    document.body.focus()
    on error resume next
    call IEWB.ExecWB (OLECMDID_PRINT, -1)
    if err.number <> 0 then
        alert "Nothing Printed"
    end if
   
    'Make it wait 10 seconds
tsp_sleep(10)

END SUB
</script>


<%set con = server.createObject ("connection")
con.open "studentsList"

set rst = server.createobject("adodb.recordset")
rst.open "select * from student where id='" &Request ("txtID")& "'",con

</head>
<body onload="print()">
          <object id="IEWB" width="0" height="0" classid="clsid:8856F961-340A-11D0-A96B-00C04FD705A2">
          </object>
          <table><tr><td>Name</td><td><rst("Name")%></td>
<td>School</td><td><%rst("school")%></td></tr></table>
</body>
</html>

ayha1999.
0
 
LVL 11

Expert Comment

by:Slimshaneey
ID: 10919443
the function is a vbscript function not a javascript one:

<SCRIPT LANGUAGE=vbcript>

function tsp_sleep(var)
Dim MaxSleep
'Sleep for 20 seconds
MaxSleep = 20
    if var < 1 then
    var = 1
    elseif var > MaxSleep then
    var = MaxSleep
    end if
    dim x
    x = timer
    do until x + var = timer
    ' sleep
    loop
 end function    
     //-->
</SCRIPT>
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:Slimshaneey
ID: 10919451
Put the response.redirect after the sleep function in the print sub.
0
 
LVL 7

Author Comment

by:ayha1999
ID: 10920002
Hi Slimshaaney,

Put the response.redirect after the sleep function in the print sub.

Ok, i changed script to vbscript. this time i get a mesage that "a script on this page is causing Internet Explorer torun slowly. if it continues to run, your computer may become unresponsive. Do you wanto to abort the script?" I clicked "No". then Explorer is freezing and it never redirecting to the search.asp but i prints. how can i avaoid this message and returning back to search.asp page after specied time interval.

the following is the modified code.

<SCRIPT LANGUAGE="vbScript">

function tsp_sleep(var)
Dim MaxSleep
'Sleep for 20 seconds
MaxSleep = 20
    if var < 1 then
    var = 1
    elseif var > MaxSleep then
    var = MaxSleep
    end if
    dim x
    x = timer
    do until x + var = timer
    ' sleep
    loop
 end function      
 
</script>
<script language="vbscript">

SUB Print()
    OLECMDID_PRINT = 6
    OLECMDEXECOPT_DONTPROMPTUSER = 2
    OLECMDEXECOPT_PROMPTUSER = 1
    document.body.focus()
    on error resume next
    call IEWB.ExecWB (OLECMDID_PRINT, -1)
    if err.number <> 0 then
        alert "Nothing Printed"
    end if
   
    'Make it wait 10 seconds
tsp_sleep(10)

Response.Redirect "inHist.asp"

END SUB

</script>

ayha1999.
0
 
LVL 11

Accepted Solution

by:
Slimshaneey earned 250 total points
ID: 10920040
Hmmm.
Try changing the sleep function to this...

Dim MaxSleep
'Sleep for 20 seconds
MaxSleep = 20
    if var < 1 then
    var = 1
    elseif var > MaxSleep then
    var = MaxSleep
    end if
    dim x
    x = timer
    do until (x + var) <= timer
    ' sleep
    loop
 end function  
0
 
LVL 7

Author Comment

by:ayha1999
ID: 10920271
Hi Shamney,

this time a script error in line 17 after that print dialog appears. i dont want print dialog to appear. i think the script error appears because end funtion is there without function.

the following is the modified code.

<SCRIPT LANGUAGE="vbScript">

Dim MaxSleep
'Sleep for 20 seconds
MaxSleep = 20
    if var < 1 then
    var = 1
    elseif var > MaxSleep then
    var = MaxSleep
    end if
    dim x
    x = timer
    do until (x + var) <= timer
    ' sleep
    loop
 end function  

SUB Print()
    OLECMDID_PRINT = 6
    OLECMDEXECOPT_DONTPROMPTUSER = 2
    OLECMDEXECOPT_PROMPTUSER = 1
    document.body.focus()
    on error resume next
    call IEWB.ExecWB (OLECMDID_PRINT, -1)
    if err.number <> 0 then
        alert "Nothing Printed"
    end if
   
    'Make it wait 10 seconds
tsp_sleep(10)

END SUB

Response.Redirect "inHist.asp"
</script>


ayha1999.
0
 
LVL 7

Author Comment

by:ayha1999
ID: 10920492
Hi Shamney,

I fixed funtion problem. now again i get the previous message "a script on this page is causing Internet Explorer torun slowly. if it continues to run, your computer may become unresponsive. Do you wanto to abort the script?"  when i clicked no. it prints but another scripts errors comes, "response.redirect... error.....

ayha1999.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Query not working correctly? (or how i want it to... 6 53
send email part1 9 39
Validating Date 4 28
ASP get fieds value 2 20
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question