473,397 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

date entry msgbox: validation

Please help, what do i add to my code so it displays the message only after 4 digits are entered in the text box. At the moment it pops up after one keystroke.


Private Sub txtYear_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtYear.TextChanged

Dim Year As Integer
Year = txtYear.Text
If Year < 1900 Or Year > 2100 Then MsgBox(" Please enter a year between 1900 and 2100 ")

kind regards
Jul 17 '07 #1
6 1711
danp129
323 Expert 256MB
Not sure if this will work in .Net

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtYear_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtYear.TextChanged
  2.  
  3. Dim Year As integer
  4. if len(txtYear.Text) <4 then exit sub
  5.  
  6. if not isnumeric(txtYear.Text) then
  7.     msgbox "Numbers only please"
  8.     exit sub
  9. end if
  10. Year = cint(txtYear.Text)
  11. If Year < 1900 Or Year > 2100 Then MsgBox(" Please enter a year between 1900 and 2100 ")
  12.  
  13. end sub
Jul 17 '07 #2
also

Expand|Select|Wrap|Line Numbers
  1.   If Year < 1900 Or Year > 2100 And len(txtyear.text) < 4 Then MsgBox(" Please enter a year between 1900 and 2100 ")
  2.  
that should also work depending on if you need more actions later on with this variable depends which way you would do it.
Jul 17 '07 #3
Killer42
8,435 Expert 8TB
Expand|Select|Wrap|Line Numbers
  1.   If Year < 1900 Or Year > 2100 And len(txtyear.text) < 4 Then MsgBox(" Please enter a year between 1900 and 2100 ")
  2.  
Seems to me, the "> 2100" test can never trigger the message box, because it would fail the "length < 4" test.

Perhaps a better approach is that seen in some programs, where the text changes colour to indicate whether it is currently valid. For example, if you started typing "2007" the text would be red (or highlighted somehow) until you got the "7" in there, then switch back to normal colour.

The final test and "dummy spit" (message box) should happen when the user leaves the textbox, or clicks "OK", or whatever happens to indicate they are finished entering the year. The Validate event procedure is probably a good place to do that.
Jul 18 '07 #4
thanks, i've used the validate event but when i set the errorprovider (using validating as per the link), vb tells me errorprovider1 is not part of my file. is this a library issue or does it need declaring?

http://msdn2.microsoft.com/en-us/lib...alidating.aspx
Jul 19 '07 #5
no worries done this now, thnx
Jul 19 '07 #6
Killer42
8,435 Expert 8TB
no worries done this now, thnx
So that's all sorted out now, is that right?
Jul 19 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Gord | last post by:
Hello, VB6 accepts Date and Time values as 'Date'. I'm trying to verify entry into a database I'm creating by verifying that an appropriate Date or Time value has been entered. Using built-in...
30
by: Dr John Stockton | last post by:
It has appeared that ancient sources give a method for Numeric Date Validation that involves numerous tests to determine month length; versions are often posted by incomers here. That sort of code...
2
by: Lyn | last post by:
Hi, I have a text control on a form which is bound to table field StartDate which is in Date format. When updating the table record via the form, any data entered into the StartDate control is...
1
by: Rob | last post by:
How can I create a validation rule for only allowing two specific dates but with variable years: 1/1/yyyy or 12/1/yyyy so only the dates 1/1/2004 or 1/1/1999 or 12/1/2001 etc. I tried...
17
by: Petyr David | last post by:
Just looking for the simplest. right now my perl script returns an error messge to the user if the date string is invalid. would like to do this before accessing the server. TX
16
by: Mik | last post by:
I apologise if this post seems a little basic, but I am a newbie and have NO access knowledge. I have downloaded the Accounts Ledger from the Microsoft Website. It allows the user to review a...
4
by: SilentThunderer | last post by:
Hey folks, Let me start out by letting you know what I'm working with. I'm building an application in VB 2005 that is basically a userform that employees can use to "Clock in". The form...
3
by: Harlequin | last post by:
I must start this posing by making the point that I am NOT a VB programmer and I'm something of a Newbie to MS Access. I can program in a number of languages (Java, Javascript, PERL,PHP and TCL) but...
4
beacon
by: beacon | last post by:
Hi everybody, I'm really hoping this will be the last problem I run into because I don't have much hair left to pull out! :) I have a form that the user will enter a census date (indexed field)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.