Hi Adi,
The thing that makes the userform go away is a statement at the end of the
OK click procedure that says either Unload Me or Me.Hide (depending on how
the userform was created). If the data entry fails validation, that
statement should not be executed.
One way to do this is to place an Exit Sub statement immediately after the
error MsgBox for each validation test. This simply skips all the remaining
tests and puts the user back in control of the userform. The next time they
click the OK button, all the validatioin will be done again.
Some programmers feel strongly that each procedure should have a single
entry point and a single exit point, and multiple Exit Sub statements
violate that principle. The alternatives are (1) to make all the validation
tests in a series of nested If .. Then clauses or (2) to maintain a Boolean
(True/False) variable that starts as False and is set to True if any test
fails, and execute the Unload statement only if that Boolean is still False
at the end of the procedure. This is suitable for a large procedure with a
dozen or more tests, but it's overkill for the usual small one.
You test option buttons by looking at their .Value properties -- if they're
all False, no button has been selected. (You can avoid having to validate
this if the Userform_Initialize or Userform_Activate procedure sets the
.Value for one option button to True. There's then no way for the user to
deselect any button without selecting a different one.)
Here's some sample code:
Private Sub CommandButton1_Click()
If TextBox1.Text = "" Then
MsgBox "Please fill the text box"
Exit Sub
End If
If (OptionButton1.Value = False) And _
(OptionButton2.Value = False) Then
MsgBox "Please select one option"
Exit Sub
End If
Unload Me
End Sub

Signature
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
> Hi,
>
[quoted text clipped - 22 lines]
>
> Many thanks to anyone who can help!