Cancel does not work in a sub - Can sb help please?

Ritzl

New Member
Joined
May 16, 2015
Messages
16
Hi all,
I have a small user form which shoes a countdown in seconds, then it closes and goes back to the main Routine and executes some staff (this repeates several times). Now my propblem, I have a cancel button on the form but I can not press it, resp. nothing happens, any idea why. I want to achieve that the cancel button aborts the countdown, closes the user form and goes back to the main program:

Code:
Private Sub CancelBtn_Click()
                                                    '  MsgBox ("Exit procedure cancel Btn....")
        CancelBtn = True
        Me.Hide
End Sub


Private Sub UserForm_Activate()
  For iz = 1 To interval
    Label2.Caption = interval - iz
     If WaitingTime.CancelBtn Then                   ' MsgBox ("Exit procedure....")
         iz = interval - iz
         Unload Me
     End If
     Application.Wait (Now + #12:00:01 AM#)
     WaitingTime.Repaint
  Next iz
    Unload Me
End Sub

Thank you very much for your help ! Cheers Marc
 
Last edited by a moderator:

Some videos you may like

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,427
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Are you sure the name of the button is correct? Also, why are you setting the value of the button to True in it's click event? You shouldn't do that.
 

Ritzl

New Member
Joined
May 16, 2015
Messages
16
Hi Thx for answering
Yes, the Name in the properties is CancelBtn

The Problem is, that if im press the CommandButton (Cancel), nothing happens. I tried with a msgBox but it was never showed so it seems the button is not active. Any ideas why that could be?
(I put the msg box as comment so you can see where it was)
Thx Marc
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,427
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Either that isn't the correct name or the code is not rated by the user form code module.
 

Ritzl

New Member
Joined
May 16, 2015
Messages
16

ADVERTISEMENT

Either that isn't the correct name or the code is not rated by the user form code module.

Is the a way to send you a print screen about the properties or the whole code? What do you mean by" the code is not rated by the user form..." anything I can do?
my email: ritzl@hispeed.ch
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,427
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Sorry that was phone autocorrect. I meant the code is not contained in the user form code module.
 

Ritzl

New Member
Joined
May 16, 2015
Messages
16
Hi Rory, sorry was a few days away....I am new to VBA and do not understand what to do. Would you be so kind to show my step by step what I need to do ? would you mind if I email you my file...this might be easier. (I stated my email above in an earlier thread). thx in advance...kind regards Marc
 

Watch MrExcel Video

Forum statistics

Threads
1,127,117
Messages
5,622,827
Members
415,934
Latest member
adstocking

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top