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
- option explicit
-
dim boo1 as boolean
-
sub importing()
-
dim i as integer
-
boo1=false
-
i=1
-
do
-
if i > 50000 then exit do
-
if boo1=true then exit sub 'the command will change the boolean
-
cells(i,1).value = "hello world"
-
i=i+1
-
doevents 'This is the important thing here
-
loop
-
end sub
-
-
'---------------Here is the code for the command button---------
-
sub commandbutton1_click()
-
boo1=true
-
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