Force Quitting A Procedure

  • Thread starter Thread starter Aaron
  • Start date Start date
A

Aaron

Hello,

I am still fairly new to Access and VBA so there might not even be a way to
do this, but what I have is a subroutine that writes to a word document.
Since this word document is fairly large it takes a couple of seconds to
write to the document. If the user accidentally selects and executes the
option that writes to the word document, the user is forced to wait until the
document is finished being written too or to force close MS Access. Both of
these actions are undesirable.

What I would like to know if there is way that the user can force quit the
subroutine, or to stop writing to the document and close the document by
pressing a button on a form or even pressing a key on the keyboard would work
too. Keep in mind that the word document isn't visible until the subroutine
is finished writing to the document.

I have not found any solutions so far, so any help or even sample code would
help a ton.

Thanks for any help in advance,
Aaron
 
If you're using Automation you aren't a totally raw beginner.

What you can do will be determined by how you go about what you're
doing. If you are writing a single monolithic string to Word then
that would have to change.

if you have several interim points in the write operation into which
some code can be inserted then you can get it done. It not already
broken up you might create a loop in which you write just a hundred
characters or so of the output string and work your way through the
string that way.

Something that may help or ideas you can use:

Put a command button on the relevant form. Name it cmdPrintToggle.
Set its caption to "Stop Print". In the Click event of that button
put some code

'The caption indicates what will be enabled after this code executes.
if me!cmdPrintToggle.caption="Stop Print" then
me!cmdPrintToggle.caption="Print OK"
else
me!cmdPrintToggle.caption="Stop Print"
endif

In the loop that writes the segments of the text to Word put something
like

DoEvents
If me!cmdPrintToggle.caption="Print OK" then
........execute any cleanup code
.........
exit sub
endif

HTH
 
Back
Top