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

validation rule and formatting

Hello everyone. I have a field on a form that is bound to a table that can be either "NA" "TBD" or a date. I have a validation rule on the field like this:

IsDate([Field])=True or "NA" or "TBD"

This works great, but the only problem is that I need the date to be formatted as m/d/yyyy (the don't want leading zeros) and the only place I can think of to set the format is in the table and in the text box properties, and it doesn't work, it accepts any date format. How do I work around this?
Sep 10 '15 #1
1 1517
jforbes
1,107 Expert 1GB
The root problem you are running into is that your Date field isn't strongly typed, meaning that you are storing a Date value into a Text field. This can be done but it is a bad practice and if you have control over your data structure I would recommend putting in the effort to change the field from a Text data type to a DateTime data type.

The reasons that it is a bad practice are many and one of them includes the difficulty that you are running into right now. Other problems will show up when you go to query your data or more importantly when you try to sort or filter your records by this date column. If you store your Dates in a Text field and then sort by that column, they will be sorted alphabetically not chronologically.

So then this hypothetical situation starts to snowball like this: You will then come to the conclusion that you should store your date in yyyy/mm/dd format so that you can correctly order the rows. Then someone wont like how it is displayed and demand that the year get moved to the end. So you will then write a special routine to format it by transposing the year and day, just for reporting. Which will work at first, and then in October it starts acting up because there is now ten digits in the Date instead of nine. So you then decide to convert the text to a date before you format it display and it gets you past the problem. Then someone wants a running total of all outstanding items for the last two weeks and your head explodes because you realize the function to query for the last two weeks worth of data is a complete mess.

...I would strongly recommend to convert your column to a DateTime and an additional field to hold "TBD" and "NA". Actually, I would add a Boolean field to only track "NA" and if the Date field is Null, then consider it "TBD", because that's what a Null field most often means for a Date.

But if you are a glutton for punishment and don't want to do this, you might want to look at the Input Mask for your field. I don't know if it will work, but it might.

If that doesn't work, you might need to add an unbound field to display and edit the Date and hide the current bound field. Then in the OnCurrent event, update the unbound field with the value in the bound field and perform any display magic needed. Then on the unbound fields AfterUpdate Event, update the Bound field with the formatted value using VBA.
Sep 11 '15 #2

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

Similar topics

2
by: Dalan | last post by:
This ought to be simple enough, but not certain which to use. I have a few fields set to Require data to be entered; however, the message displayed by Access 97 is too generic to be of any real...
2
by: Joey P | last post by:
Hi all, I am doing a project for university whereby i have to implement a simple database related to a frozen foods company. I am having some trouble though creating a validation rule for one...
6
by: Chuck | last post by:
A97. A database has a table: tblA which has a single text field, B. It is a primary field, indexed and no duplicates. It is used as a lookup for table tblC. A form based on tblA is used to add...
4
by: ron | last post by:
I have a access based guest book. I want to create a validation rule to block certain words or parts of a srting. How do i do this? ie: this is a nice site. come visit my porn site at www.abc.zy...
1
by: lewy the fly via AccessMonster.com | last post by:
I have a table with a cell formated to Date/Time and I wish to set the validation rule to allow either a date or the letters TBA to be inserted. Is this possible and if so how. -- Message...
10
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the...
3
by: KPR1977 | last post by:
I want to set a validation rule that will not allow me to input data in field1 in TableA that is not found in TableB under field2. Basically, Table B under field 2 has the following row entries: ...
12
alakazamm
by: alakazamm | last post by:
I am building a database on Access 2000 which include a Customer Details table. In this Customer Details table there is a 'Post Code' field which I am required to make an Input Mask to limit the...
1
by: MLH | last post by:
Anyone remember if A97 append query failure would ever report data breaking validation rule when such was not the case. I have an old SQL statement - several years old now. I've encountered a case...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.