473,324 Members | 2,248 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,324 software developers and data experts.

HOW CAN I VALIDATE YEAR RANGE(period)

suppose i need only to validate year range for period that is 2014-2016 like this format. it shouldnot accept the value period 2020-2016. how can i give my period first given year should be greater than second given year. kindly help!
Aug 18 '20 #1
4 2976
twinnyfo
3,653 Expert Mod 2GB
aditya7873,

Welcome to Bytes!

First, you tell us nothing about how you are getting your range in the first place. If you are getting the range as one text string, then you will have to approach this problem differently than if you have two text boxes with four digit years that are being entered.

Each approach is going to be significantly different than the other, so rather than guess what you have, we will wait for further details.

Standing by to hepp!
Aug 18 '20 #2
Thank-you for your reply..
The range will be in input format, means it will be done manually.
A User will able to input 2 ranges(years).
example- let text box given called period and input will be done like 2014-2015(in this format only). if the user input wrong input like 2013-2010 which is wrong. 1st year should be greater than 2nd given year.
I hope you got my problem statement.
Aug 19 '20 #3
twinnyfo
3,653 Expert Mod 2GB
That is helpful.

So, I would begin by recommending you have TWO text boxes for Year input. It is a lot easier to manage two numerical values than it is one text value being reinterpreted as numerical values.

For Each text box, you would have something similar to this:

Expand|Select|Wrap|Line Numbers
  1. If IsNumeric(Me.txtStartYear) Then
  2.     If Me.txtStartYear > 999 And Me.txtStartYear < 10000 Then
  3.         [Evaluate with Me.txtYearStop]
  4.         'Final text string will be either
  5.         'Me.txtStartYear & "-" & Me.txtStopYear or
  6.         'Me.txtStopYear & "-" & Me.txtStartYear
  7.     Else
  8.         MsgBox "Enter a four digit year"
  9.     End If
  10. Else
  11.     MsgBox "Please enter a numeric year"
  12. End If
This is generally pretty simple to add such statements behind your form.

Hope this hepps!
Aug 19 '20 #4
cactusdata
214 Expert 128KB
I would also use two fields, but if you insist, here is how:

Expand|Select|Wrap|Line Numbers
  1. Private Sub YourTextbox_BeforeUpdate(Cancel As Integer)
  2.  
  3.     Dim Years   As Variant
  4.  
  5.     Years = Split(Me!YourTextbox.Value, "-")
  6.     If LBound(Years) < UBound(Years) Then
  7.         If Years(LBound(Years)) >= Years(UBound(Years)) Then
  8.             Cancel = True
  9.         End If
  10.     End If
  11.  
  12.     If Cancel = True Then
  13.         MsgBox "The first year must be earlier than the last year."
  14.     End If
  15.  
  16. End Sub
Aug 20 '20 #5

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

Similar topics

7
by: Alexandre | last post by:
Hi again, What's the best I can do to validate fields like date before send my datas. thx
5
by: Andrew | last post by:
Hi, How can I validate a date, like 3/26/04, before submitted? Thanks for any idea. -- Andrew
19
by: Pete | last post by:
I have form/select which executes a function using onchange. No problem. However, when I validate the page with a strict HTML 4.01 doctype at http://validator.w3.org, it demands either an action or...
1
by: MikeinDC | last post by:
I found some free js that I want to use in a class project. The original HTML used <form name="form1"> and the W3C validator I am required to use fails it. It says there is no attribute"name"....
2
by: owz | last post by:
Ok, I am making a program (java class file) 2 work out if a date entered is valid or invalid for the day, month year, and for leap years.. dd/mm/yyyy . I seem 2 have gotten it 2 validate the year...
5
by: Kasrav | last post by:
I have another problem hopeful am not bothering you guys too much if u can help that would be wonderful. I have this code here def year2(): print'This program validates days and months of the...
5
by: kannan1983 | last post by:
I have column in a table which contains year(e.g 2006,2007),here i have to check the values in the column that all are numbers(e.g. it should be like 2006 not like 'a206' or 'abc6'), i have to check...
1
by: kickergirl | last post by:
I'm not sure my title actually describes my problem, but here it goes. I am creating a form to track account information for participants. Basically, a single participant can be offered up to...
1
vavc1980
by: vavc1980 | last post by:
Hello, I have a couple of textboxes where I enter a date range (From - To), I need to validate that the Date From is greater (future) or at least equal to the Date From, or else give an error. ...
3
by: Sushant Panda | last post by:
I m trying to validating xml file against xsd file in vb6.0 but i m getting an error xsd file:(Aces_Dlr.xsd) <?xml version="1.0" encoding="UTF-8"?> <!--W3C Schema generated by XMLSpy v2010...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.