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 / October 2003

Tip: Looking for answers? Try searching our database.

Text box in a user form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
harg7769@lineone.net - 16 Oct 2003 15:55 GMT
I have set up a user form to populate a document with the answers and
everything is fine.It all works. Now hoever, I would like to know if
it is possible to setup some sort of rule for some of the fields so
that only data in a certain format can be inserted.

For example, I have a field that should hold a date, but a user can
type whatever they want in there and it will accept it. Is this a
limitation of VBA or can I modify it to only accept a date?

Regards

Andrew Hargreaves
Mark Tangard - 16 Oct 2003 18:16 GMT
Hi Andrew,

You can use the Exit event of the textbox to check the format:

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsDate(TextBox1.Text) Then
   MsgBox "Ey! Gotta be a date here."
   TextBox1.SelStart = 0
   TextBox1.SelLength = Len(.Text)
   Cancel = True
End If
End Sub

--
Mark Tangard, Microsoft Word MVP
Please reply only to the newsgroup, not by private email.
Note well: MVPs do not work for Microsoft.
"Life is nothing if you're not obsessed." --John Waters

> I have set up a user form to populate a document with the answers and
> everything is fine.It all works. Now hoever, I would like to know if
[quoted text clipped - 8 lines]
>
> Andrew Hargreaves
harg7769@lineone.net - 17 Oct 2003 10:41 GMT
Excellent MArk, I'll give that a go.

Thanks

Andrew

>Hi Andrew,
>
[quoted text clipped - 8 lines]
>End If
>End Sub
 
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.