Hi
I'm trying to Select Data from an Access DB.
I wrote this query to Select all Invoices that were Invoiced between two dates.
I get the following error
Syntax error (missing operator) in query expression 'Invoiced >=02/01/13 AND <= 05/01/13'

"SELECT * FROM invoiced_filter WHERE Invoiced > " & fromdte & " AND < " & todte

Thanks in Advence

Recommended Answers

All 5 Replies

I don't have my dev machine so I can't test this but I believe the format for a date value is like

select * from tble where Invoiced > #01/05/2012#

so try

    "SELECT * FROM invoiced_filter " & _
    " WHERE Invoiced > #" & fromdte & "# AND < #" & todte & "#"
commented: correct on date format +6

Thanks Reverend for your reply.
But the error still existes. Accept now the error is
"Syntax error (missing operator) in query expression 'Invoiced > #01/01/13# AND < # 05/01/13#'

        Dim datefrom, dateto As Date

        datefrom = Convert.ToDateTime(Trim(TextBox1.Text))
        dateto = Convert.ToDateTime(Trim(TextBox1.Text))

        Dim cmdload As New SqlCommand(("SELECT * FROM invoiced_filter WHERE invoiced BETWEEN '" & _
                                       datefrom.Date & "'  AND '" & _
                                       dateto.Date & "'"), con.con)

Jim has a minor error in his code:

 "SELECT * FROM invoiced_filter " & _
" WHERE (Invoiced > #" & fromdte & "# AND Invoiced < #" & todte & "#)"

Access also supports the Between statement but it requires the hash mark ("#") as Jim shown.

 "SELECT * FROM invoiced_filter " & _
" WHERE (Invoiced Between #" & fromdte & "# AND Invoiced < #" & todte & "#)"
commented: That's why I like to test these things before posting ;-P +12

Thank You all for your replies
I guess all I was missing from my original QUERY was the table name Invoiced after the AND.
Here is the working QUERY

   SelectQueryString = "SELECT * FROM invoiced_filter & _ 
   WHERE (Invoiced >= #" & fromdte & "# AND Invoiced <= #" & todte & "#)"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.