Solved

automatically print redirected to the specified Page

Posted on 2004-04-26
8
736 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
 
LVL 11

Expert Comment

by:Slimshaneey
ID: 10919451
Put the response.redirect after the sleep function in the print sub.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now