Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date validation

Status
Not open for further replies.

nicklewis

IS-IT--Management
Feb 7, 2005
21
GB
Right im proberly asking a silly question but ive been playing around with this one for a while and just not seeing what im doing wrong

what i need to do is basically vaildate a date after update by using two text fields as the between dates so if the date netered is between these two datas it will then add for example

txtdatein must be between txttommorow and txtaddmonth
txttommorow automatically picks up tommorows date and txtaddmonth automatically picks up a month tommorow's date
so after txtdatein is updated how do i valiadte this to be inbetween these dates

any help would be much appreciated

Thanks in advance
 
Hi!

Try this:

If txtdatein >(=) txttommorow And txtdatein <(=) txtaddmonth Then
Do your stuff
Else
Do your other stuff
End If

Three things to note. First I put the = sign in parentheses because I didn't know if it was okay for datein to equal either date. Second unless you really need to show tomorrow's date and the date one month later you don't need to put this information in text boxes. Finally this sort of check should be done in the before update event of the control or the form then, if the date doesn't validate you can set Cancel = -1 and the update won't happen.

hth


Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
Hi Jebry
Is it necessary to format the text boxes as dates, if the locale is not US?
 
How are ya nicklewis . . . . .

In the BeforeUpdate event of txtDateIn, try this:
Code:
[blue]   If CDate(txtDateIn) < CDate(txttommorow) Or _
      CDate(txtDateIn) > CDate(txtAddMonth) Then
      MsgBox "Your Error Message Here!"
      Cancel = True
   End If[/blue]

Calvin.gif
See Ya! . . . . . .
 
cheers for your help guys i realised what id done about 2 mins after i sent it to the forum i was used to looking at dates in expression builder not coding its been a while

Cheers for all your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top