Solved

Easy SQL Question

Posted on 2001-06-22
4
145 Views
Last Modified: 2010-05-02
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
Comment
Question by:flosoft
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 32

Expert Comment

by:Brendt Hess
ID: 6219353
Your WHERE statement should be like:

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

This assumes SrchWord is a field name.
0
 

Author Comment

by:flosoft
ID: 6219407
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
 
LVL 3

Accepted Solution

by:
TheAnswerMan earned 100 total points
ID: 6219412
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
 

Author Comment

by:flosoft
ID: 6219437
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month8 days, 11 hours left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question