Syntax error on date field (1 Viewer)

shery1995

Member
Local time
Today, 12:20
Joined
May 29, 2010
Messages
71
Hi All

I am trying the following line of code:

strCriteria = "[MatterDate] Between " & Format(Me.txtDateFrom, "\#dd\/mm\/yyyy\#) & " And " & Format(Me.txtDateTo, "\#dd\/mm\/yyyy\#")

But getting Syntax error message. Will much appreciate if someone can help to to sort it out.

Many thanks
 

Minty

AWF VIP
Local time
Today, 12:20
Joined
Jul 26, 2013
Messages
10,371
You are missing one closing "

strCriteria = "[MatterDate] Between " & Format(Me.txtDateFrom, "\#dd\/mm\/yyyy\#") & " And " & Format(Me.txtDateTo, "\#dd\/mm\/yyyy\#")
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:20
Joined
Oct 29, 2018
Messages
21,467
Hi. That code will probably result in unexpected outcome anyway. Suggest using the format "yyyy-mm-dd" to avoid potential problems/issues.
 

Gasman

Enthusiastic Amateur
Local time
Today, 12:20
Joined
Sep 21, 2011
Messages
14,269
Also Debug.Print the variable to see the error ?
 

shery1995

Member
Local time
Today, 12:20
Joined
May 29, 2010
Messages
71
Hi. That code will probably result in unexpected outcome anyway. Suggest using the format "yyyy-mm-dd" to avoid potential problems/issues.
Thank you for your reply. Format requirement is dd/mm/yyyy.
 

shery1995

Member
Local time
Today, 12:20
Joined
May 29, 2010
Messages
71
You are missing one closing "

strCriteria = "[MatterDate] Between " & Format(Me.txtDateFrom, "\#dd\/mm\/yyyy\#") & " And " & Format(Me.txtDateTo, "\#dd\/mm\/yyyy\#")
Thank you for your reply. Can you please point where exactly closing is missing?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:20
Joined
May 21, 2018
Messages
8,527
To save typing and get it correct look at the CSQL function
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:20
Joined
Oct 29, 2018
Messages
21,467

Dreamweaver

Well-known member
Local time
Today, 12:20
Joined
Nov 28, 2005
Messages
2,466
I use the below you need to format for a US date

Code:
int([EventDate]) BETWEEN " & Format(Me![txt_From], "\#" & "mm/dd/yyyy" & "\#") & " AND " & Format(Me![txt_To], "\#" & "mm/dd/yyyy" & "\#")
 

shery1995

Member
Local time
Today, 12:20
Joined
May 29, 2010
Messages
71
I use the below you need to format for a US date

Code:
int([EventDate]) BETWEEN " & Format(Me![txt_From], "\#" & "mm/dd/yyyy" & "\#") & " AND " & Format(Me![txt_To], "\#" & "mm/dd/yyyy" & "\#")
Many hanks
 

Gasman

Enthusiastic Amateur
Local time
Today, 12:20
Joined
Sep 21, 2011
Messages
14,269
I can never quite remember the correct syntax and use this that I found on the web.
Code:
Public Const strcJetDate = "\#mm\/dd\/yyyy\#"  'Needed for dates in queries as Access expects USA format.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 07:20
Joined
Feb 19, 2002
Messages
43,263
Using FORMAT() to format a date turns it into a string. Fine for display purposes or when you need to pass a date to SQL Server and it KNOWS it's getting a date. If you format a date into a string, then 01/02/20 is going to be less than 02/01/20 and that would be incorrect if the string were dd/mm/yy.

Strings are evaluated character by character, left to right. So, 2 is > 10000000 if the fields are strings.
 

Users who are viewing this thread

Top Bottom