Date Range Search
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Date Range Search

  1. #1
    Join Date
    Aug 2011
    Posts
    15

    Date Range Search

    Good Day to all

    Somebody help me, i need to make a search form on a date range, for example i want search and to display my records on my report between January 1 to January 30. Im using ADO recordset, How can i do that? How possible codes in vb6 could do this?

    Thanks in advance

    Regards
    Neil

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,985

    Re: Date Range Search

    Here's a method that works. It used the TIME PART of the DATE, which you may not need,

    Code:
      Select * From Table1 Where Day>Table1.Day AND Day<=Table1.Day + 1
    Will also work, and save some time...

    Code:
    Option Explicit
    
    
    
    Private Sub Form_Load()
    Dim dteDate     As Date
    Dim adoRec      As ADODB.Recordset
        dteDate = CDate("7 March 2005 10:04:00AM")
        Set adoRec = GetRecordset(dteDate)
        With adoRec
            Do While Not .EOF
                'your code goes here
                 MsgBox .Fields(0)
                .MoveNext
            Loop
            .Close
        End With
        Set adoRec = Nothing
    End Sub
    
    Private Function GetRecordset(ByVal pdteSearchDate As Date) As ADODB.Recordset
    Dim strSQL      As String
    Dim adoRec      As ADODB.Recordset
        strSQL = "SELECT * "
        strSQL = strSQL & "FROM AS_Createsched "
        strSQL = strSQL & "WHERE AS_Createsched.CSIN_dates = #" & Format$(pdteSearchDate, "d mmm yyyy") & "# "
        strSQL = strSQL & "AND HOUR(AS_Createsched.CSIN_times) = " & Format$(pdteSearchDate, "hh") & " "
        strSQL = strSQL & "AND MINUTE(AS_Createsched.CSIN_times) = " & Format$(pdteSearchDate, "nn") & " "
        Set adoRec = New ADODB.Recordset
        adoRec.Open strSQL, GetConnString, adOpenForwardOnly, adLockReadOnly
        Set GetRecordset = adoRec
        Set adoRec = Nothing
    End Function
    
    Private Function GetConnString() As String
        GetConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db4.mdb;Persist Security Info=False"
    End Function
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center