UserForm Mouse click on form to close


I have a Userform1 setup which works great, also using UserForm1_click() so when its clicked it shuts down which works....

Now I have added a application.wait (30 secs) setup and now clicking on the form no longer works as its waiting for the 30 second timer, is there a way to add a delay of 30 seconds before the form closes but still although clicking on the form to close it?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
Instead of using Application.Wait, use the Wait30 sub I show here. In this code I have a command button calling the sub but you would probably need to call it from somewhere else.

Option Explicit
Private mbClicked As Boolean

Private Sub CommandButton1_Click()
End Sub

Private Sub UserForm_Click()
mbClicked = True
End Sub

Sub Wait30()
Dim dteTime1 As Date
Dim dteTime2 As Date

dteTime1 = Now
dteTime2 = Now + TimeValue("0:00:30")
    Do Until dteTime1 >= dteTime2
        If mbClicked Then
            Unload Me
            Exit Sub
        End If
        dteTime1 = Now()

End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MirageSFAuthor Commented:
Oh, very nice and worked a treat thank you.
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

If you expand the “Full Biography” section of my profile you'll find links to some articles I've written that may interest you.

Marty - Microsoft MVP 2009 to 2017
              Experts Exchange MVE 2015
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2017
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.