Validation in txt boxes

baz7621

Registered User.
Local time
Today, 19:56
Joined
Mar 26, 2004
Messages
10
Hiya all!

I have a form and I have a txtbox called txt_year. In this txt box I want the user to enter the year of the date in the format of yyyy eg.// 2004

How do I put validation on this txt box so that the value entered is in the format of yyyy??

Fanx all
 
You can use the input mask of your text box to force the user to enter four numbers. Use something like 0000.
 
ok thats well enough 2 use an input mask but whats 2 stop the user entering 9999 0111 1900 etc as the date?
 
baz7621 said:
ok thats well enough 2 use an input mask but whats 2 stop the user entering 9999 0111 1900 etc as the date?

You could create a table (or value list) with the years you want to limit the users entry to. Then use the "Limit to List" option. (You wouldn't even have to mess with the format then.)
 
Hiya fanx so far but i see one problem:

If i create a table of dates for example 2000 through to 2005 then any year after 2005 will not work.


So I thought about it and came up with this but it doesnt work. What i want it to do is get the year from the system clock and the start year is 2000 therefore if today_days date is less than or equal to start_date then view report else produce a message box.


Code:
Dim todays_date As Date

Dim start_date As Date

todays_date = Year(Date)

start_date = Year(2000)

If todays_date <= start_date Then

    Dim stDocName As String

    stDocName = "Best Selling Items"
    DoCmd.OpenReport stDocName, acPreview

Else
    MsgBox "Invalid year"


Would it be possible for someone 2 change mine so it works or create a new IF statement

Fanx in advance
 
Why not just use the Calendar Control for date selection?
 
Mile-O-Phile said:
Why not just use the Calendar Control for date selection?


I am sorry but i dont know what you mean by Calendar Control :o Can you explain please i am new 2 vba
 
Have a look in the Sample Databases forum for one of my Calendar Examples. :cool:
 

Users who are viewing this thread

Back
Top Bottom