Prev: Form Menu's Question
Next: Syntax Error on DLookup
From: Pamela on 4 Jan 2010 10:13 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
From: Dorian on 4 Jan 2010 10:26 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
From: John W. Vinson on 4 Jan 2010 12:37 On Mon, 4 Jan 2010 07:13:01 -0800, Pamela <Pamela(a)discussions.microsoft.com> 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]
|
Pages: 1 Prev: Form Menu's Question Next: Syntax Error on DLookup |