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?
Best regards,
ANDy
Jean-Guy Marcil - 01 Mar 2005 14:14 GMT
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
'_______________________________________

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
Doug Robbins - 02 Mar 2005 00:18 GMT
The following code should do what you want:
Private Sub txtSingle_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
Dim i As Long
For i = 1 To ActiveDocument.Characters.Count
If Shift = 0 Then
If Asc(UCase(ActiveDocument.Characters(i))) = KeyCode Then
Calendar.Hide
Else
txtSingle.Text = ""
End If
Else
If Asc(ActiveDocument.Characters(i)) = KeyCode Then
Calendar.Hide
Else
txtSingle.Text = ""
End If
End If
Next i
End Sub
where txtSingle is the control into which the user will enter the character.

Signature
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.
Hope this helps,
Doug Robbins - Word MVP
>
> The single character value a user enters in a text box in my user form,
[quoted text clipped - 7 lines]
>
> ANDy