Syntax error

J

Jeff

Hi,

Could someone help me to correct the following line. Thank you.

intYounger3Y = DCount("[Name]", "tbRegVacc", "[Birthdate]< DateAdd("y" -3,
"Me![InputBirth]")")
 
M

Marshall Barton

Jeff said:
Could someone help me to correct the following line. Thank you.

intYounger3Y = DCount("[Name]", "tbRegVacc", "[Birthdate]< DateAdd("y" -3,
"Me![InputBirth]")")


I think you probably want something like:

intYounger3Y = DCount("[Name]", "tbRegVacc", _
"[Birthdate] < " & Foramt(DateAdd("yyyy", -3, _
Me![InputBirth]), "\#yyyy-m-d\#"))
 
K

kismert

Try:

intYounger3Y = DCount("[Name]", "tbRegVacc", "[Birthdate]<#" & DateAdd("y",
-3, Me![InputBirth]) & "#")
 
R

RonaldoOneNil

Neither of the above 2 will work beacuse of the quotes around the yyyy in the
dateadd function. Try this

Dim dtCheckDate As Date

dtCheckDate = DateAdd("yyyy", -3, Me!InputBirth)
Me.intYounger3Y = DCount("[Name]", "tbRegVacc", "[Birthdate]< #" &
dtCheckDate & "#")
 
D

Douglas J. Steele

And, in fact that likely won't work as expected if the user has his/her
Short Date format set to dd/mm/yyyy, since Access typically does not respect
Regional Settings in SQL statements (which is what a Domain Aggregate
function such as DCount boils down to)

Me.intYounger3Y = DCount("[Name]", "tbRegVacc", _
"[Birthdate]< " & Format(DateAdd("yyyy", -3, Me!InputBirth),
"\#yyyy\-mm\-dd\#")))


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


RonaldoOneNil said:
Neither of the above 2 will work beacuse of the quotes around the yyyy in
the
dateadd function. Try this

Dim dtCheckDate As Date

dtCheckDate = DateAdd("yyyy", -3, Me!InputBirth)
Me.intYounger3Y = DCount("[Name]", "tbRegVacc", "[Birthdate]< #" &
dtCheckDate & "#")

Jeff said:
Hi,

Could someone help me to correct the following line. Thank you.

intYounger3Y = DCount("[Name]", "tbRegVacc", "[Birthdate]<
DateAdd("y" -3,
"Me![InputBirth]")")
 
M

Marshall Barton

RonaldoOneNil said:
Neither of the above 2 will work beacuse of the quotes around the yyyy in the
dateadd function. Try this

Dim dtCheckDate As Date

dtCheckDate = DateAdd("yyyy", -3, Me!InputBirth)
Me.intYounger3Y = DCount("[Name]", "tbRegVacc", "[Birthdate]< #" &
dtCheckDate & "#")


Well, kismet only had a single y (day of the year), so
that's why it wouldn't work, but the quotes in both replies
are correct.

OTOH, as Doug said, using the Format function is also
necessary unless you can guarantee that every machine that
ever runs the application has its regional date settings
exactly the way you need them to get your code to work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top