Date format

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have syntax error???

if (((Date()) Between '6/30/2006' And '9/29/2006')) then
txtDt = 6/30/2006
end if

txtDt is unbound text box.


Help,
Please
 
Date values need to be delimited with "#", not with apothrophes. Your
statement might look like:
if (((Date()) Between #6/30/2006# And #9/29/2006#)) then

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
GGill said:
I have syntax error???

if (((Date()) Between '6/30/2006' And '9/29/2006')) then
txtDt = 6/30/2006
end if

txtDt is unbound text box.


Help,
Please

Try

if Date >= #6/30/2006# And Date <= #9/29/2006# then
me!txtDt = #6/30/2006#
end if
 
Tank you so much.
It works great.

Could tell me what format should I use to show current year,
so where you see '2006' I need to have format showing current year.
Then this code i can use for every year.

if (((Date()) Between '6/30/2006' And '9/29/2006')) then
txtDt = 6/30/2006
end if

Thank you
 
I have syntax error???

if (((Date()) Between '6/30/2006' And '9/29/2006')) then
txtDt = 6/30/2006
end if

txtDt is unbound text box.

The BETWEEN operator works in SQL, but not in VBA - and your
delimiters are wrong, dates are not text strings. Try

If Date >= #6/30/2006# And Date <= #9/29/2006# Then

Will this code need to be rewritten every year, though? What's the
intent - what are you trying to accomplish?

John W. Vinson[MVP]
 
GGill said:
Tank you so much.
It works great.

Could tell me what format should I use to show current year,
so where you see '2006' I need to have format showing current year.
Then this code i can use for every year.

if (((Date()) Between '6/30/2006' And '9/29/2006')) then
txtDt = 6/30/2006
end if

Thank you

Like this?

if Date >= dateserial(year(date), 6, 30) And _
Date <= dateserial(year(date), 9, 29 then
me!txtDt = dateserial(year(date), 6, 30)
end if
 
Great,
Thank you

RoyVidar said:
Like this?

if Date >= dateserial(year(date), 6, 30) And _
Date <= dateserial(year(date), 9, 29 then
me!txtDt = dateserial(year(date), 6, 30)
end if
 
Back
Top