PDA

View Full Version : Solved: prevent msgbox display



av8tordude
05-25-2011, 12:12 PM
How can I prevent a msgbox from displaying if I'm still focused in the textbox? Currently, if I enter a value over 75.00, I get the msgbox (which works properly when I exit the textbox), but if I never exit the textbox, but close the userform, the msgbox still displays. How can I suppress this from displaying if I'm still focus on the textbox?



Private Sub Amnt_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If CCur(Amnt) > "$75.00" Then
MsgBox "Expenses over $75.00 requires to be substantiated.", vbInformation, "PerDiem Traveler"
frmReceipt.Show
End If
End Sub

Kenneth Hobs
05-25-2011, 12:22 PM
If you don't exit the textbox then the MsgBox will not display. So, I don't see the issue. Why not use another textbox or static text control to show a message? You could also use another Userform to show the message so that you can have more control.

av8tordude
05-25-2011, 01:57 PM
I've tried this code, but doesn't work. Is there a different way to write this

If Amnt.SetFocus Then Exit Sub

GTO
05-25-2011, 07:08 PM
Hi Aviator,

I'd echo Kenneth in considering another label or something for the warning. That said and as you experienced, the exit event will fire if the control has focus when the form is closed. Maybe set a flag?

Option Explicit

Dim bolClosing As Boolean

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Len(TextBox1.Value) < 4 And Not bolClosing Then
MsgBox "Expenses over $75.00 requires to be substantiated.", vbInformation, "PerDiem Traveler"
'frmReceipt.Show
End If
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
bolClosing = True
End Sub

av8tordude
05-26-2011, 10:33 AM
GTO, it's exactly what I was looking for. Thank you