A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Using less than a date in Code



 
 
Thread Tools Display Modes
  #1  
Old January 4th, 2010, 03:13 PM posted to microsoft.public.access.forms
Pamela
external usenet poster
 
Posts: 193
Default 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  
Old January 4th, 2010, 03:26 PM posted to microsoft.public.access.forms
Dorian
external usenet poster
 
Posts: 542
Default 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  
Old January 4th, 2010, 05:37 PM posted to microsoft.public.access.forms
John W. Vinson
external usenet poster
 
Posts: 18,261
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:57 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.