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?
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 FyeCommented:
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 FyeCommented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Skip SleeperIT ManagerAuthor Commented:
Here it is


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

Open in new window

0
 
Dale FyeCommented:
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 FyeCommented:
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 ConnectWise

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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.