Hi, all.
I found the tutorial from this website after doing a google search that shows a method on creating search forms. I am trying to adapt the code for my own, but have hit a road block. Every time I try to run the query, it asks me to enter parameter values. I checked the spelling on everything, and it all seems right... Haven't touched Access for a few years, so I was thinking there might be some form building details that I had forgotten.
Here is the code...
I know I have to adjust the code that strips off the last "AND". Was playing with the code when I was troubleshooting, and that's where I left off.
And attached is the DB in question.
Thanks so much for your help!
I found the tutorial from this website after doing a google search that shows a method on creating search forms. I am trying to adapt the code for my own, but have hit a road block. Every time I try to run the query, it asks me to enter parameter values. I checked the spelling on everything, and it all seems right... Haven't touched Access for a few years, so I was thinking there might be some form building details that I had forgotten.
Here is the code...
Code:
Option Compare Database
Option Explicit
Private Sub btnClear_Click()
Dim intIndex As Integer
' Clear all search items
' Me.txtKeywords = ""
Me.cmbIndustry = 0
Me.cmbAudience = 0
End Sub
Private Sub btnSearch_Click()
' Update the record source
Me.frmsubItems.Form.RecordSource = "SELECT * FROM qryItemData " & BuildFilter
' Requery the subform
Me.frmsubItems.Requery
End Sub
Private Sub Form_Load()
' Clear the search form
btnClear_Click
End Sub
Private Function BuildFilter() As Variant
Dim varWhere As Variant
Dim varItem As Variant
Dim intIndex As Integer
varWhere = Null ' Main filter
' Check for LIKE Keywords
If Me.txtKeywords > "" Then
varWhere = varWhere & "[itemKeywords] LIKE """ & Me.txtKeywords & "*"" AND "
End If
' Check for Industry
If Me.cmbIndustry > 0 Then
varWhere = varWhere & "[itemIndustry] = " & Me.cmbIndustry & " AND "
End If
' Check for Audience
If Me.cmbAudience > 0 Then
varWhere = varWhere & "[itemAudience] = " & Me.cmbAudience & " AND "
End If
' Check if there is a filter to return...
If IsNull(varWhere) Then
varWhere = ""
Else
varWhere = "WHERE " & varWhere
' strip off last "AND" in the filter
If Right(varWhere, 5) = " AND " Then
varWhere = Left(varWhere, Len(varWhere) - 5)
End If
End If
BuildFilter = varWhere
End Function
I know I have to adjust the code that strips off the last "AND". Was playing with the code when I was troubleshooting, and that's where I left off.
And attached is the DB in question.
Thanks so much for your help!
Attachments
Last edited: