- Version
- Download 370
- File Size 63.74 KB
- File Count 1
- Create Date April 14, 2016
- Last Updated April 14, 2016
Filter Record by Date Range in Visual Basic
Filter record by data range in Visual Basic 6
This is a part of my library system where it demonstrates how to filter records in database between two dates.
Program features
1. Program will allow you to select date from and date to. Note (date from must not be greater than the date value of date to).
2. After you have selected the dates click show to display the records available between two dates.
3. The program is also capable of printing the results.
Happy Programming.
Source code:
Sub DateRangeResult(lstReturn As ListView, DateFrom As Date, DateTo As Date)
Dim lstItem As ListItem, a As Integer
If rs.State = adStateOpen Then rs.Close
sql = " SELECT ReturnedBooks.TransactionID, ReturnedBooks.BookID, ReturnedBooks.BookTitle, ReturnedBooks.BorrowersID, ReturnedBooks.BorrowersName, ReturnedBooks.Date_Borrowed, ReturnedBooks.Date_Returned, ReturnedBooks.DueDate, ReturnedBooks.CopiesReturn, ReturnedBooks.ProcessedBy" & _
" From ReturnedBooks" & _
" WHERE (((ReturnedBooks.Date_Returned)>=#" & DateFrom & "#) and ((ReturnedBooks.Date_Returned) <=#" & DateTo & "#))" & _
" GROUP BY ReturnedBooks.TransactionID, ReturnedBooks.BookID, ReturnedBooks.BookTitle, ReturnedBooks.BorrowersID, ReturnedBooks.BorrowersName, ReturnedBooks.Date_Borrowed, ReturnedBooks.Date_Returned, ReturnedBooks.DueDate, ReturnedBooks.CopiesReturn, ReturnedBooks.ProcessedBy" & _
" ORDER BY ReturnedBooks.Date_Returned;"
rs.Open sql, conn
lstReturn.ListItems.Clear
Do While Not rs.EOF
a = a + 1
Set lstItem = lstReturn.ListItems.Add(, , a, 1, 1)
lstItem.SubItems(1) = rs(0).Value
lstItem.SubItems(2) = rs(1).Value
lstItem.SubItems(3) = rs(2).Value
lstItem.SubItems(4) = rs(3).Value
lstItem.SubItems(5) = rs(4).Value
lstItem.SubItems(6) = rs(5).Value
lstItem.SubItems(7) = rs(6).Value
lstItem.SubItems(8) = rs(7).Value
lstItem.SubItems(9) = rs(8).Value
lstItem.SubItems(10) = rs(9).Value
rs.MoveNext
Loop
End Sub