Date() syntax

alexlds

Registered User.
Local time
Today, 05:03
Joined
May 28, 2012
Messages
71
What I am trying to do is to get an application to quit if anyone uses it after 01/01/2013

This seems to work OK

if date = "01/01/2013" then DoCmd.Quit (ie nothing happens)

but when I then change it to

if date > "01/01/2013" then DoCmd.Quit

it DOES quit ! - and I cant work out why !!

What am I doing wrong?? Can anyone help??
 
Instead of using "" try them with ## as Date() returns the date whihc are not String type but are Date type. so try..
Code:
If Date > #1/1/2013# Then DoCmd.Quit
 
Just a pointer (it shouldn't effect you in this case as you are refering to 1 Jan 2013), when referening to dates using the hash symbol it will look at the date in the USA format os say you wanted to use 12/06/2013 meaning 12 June 2013 the code would change it to read as 06/12/2013 meaning 6 December 2013. You can aviod this by using Long in a Dim Statement.
 
Curiouser and Curiouser said Alice as she went down the rabbit hole . .

With todays date of 23/8/12

If Date > "24/08/2012" Then [Text2] = "yep" (ie testing against tomorrow)
If Date < "24/08/2012" Then [Text2] = "nope"
It returns “nope” - as it should

And

If Date > "22/08/2012" Then [Text2] = "yep" (ie testing against yesterday)
If Date < "22/08/2012" Then [Text2] = "nope"
It returns “yep” - as it should

But when I do

If date > “1/1/2013” then [Text2} = “yep” (ie testing against a 2013 date)

It returns “yep” ! ! ! ! What on earth is going on ??
 
Also note that if your users were already logged in before that date, your code will not fire. But then again, it depends on how you implement it.
 
Hi vbaInet

dont know if you saw my last post. I just cant understand why it works when testing against 2012 dates but falls over when testing against a 2013 date
 
So it should be:
Code:
If Date > Format(Me.Text2, "\#mm\/dd\/yyyy\#") Then
 
But when I do

If date > “1/1/2013” then [Text2} = “yep” (ie testing against a 2013 date)

It returns “yep” ! ! ! ! What on earth is going on ??

Just remember, by putting the date in quotes "1/1/2013" you are comparing TEXT not a date.

Octothorpes (#) are required when using dates. And non-ambiguous dates should really be used. So, yyyy-mm-dd can work, as can 2 AUG 2012 should work (when using the text of the month so there is no confusion about Access wondering what 8/2 and 2/8 are). But using the force formatted U.S. date format like VbaInet showed is the normal way as that also takes care of any regional setting differences.
 
Last edited:
Thanks for the reply

the bit of code i posted was just to illustrate the problem. What I really want to do is publish a compiled accde containing code that will shut it down if anyone tries to use it after 01/01/2013

So you reccon that

If Date > #1/1/2013# Then DoCmd.Quit will work. If so Im happy to use that - but as only a recreational user Im still struggling to understand whats going on - why it works with 2012 dates but not 2013 dates
 
Just seen boblarsens reply - thanks - I think I understand what is happening now !
 

Users who are viewing this thread

Back
Top Bottom