Help with VBA SQL Wildcard (1 Viewer)

amerfeld

Registered User.
Local time
Today, 16:31
Joined
Aug 17, 2004
Messages
58
Hi everyone. Hoping for some help here as I have exhausted all other resources. I have a form containing combo boxes used to filter a list box that uses an sql statement based on a table as its recordsource.

I have these combo boxes:
1. cboOperation
2. cboCustNme
3. cboPartNo
4. cboPartDesc
The listbox is named lstQuoteSearch.

When filtering by 2,3,4 all is well. However, when filtering by 1, I need to use a wildcard to search for the chosen operation in an operation list field. ie If user chooses powder, the sql needs to look in an operationslist field to find powder. The field could contain, "Powder" or "Liquid, Powder" etc.

Here is my code which worked up until the point that I needed to add in the wildcard fun.

**********************************************************
Public Sub frmRequeryQuote()
' Comments : This module requeries list box to update based on selection in combo boxes

' --------------------------------------------------------
On Error GoTo Proc_Err
'Purpose: Build SQL and requery the list box
Dim strfilter As String
Dim strOpsList
strfilter = ""
DoCmd.Hourglass True

'create WHERE clause

If Not IsNull(Me!cboCustNme) Then
strfilter = strfilter & " tmakpoquotesearch3.CustNme = '" & Me!cboCustNme & "' AND"
End If
If Not IsNull(Me!cboPartNo) Then
strfilter = strfilter & " tmakpoquotesearch3.PartNo = '" & Me!cboPartNo & "' AND"
End If
If Not IsNull(Me!cboPartDesc) Then
strfilter = strfilter & " tmakpoquotesearch3.partdesc = '" & Me!cboPartDesc & "' And"
End If

'Cleanup the string

If right(strfilter, 3) = "AND" Then 'strip trailing AND
strfilter = Trim(left(strfilter, Len(strfilter) - 3))
End If

strfilter = " WHERE " & strfilter

If IsNull(Me!cboOperation) Then
Else
strOpsList = "Like "" * " & Me!cboOperation & " * "")"
strfilter = strfilter & " " & "AND" & " " & "(" & "(" & "tmakpoquotesearch3.operationslist)" & " " & strOpsList
End If

strfilter = strfilter & " " & " ORDER BY tmakpoquotesearch3.CustNme,tmakpoquotesearch3.QuoteID DESC " 'Add ORDER BY clause
Me!lstQuoteSearch.RowSource = mcstrSQL & strfilter

'Put SQL in the list box
Me!lstQuoteSearch.Requery

DoCmd.Hourglass False

Exit Sub

Proc_Err:
MsgBox "The following error occurred: " & Error$
Resume Next
End Sub
********************************************************

I have tried every syntax I can think of and nothing has worked. Can anyone help, please?
 

RuralGuy

AWF VIP
Local time
Today, 15:31
Joined
Jul 2, 2005
Messages
13,826
Try without the spaces:
strOpsList = "Like ""*" & Me!cboOperation & "*"")"
 

amerfeld

Registered User.
Local time
Today, 16:31
Joined
Aug 17, 2004
Messages
58
You are awsome! That worked perfectly. Knew it was something that should be easy, but I'm not very good at writing sql. Thanks! You made my day!
 

Users who are viewing this thread

Top Bottom