473,322 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Stop Loop and return to program code error

I want loop to stop if cancel is clicked and eturn to program. Here is my code. Stumped - sorry if it's basic.
Expand|Select|Wrap|Line Numbers
  1. Do while not EOF
  2. .
  3. .
  4. .
  5. .
  6. Printer.EndDoc
  7. If Label9 = 5 Then ' use 20 for production
  8. Label9 = 0
  9. intpress = MsgBox("Print NEXT batch? (NO will cancel printing)?", vbQuestion + vbOKCancel, "Continue?")
  10. If intpress = vbCancel Then
  11. End ' Think problem here!
  12. Else
  13. End If
  14. End If
  15. Loop
  16. Close ifile
  17. End Sub
Oct 25 '10 #1
2 1100
Stewart Ross
2,545 Expert Mod 2GB
Hi. Use Exit Sub if you want to jump out of your subroutine at line 11 above. However, this will simply stop the sub altogether and will not close any open file cleanly. I'd suggest redesigning your sub so that you use a boolean variable of some kind as part of your loop test:

Expand|Select|Wrap|Line Numbers
  1. Dim blPrintMore as Boolean
  2. blPrintMore = True
  3. Do while Not EOF And blPrintMore
  4. ..
  5.  blPrintMore = Not intPress = vbCancel
  6.  if blPrintmore then
  7.   'your print section here
  8.  End If
  9. Loop
-Stewart
Oct 25 '10 #2
Thank you!
Oct 26 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Sier | last post by:
CL_ConsoleWindow console("Console"); Is this some c++ idiom or a macro? I know you can't tell without the headers, but I want a quick explanation.
3
by: RobertTG | last post by:
Someone please translate the code below into English... Particularly the indicated line Thanks function attachComment() { var aForms = document.getElementsByTagName("FORM"); for (var i = 0;...
16
by: Mars | last post by:
I am reading the code of a program from the examples, but really don't understand this one........ int i,j; ..................................................... while (scanf("%d",&i),j) {...
13
by: dbuchanan | last post by:
This code resets a form with two cbo's (comboBoxes) and one datagrid. The first cbo (cboSelection) selects a main table and filters the second cbo. The second cbo (cboView) selects the secondary...
9
by: oddvark | last post by:
Hello, under vc7.1 this code compiles: if (!parent.fillTool) parent.fillTool.dispose; where dispose is a method of fillTool. Notice that dispose does not have ( ) behind it. Under vc8,...
5
by: lucas | last post by:
is a javascript file; is ajax? or javascript but in hidden code? eval(function(p,a,c,k,e,d) {e=function(c)...
1
maher5
by: maher5 | last post by:
hi i had some help completing my assignment which i still dont understand fully. i dont know what this bit of the code means/do. the assignment was the morse code convertion. ...
9
by: James Dow Allen | last post by:
How about this idea? Post fragments of C code which seem fun, interesting or instructive. Puzzles can be posed in various ways. (What does this do? Can you see the bug? How to code this for...
3
by: qianz99 | last post by:
Hi I am not sure what this code does. I have the following questions 1. where is the case? 2. #define TLV_INTEGER(name, octets) p->name = -1; Is it define a function TLV_INTEGER(name, octets) ...
6
by: sbcs | last post by:
I'm a website developer. Recently I've found variations of this code on the home pages of several of my sites. It triggers warnings in some anti-virus/malware programs but not in others. The pages...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.