UserForm Mouse click on form to close

Hi,

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?
MirageSFAsked:
Who is Participating?
 
Martin LissConnect With a Mentor Older 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()
Wait30
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
        DoEvents
        dteTime1 = Now()
    Loop

End Sub

Open in new window

0
 
MirageSFAuthor Commented:
Oh, very nice and worked a treat thank you.
0
 
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.