Private Sub Form_Load()
' Create the instance of the database class
Set gDB = New CDatabase
' Open the database
gDB.dbName = App.Path & "\northwind.MDB"
' Create an object variable for the ColumnHeader object.
Dim clmX As ColumnHeader
' Add ColumnHeaders.
Set clmX = lvFind.ColumnHeaders.Add(, , "Product", (lvFind.Width - 1066) / 2)
Set clmX = lvFind.ColumnHeaders.Add(, , "Supplier ID", (lvFind.Width - 1066) / 2)
Set clmX = lvFind.ColumnHeaders.Add(, , "Category ID", 976)
lvFind.BorderStyle = ccFixedSingle ' Set BorderStyle property.
lvFind.View = lvwReport ' Set View property to Report.
' Label OptionButton controls with SortOrder options.
OptSort(0).Caption = "Sort Ascending"
OptSort(1).Caption = "Sort Descending"
lvFind.SortOrder = lvwAscending ' Sort ascending.
OptSort(0).Value = True
End Sub
Private Sub lvFind_ColumnClick(ByVal ColumnHeader As ColumnHeader)
' When a ColumnHeader object is clicked, the ListView control is
' sorted by the subitems of that column.
' Set the SortKey to the Index of the ColumnHeader - 1
lvFind.SortKey = ColumnHeader.Index - 1
' Set Sorted to True to sort the list.
lvFind.Sorted = True
End Sub
Private Sub Form_Activate()
txtWord.SetFocus
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set frmFind = Nothing
End Sub
Private Sub lvFind_DblClick()
cmdFind(findCloseButton) = True
End Sub
Private Sub cmdFind_Click(Index As Integer)
Dim sSQLProducts As String
Dim sErr As String
Dim itmX As ListItem ' Create a variable to add ListItem objects.
Select Case Index
Case findFindItButton
On Error Resume Next
lvFind.ListItems.Clear
sSQLProducts = "Select * from Products where ProductName like '*" & txtWord & "*' "
Set mrsProducts = gDB.DB.OpenRecordset(sSQLProducts, dbOpenDynaset)
If Err.Number <> 0 Then
sErr = Err.Description
On Error GoTo 0
Err.Raise dbOpenRSError, "cmdFind_Click", sErr
End If
While Not mrsProducts.EOF
Set itmX = lvFind.ListItems.Add(, , CStr(mrsProducts!ProductName))
itmX.SubItems(1) = CStr(mrsProducts!SupplierID)
itmX.SubItems(2) = mrsProducts!CategoryID
mrsProducts.MoveNext
Wend
mrsProducts.Close
Case findCloseButton
Unload Me
Case Else
ColorListviewRow lvFind, 5, vbRed ' use 16711681 instead of vbBlue
End Select
End Sub