HI I have a userform with a textbox that will not let you exit it if it is empty. This works great until I want to exit the userform and click a command button to leave and it asks me to enter a batch no.

I found a old post suggesting the following
Dim bflag As Boolean



Private Sub supplierpricetxt_Exit(ByVal Cancel As MSForms.ReturnBoolean)

If bflag = True Then Exit Sub
  
  
    If supplierpricetxt = "" Then
    MsgBox "Please enter a Batch No."
    
    Cancel = True
    Exit Sub
    End If
End Sub


Private Sub cmdClearAndExit_Click()
bflag = True
Unload Me
End Sub
However this does not seem to work for me even though the logic seems fine. Am I missing something or is there alternative ways around this problem.