By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,830 Members | 682 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,830 IT Pros & Developers. It's quick & easy.

Screen Refresh

P: n/a
I am doing a import of a file in to access. I have a form that is
updated for every record and every file that is imported. I would
like to be able to start and stop the process. However when I start
the process I am unable to stop it. All controls to the form are
lost. I think when I make the call to do the import module the
function will not continue till the module it called has finished
running. Is there a way to tell it to run this function but dont wait
for it to finish?
Thanks for you help,
Kirk
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

There is only one thread running during VBA execution. So,...

In the called function use he DoEvents command. It will temporarily
stop the running code & allow other objects to raise an event.

It sounds like your called function is looping so try something like
this:

Set up a global variable in a standard module:

Public blnStopFunction As Boolean
==================

In the called function's loop do something like this:

Do While Not Eof(#inputFile)
..... file handling stuff
DoEvents
' Did user click the stop button
If blnStopFunction = True Then Exit Do
Loop

If blnStopFunction Then ... clean up open file then exit function

===============

On the form that calls the function, have a button, "Cancel," that sets
the blnStopFunction variable = True. When the DoEvents runs in the
called function loop, the click on the Cancel button will set the
blnStopFunction. The blnStopFunction check in the loop will determine
if the Cancel button has been clicked & if the routine should continue.
Be sure to clean up the file handling before returning to the calling
code (close the file, etc.).

Have some code in the calling code that will also check to see if the
called function completed or was cancelled - just check blnStopFunction
to see if it is True. Be sure to re-set to False afterward (so you can
call the function again w/o premature cancellation. Better yet, set the
variable to False before the initial call to the file handling function.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQSaKfIechKqOuFEgEQKChQCgy7g+Gcaeh7mFWMfFwOViQC uOiKQAoK2g
1EtLg77asvHnOFOph0u+YxRx
=0OcL
-----END PGP SIGNATURE-----
Kirk wrote:
I am doing a import of a file in to access. I have a form that is
updated for every record and every file that is imported. I would
like to be able to start and stop the process. However when I start
the process I am unable to stop it. All controls to the form are
lost. I think when I make the call to do the import module the
function will not continue till the module it called has finished
running. Is there a way to tell it to run this function but dont wait
for it to finish?


Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.