Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2005

Tip: Looking for answers? Try searching our database.

stop-validate user input in a form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
and - 01 Mar 2005 09:00 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.