- Local time
- Today, 14:02
- Joined
- Feb 19, 2002
- Messages
- 46,224
The suggestions to use the Control's BeforeUpdate event or the Form's BeforeUpdate event should put you on the right track. Validation MUST be done in an event which allows you to cancel the update. Otherwise, you get a lot of warning messages but bad data still gets saved. At the end is a link to a couple of videos as well as a database which will help you to understand how control and form events actually work.
BUT, the problem could be with the date field. How are you populating it? If you are using Now() which populated the date AND the time, you will NEVER succeed with finding a specific date using a time value. WHY? Dates are stored internally as double precision numbers. They are NOT strings. The integer portion of the number is the number of days since 12/30/1899 (for Jet/ACE) and the decimal is the elapsed time since midnight.
Here's an example that shows the problem.
Print now() --- print the value of Now
12/10/2024 2:38:17 PM
print cdbl(#12/10/2024 2:38:17 PM#) --- Print the actual stored value
45636.6099189815
print cdate(45636.6099189815) --- back the other way so you can see it is the same date
12/10/2024 2:38:17 PM
Print cdate(45636.609918) --- slightly modify the date but it comes up the same string
12/10/2024 2:38:17 PM
print cdate(45636.60991855) --- slightly modify the date but it comes up the same string
12/10/2024 2:38:17 PM
print cdate(45636.6099186666) --- slightly modify the date but it comes up the same string
12/10/2024 2:38:17 PM
SO. The realty is there are a lot of values for 2:38:17 PM but none will match. To get a match, you would have to know what the underlying stored value is. You can't search using a string.
BUT, the problem could be with the date field. How are you populating it? If you are using Now() which populated the date AND the time, you will NEVER succeed with finding a specific date using a time value. WHY? Dates are stored internally as double precision numbers. They are NOT strings. The integer portion of the number is the number of days since 12/30/1899 (for Jet/ACE) and the decimal is the elapsed time since midnight.
Here's an example that shows the problem.
Print now() --- print the value of Now
12/10/2024 2:38:17 PM
print cdbl(#12/10/2024 2:38:17 PM#) --- Print the actual stored value
45636.6099189815
print cdate(45636.6099189815) --- back the other way so you can see it is the same date
12/10/2024 2:38:17 PM
Print cdate(45636.609918) --- slightly modify the date but it comes up the same string
12/10/2024 2:38:17 PM
print cdate(45636.60991855) --- slightly modify the date but it comes up the same string
12/10/2024 2:38:17 PM
print cdate(45636.6099186666) --- slightly modify the date but it comes up the same string
12/10/2024 2:38:17 PM
SO. The realty is there are a lot of values for 2:38:17 PM but none will match. To get a match, you would have to know what the underlying stored value is. You can't search using a string.
Bad Data is Bad for Business #1 and #2
I just added #2 --- that link is further down. It is much shorter than #1. I also added a copy of the database I used for the video. Enjoy:) I created a database to help people to understand how and why to use the Form's BeforeUpdate event to validate data. @Uncle Gizmo and I made a...
www.access-programmers.co.uk