Cascading combo boxes syntax error

Hi Experts,

I have modified some code (provided by Dale Fye) to search a form with two combo boxes.  The code stops with a missing operator/syntax error in the query expression that I can't figure out how to correct.  

In the attached db, there is only the one form I'm working on.

Any help is greatly appreciated!

Thanks!
VernonHomesInventory_ver-1.0_be.accdb
Skip SleeperIT ManagerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale FyeOwner, Developing Solutions LLCCommented:
skip,

on my iPad at the moment, can you post the sample code and highlight where it is failing.  Probably just a syntax error due to "air code"

Dale
0
Skip SleeperIT ManagerAuthor Commented:
Hi Dale,

Not sure how to highlight but I commented just before the line (near bottom)

Thanks!

Private Sub cmd_Filter_Click()
    ' Dale Fye from EE

    Dim strFilter As String

    If Me.cboSearchLocation & "" <> "" Then strFilter = "([Location] = " & Me.cboSearchLocation & ")"

    If Me.cboSearchItems & "" <> "" Then
        If strFilter <> "" Then strFilter = strFilter & " AND "
       'strFilter = strFilter & "([Item] = " & Me.cboSearchItems & ")"  USE FOR NUMERIC VALUES
       strFilter = strFilter & "([Item]) = " & Chr$(34) & Me.cboSearchItems & Chr$(34) & ")"
       ' used for strings
              
    End If
****FAILS on next line*****
    Me.Filter = strFilter
    Me.FilterOn = IIf(strFilter = "", False, True)
End Sub

Open in new window

0
Dale FyeOwner, Developing Solutions LLCCommented:
Insert a line before line 16:

debug.print strFilter

Then put a breakpoint on what is now line 16

Then post back the value that is printed in your immediate window.

Dale
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Skip SleeperIT ManagerAuthor Commented:
Here it is


([Location] = AW Clean Service Room) AND ([Item]) = "Clothing Protectors")

Open in new window

0
Dale FyeOwner, Developing Solutions LLCCommented:
modify this line:

If Me.cboSearchLocation & "" <> "" Then strFilter = "([Location] = " & Me.cboSearchLocation & ")"

Open in new window

to:
If Me.cbo.SearchLocation & "" <> "" Then strFilter = "([Location] = " & chr$(34) & Me.cboSearchLocation & chr$(34) & ")"

Open in new window

You must wrap strings in quotes.  The original code assumed that cboSearchLocations bound column would be a number, so there were no quotes.
0
Skip SleeperIT ManagerAuthor Commented:
It worked perfectly!  Thank you!
0
Skip SleeperIT ManagerAuthor Commented:
Note: you had provided the optional code for strings in the original post.  I just found where I didn't add the quotes.  Thanks again!
0
Skip SleeperIT ManagerAuthor Commented:
Dale,

What is the code doing when it's checking for "not equal to"?
0
Dale FyeOwner, Developing Solutions LLCCommented:
You only want to add the criteria of the combo boxes are not empty.

if you don't select anything in the combo, or delete the text that is currently selected, then the combo value will be either NULL or an empty string.  You can check for either of those values, or you can simply add an empty string and perform that test.

You could also use:

IF NZ(me.cboName, "") <> "" then
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Skip SleeperIT ManagerAuthor Commented:
Got it, thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.