If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Using less than a date in Code
To prevent date mistyping of the new year, I'd like code to run on the
AfterUpdate event of my DateInspected control if the user accidentally inputs a date before 2/28/09 (for instance, 1/4/09 - when it probably should be 1/4/10) My table is storing the date in 2/28/09 format. Here is my code: Private Sub DateInspected_AfterUpdate() If Me.DateInspected 2 / 28 / 2009 Then MsgBox "Please double check the date", vbOKOnly, "Attention" End If End Sub Thanks so much for your help! Pamela |
#2
|
|||
|
|||
Using less than a date in Code
You need
If Me.DateInspected #2/28/2009# You always need the #...# delimiters for a date literal. However, it's not a good idea to make this a fixed date. I'd research the DateDiff function in Access Help. -- Dorian "Give someone a fish and they eat for a day; teach someone to fish and they eat for a lifetime". "Pamela" wrote: To prevent date mistyping of the new year, I'd like code to run on the AfterUpdate event of my DateInspected control if the user accidentally inputs a date before 2/28/09 (for instance, 1/4/09 - when it probably should be 1/4/10) My table is storing the date in 2/28/09 format. Here is my code: Private Sub DateInspected_AfterUpdate() If Me.DateInspected 2 / 28 / 2009 Then MsgBox "Please double check the date", vbOKOnly, "Attention" End If End Sub Thanks so much for your help! Pamela |
#3
|
|||
|
|||
Using less than a date in Code
On Mon, 4 Jan 2010 07:13:01 -0800, Pamela
wrote: To prevent date mistyping of the new year, I'd like code to run on the AfterUpdate event of my DateInspected control if the user accidentally inputs a date before 2/28/09 (for instance, 1/4/09 - when it probably should be 1/4/10) My table is storing the date in 2/28/09 format. Here is my code: Private Sub DateInspected_AfterUpdate() If Me.DateInspected 2 / 28 / 2009 Then MsgBox "Please double check the date", vbOKOnly, "Attention" End If End Sub Thanks so much for your help! Pamela How did you decide on 2/28/09? Will that same date apply in January 2013 (assuming that the Mayan calendar doesn't make the question irrelevant)? Note that dates in Access are NOT stored as text strings. A date is actually stored internally as a Double Float number, a count of days and fractions of a day (times) since midnight, December 30, 1899: ?Now(); CDbl(Now()) 1/4/2010 10:35:23 AM 40182.4412384259 I would suggest instead that you check to see if the date if earlier than (say) ten months in the past: If Me.DateInspected DateAdd("m", -10, Date()) Then MsgBox... You can use the DateAdd, DateDiff, DateSerial and other Date functions to do all sorts of checking; see the VBA help on these functions for details. -- John W. Vinson [MVP] |
Thread Tools | |
Display Modes | |
|
|