• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 156
  • Last Modified:

Easy SQL Question

Hi,
Ok - I can't remember or find what I am doing wrong in this code, Here is the code:
Dim strSQL As String
Dim SrchWord As String
SrchWord = Combo1.Text
If txtCustSearch.Text = txtLastSKU Then Exit Sub
txtLastSKU = txtCustSearch.Text
strSQL = "SELECT FirstName, LastName,CustID,Address,City,State,Zip,Phone1,StateID from Customers " & _
         "Where'" & SrchWord & "Like'" &_ txtCustSearch.Text & "%'"

The problem is in how I am bracketing SrchWord, I can't seem to get it to work, even though I know it's probably easy - I just can't seem to get it.

The combo box is filled with valid field names for search criteria (LastName, FirstName etc:)

Your help is appreciated.

Thank,
Tom

0
flosoft
Asked:
flosoft
  • 2
1 Solution
 
Brendt HessSenior DBACommented:
Your WHERE statement should be like:

        "Where [" & SrchWord & "] Like '" &_ txtCustSearch.Text & "%'"

This assumes SrchWord is a field name.
0
 
flosoftAuthor Commented:
Hi,
srchWord is a valid field name selected from a combobox populated with valid field names (LastName, FirstName etc)

I use
Dim SrchWord as String then
SrchWord = Combo1.text

To make srchword = the text of combo1, which at form load is filled with field names listed above and spelled correctly.

0
 
TheAnswerManCommented:
No.. the problem is that there is a single quote right after the WHERE..  take it out.
and put a space before and after Like

"Where'" & SrchWord & "Like'" &_ txtCustSearch.Text & "%'"
becomes
"Where " & SrchWord & " Like '" &_ txtCustSearch.Text & "%'"
0
 
flosoftAuthor Commented:
Hey Thanks Bunches - This is the kinda thing that drives me CRAZY!

It is really appreciated - Excellent Answer.

Thanks to both of you!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now