rivate Sub cmdSearch_Click()
Dim sKeyWord As String
Dim sSQL As String, sWhere As String
Set rst = New Recordset
Select Case cboField.ListIndex
Case 0: sKeyWord = "AND "
Case 1: sKeyWord = "OR "
Case 2: sKeyWord = "AND NOT "
End Select
sSQL = "SELECT movieInfo.title, MediaType.StrKey, genre.genre, movie_inventory.PurchaseDate, movieInfo.movie_year, country.country, language1.language1, audienceRating.rating " _
& "FROM audienceRating INNER JOIN (language1 INNER JOIN " _
& "(country INNER JOIN ((MediaType INNER JOIN (movieInfo INNER JOIN movie_inventory " _
& "ON movieInfo.movieId = movie_inventory.movieId) ON " _
& "MediaType.media_catId = movie_inventory.media_catId) INNER JOIN " _
& "genre ON movieInfo.GenreID = genre.genreId) ON country.countryId = movieInfo.countryId)" _
& "ON language1.languageId = movieInfo.languageId) ON audienceRating.ratingId = movieInfo.ratingId"
If txtSearch.Text <> "" And chkMatchcase.Value Then sWhere = sWhere & sKeyWord & "title Like '%" & txtSearch.Text & "%' "
If txtSearch.Text <> "" And chkMatchWhole.Value Then sWhere = sWhere & sKeyWord & "title = '" & txtSearch.Text & "' "
If txtReference.Text <> "" Then sWhere = sWhere & sKeyWord & "reference = '" & txtReference.Text & "' "
If cboGenre.Text <> "" Then sWhere = sWhere & sKeyWord & "genre = '" & cboGenre.Text & "' "
If cboSubgenre.Text <> "" Then sWhere = sWhere & sKeyWord & "genre = '" & cboSubgenre.Text & "' "
If cboCountry.Text <> "" Then sWhere = sWhere & sKeyWord & "country = '" & cboCountry.Text & "' "
If cboFormat.Text <> "" Then sWhere = sWhere & sKeyWord & "strKey = '" & cboFormat.Text & "' "
If cboYear.Text <> "" Then sWhere = sWhere & sKeyWord & "movie_year = '" & cboYear.Text & "' "
If chkPurchased.value Then sWhere = sWhere & sKeyWord & "PurchaseDate >= #" & dtpPurchaseAfter.Value & "# AND PurchaseDate <= #" & dtpPurchaseAfter.Value & "#"
If sWhere <> "" Then
sSQL = sSQL & " WHERE " & Mid(sWhere, Len(sKeyWord) + 1)
End If
rst.Open sSQL, cnAddMovie, adOpenKeyset, adLockPessimistic, adCmdText
Call PopulateList(ListView1, rst)
End Sub