Selecting between 2 dates using variables
Hi
I have a small problem with the SQL statement that returns the information from an Access 2003 table based on the dates input by the user. IT works fine if I manually code the dates as below:
Code:
Dim da As New OleDb.OleDbDataAdapter("Select * From Sanctions Where [Date] BETWEEN #01/04/2009# AND #30/04/2009# AND [Group] Like '%EN%' AND [Description] <> 'Merits' ", cnDept)
but if I try to put ther variables in the statement like:
Code:
Dim da As New OleDb.OleDbDataAdapter("Select * From Sanctions Where [Group] Like '%EN%' AND [Date] BETWEEN # SDate # AND # FDate # AND [Description] <> 'Merits' ", cnDept)
it returns a syntax error.
Can anyone help me with the syntax of this statement please? I am sure I have used variables in this way before for dates.
Thanks in advance ;)
Re: Selecting between 2 dates using variables
Is SDate and FDate are Varaibles?
If So then try this
Code:
Dim da As New OleDb.OleDbDataAdapter("Select * From Sanctions Where [Group] Like '%EN%' _
AND [Date] BETWEEN #" & SDate & "# AND #" & FDate & "# AND [Description] <> 'Merits' ", _
cnDept)
Re: Selecting between 2 dates using variables
Yep sorry shouuld have mentioned that - they are variables!
Will give that a go now . . . .
Cheers
Re: Selecting between 2 dates using variables
That's great - thanks ComITSolutions ;)