and was telling us:
and nous racontait que :
The single character value a user enters in a text box in my user
form, should be validated (checked whether it already exists in the
active document). The user box should stay visible until a value is
entered that does not exist in the active document.
How can I approach this problem? With a while loop?
Something like this should get you started. Here I assumed that letter case
was irrelevant, if it is relevant, remove the LCase() from the code. Also,
to test this idea, the value to be checked against in the document has to be
delimited by a bookmark which is called "CharValue" in this example. You
could call it whatever you want, just change the code accordingly.
Insert this code in the userform code panel and change TextBox1 to fit you
textbox name.
'_______________________________________
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If LCase(Me.TextBox1.Value) = _
LCase(ActiveDocument.Bookmarks("CharValue").Range.Text) Then
MsgBox "Invalid value, try again."
Me.TextBox1.Value = ""
Cancel = True
End If
End Sub
'_______________________________________
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:
http://www.word.mvps.org