Format query date field with code

D

David McKnight

I get an Expected end expression error with the following code at point of
"mmdd". What is missing here?

qdf.SQL = _
"SELECT Table1.Yearof, Table1.Dateof, " & _
"Table1.Nameof, Table1.Valueof FROM Table1 " & _
"INNER JOIN Table5 " & _
"ON Table1.Yearof = Table5.Yearof " & _
"WHERE " & _
"Format([Table1.Dateof], "mmdd") >= '1115' AND " & _
"Format([Table1.Dateof], "mmdd") <= '1215';"
 
O

Ofer

Remove the square brackets or put them for each word

Yours
"WHERE " & _
"Format([Table1.Dateof], "mmdd") >= '1115' AND " & _
"Format([Table1.Dateof], "mmdd") <= '1215';"

Try
"WHERE " & _
"Format(Table1.Dateof, "mmdd") >= '1115' AND " & _
"Format(Table1.Dateof, "mmdd") <= '1215';"
Or
"WHERE " & _
"Format([Table1].[Dateof], "mmdd") >= '1115' AND " & _
"Format([Table1].[Dateof], "mmdd") <= '1215';"
 
O

Ofer

Sory, also chenge the double quote to single quote in the format

Yours
"Format([Table1.Dateof], "mmdd") >= '1115' AND " & _
"Format([Table1.Dateof], "mmdd") <= '1215';"

Change to
"Format(Table1.Dateof, 'mmdd') >= '1115' AND " & _
"Format(Table1.Dateof, 'mmdd') <= '1215';"
 

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