CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2002
    Location
    Tenby, Wales
    Posts
    277

    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

  2. #2
    Join Date
    Feb 2008
    Location
    Bangalore
    Posts
    149

    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

  3. #3
    Join Date
    Dec 2002
    Location
    Tenby, Wales
    Posts
    277

    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

  4. #4
    Join Date
    Dec 2002
    Location
    Tenby, Wales
    Posts
    277

    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
  •  





Click Here to Expand Forum to Full Width

Featured