-
May 6th, 2009, 03:42 AM
#1
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
Visual Basic 2005 ver. 8.0.50727.867
-
May 6th, 2009, 06:20 AM
#2
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)
Encourage the efforts of fellow members by rating
Lets not Spoon Feed and create pool of lazy programmers
- ComIT Solutions
-
May 6th, 2009, 06:34 AM
#3
Re: Selecting between 2 dates using variables
Yep sorry shouuld have mentioned that - they are variables!
Will give that a go now . . . .
Cheers
Visual Basic 2005 ver. 8.0.50727.867
-
May 6th, 2009, 06:43 AM
#4
Re: Selecting between 2 dates using variables
That's great - thanks ComITSolutions
Visual Basic 2005 ver. 8.0.50727.867
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|