Connecting Tech Pros Worldwide Help | Site Map

Activate the current window

Newbie
 
Join Date: Dec 2006
Posts: 7
#1: Aug 29 '07
Hi,

I have written some macro in VBA. It has 2 buttons one is SUBMIT and another is CANCEL. When i click on SUBMIT then it calls access and populate the data in another excel file and takes around 20-30 minutes to populate/complete the process. What I want is on click on CANCEL it should stop the process.

Any help will be appreciated.
kadghar's Avatar
Expert
 
Join Date: Apr 2007
Location: Mexico City
Posts: 1,155
#2: Aug 29 '07

re: Activate the current window


Quote:

Originally Posted by Probleminfinity

Hi,

I have written some macro in VBA. It has 2 buttons one is SUBMIT and another is CANCEL. When i click on SUBMIT then it calls access and populate the data in another excel file and takes around 20-30 minutes to populate/complete the process. What I want is on click on CANCEL it should stop the process.

Any help will be appreciated.

Hi, if you're using DO of FOR in your code that will make a DoEvents work that.
imagine you have your sub called Importing and commandbutton1 will stop it

Expand|Select|Wrap|Line Numbers
  1. option explicit
  2. dim boo1 as boolean
  3. sub importing()
  4. dim i as integer
  5. boo1=false
  6. i=1
  7. do
  8.     if i > 50000 then exit do
  9.     if boo1=true then exit sub   'the command will change the boolean
  10.     cells(i,1).value = "hello world"
  11.     i=i+1
  12.     doevents 'This is the important thing here
  13. loop
  14. end sub
  15.  
  16. '---------------Here is the code for the command button---------
  17. sub commandbutton1_click()
  18. boo1=true
  19. end sub
well that's the main idea
and sorry if im curious, have you tried importing your Access data into an array and asigning the array into a range, that should be quite fast.

Good Luck
Reply