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

    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


  2. #2
    Join Date
    Jan 2006
    Fox Lake, IL

    Re: Date Range Search

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

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

    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)
        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

    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

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.