user3883116
user3883116

Reputation: 37

VBA: Message Userform to popup and remain active in front of all applications if the VBA main Userform is running in background

I have created a VBA code in which a message userform pops up after taking a certain action. the problem is that when the VBA main userform is running in the background (behind another active application), the message userform pops up, but remains in the background only and does not come forward, ahead of all active applications. Is there a way to bring it ahead of all active applications? Thanks, this would be really helpful.

Part of my code is below:

Private Sub CheckBox1_Click()

X1 = Now

If CheckBox1.Value = True Then TextBox1.Value = Now
If CheckBox1.Value = False Then TextBox1.Value = Null

If CheckBox1.Value = True Then TextBox2.Value = "00:00:00"

TextBox1.BackColor = vbYellow
TextBox2.BackColor = vbYellow

If CheckBox1.Value = True And CheckBox6.Value = False Then
   nTimer = nCounter
   Call RunTimers
End If

If CheckBox1.Value = False Then TextBox2.Value = Null


End Sub


Public Sub RunTimers()    ' Hypothesis initial and Management Bridge on Validation action

 If nTimer > 1 Then

        nTimer = nTimer + 1
        UserForm1.lblsla1.Caption = Format(TimeSerial(0, 0, nTimer), "hh:mm:ss")
        Application.OnTime Now + TimeSerial(0, 0, 1), "RunTimers"


    If nTimer = 1500 Then    '25 minutes
    'MsgBox "HY IS DUE IN NEXT 5 MINUTES", vbOKOnly, reminder
    HYIReminder.Show
    End If

    If nTimer = 12600 Then   '3.5 hours
    'MsgBox "MB IS DUE IN NEXT 5 MINUTES", vbOKOnly, reminder
    MBReminder.Show
    nTimer = 0
    End If

    If UserForm1.CheckBox1.Value = False Then
       nTimer = 0
       UserForm1.lblsla1.Caption = ""
    End If

 End If

End Sub

Upvotes: 1

Views: 5643

Answers (1)

Bernard Saucier
Bernard Saucier

Reputation: 2260

Try changing :

MBReminder.Show
HYIReminder.Show

To :

MBReminder.Show vbModeless
HYIReminder.Show vbModeless

Some details on Modeless VS Modal forms. Not necessary to go through it, just the first few lines should be enough!

Upvotes: 2

Related Questions