Hi all,
I have this code to perform my search.
I have a print button to print the results after searching.
Could someone please help?
Thanks in advanced.
I have this code to perform my search.
I have a print button to print the results after searching.
Could someone please help?
Thanks in advanced.
Code:
Private Sub cmdSearch_Click()
Dim strWhere As String
Dim lngLen As Long
If Not IsNull(Me.txtSongNumber) Then
strWhere = strWhere & "([SongNumber] = Like ""*" & Me.txtSongNumber & "*"") AND "
End If
If Not IsNull(Me.txtTitle) Then
strWhere = strWhere & "([Title] = Like ""*" & Me.txtTitle & "*"") AND "
End If
If Not IsNull(Me.txtAuthor) Then
strWhere = strWhere & "([Author] = Like ""*" & Me.txtAuthor & "*"") AND "
End If
If Not IsNull(Me.txtKeywords) Then
strWhere = strWhere & "([Keywords] = Like ""*" & Me.txtAuthor & "*"") AND "
End If
If Not IsNull(Me.txtYear) Then
strWhere = strWhere & "([Year] = """ & Me.txtYear & """) AND "
End If
If Not IsNull(Me.cboArea) Then
strWhere = strWhere & "([Area] = """ & Me.cboArea & """) AND "
End If
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "Please enter at least a criteria", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove the " AND " at the end.
strWhere = Left$(strWhere, lngLen)
'Finally, apply the string as the form's Filter.
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub