Results 1 to 14 of 14

Thread: [RESOLVED] Search by Month Problem

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Posts
    124

    Resolved [RESOLVED] Search by Month Problem

    I have a bit of a problem in date ranges. Im using SQL Server 2k and VB6 frontend.

    I have a form with Msflexgrid populated from database. My problem is searchin by Month.

    Here is my code for the combobox. Please take a look at view by month coz im having error to that.

    vb Code:
    1. Select Case ComboBox.Text
    2.         Case "Today"
    3.        
    4.               'VIEW TODAY'S RECORDS
    5.               strSQL = "SELECT * FROM TABLE WHERE FIELD_DATE ='" & Date & "'"
    6.              
    7.         Case "Yesterday"
    8.               'VIEW YESTERDAY'S RECORDS
    9.               strSQL = "SELECT * FROM TABLE WHERE FIELD_DATE ='" & Date - 1 & "'"
    10.        
    11.         Case "This Week"
    12.               'VIEW THIS WEEK'S RECORDS
    13.               strSQL = "SELECT * FROM TABLE WHERE FIELD_DATE BETWEEN '" & _
    14.                         Date - 7 & " ' AND '" & Date & "'"
    15.              
    16.         Case "This Month"
    17.               'VIEW THIS MONTH'S RECORDS
    18.               'IM GETTING AN ERROR HERE
    19.               strSQL = "SELECT * FROM TABLE WHERE FIELD_DATE BETWEEN '" & _
    20.                        CDate(Month(Date) & "/01/" & Year(Date)) & "' AND '" & _
    21.                        CDate(Month(Date) & "/31/" & Year(Date)) & ""
    22.              
    23.         Case "This Year"
    24.               'VIEW THIS YEAR'S RECORDS
    25.               strSQL = "SELECT * FROM TABLE WHERE FIELD_DATE BETWEEN '" & _
    26.                        CDate("1/01/" & Year(Date)) & "' AND '" & _
    27.                        CDate("12/31/" & Year(Date)) & ""
    28.     End Select

    Is there any other approach to do this. I maybe doing this wrong. Thanks in anticipation.
    Last edited by Erroneous; Apr 4th, 2008 at 04:44 AM.

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