473,378 Members | 1,500 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Search Query isn't working for certain results

11
Hi all,

The program I am using is Microsoft Access 2010. I have a search form set up where I can type criteria in a textbox (Changed named to Keyword) and press a button to run a query. The Criteria for the query is is

Like "*" & [Forms]![Search Form]![Keyword] & "*"

I have a list item in the keywords column called "Port au Port #1 wells" (It's a local oil and gas well where I live) and when I put that exact text in the textbox I have set up for the search query, it says there are no matches. However, everything else I search without the "#" sign seems to return the correct number of records. Why is this happening?
Mar 4 '15 #1
6 1067
twinnyfo
3,653 Expert Mod 2GB
Try this:

Expand|Select|Wrap|Line Numbers
  1. Like "'*" & [Forms]![Search Form]![Keyword] & "*'"
The missing single quotes may have been causing problems...
Mar 4 '15 #2
amwkl4
11
That solution didn't work, it also made other words stop working too. Do you have any other ideas?
Mar 4 '15 #3
twinnyfo
3,653 Expert Mod 2GB
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSearch_Click()
  2.     Dim strSQL As String
  3.  
  4.     strSearch = ""
  5.     strSearch = "LIKE '*" & Me.Keyword & "*'"
  6.     strSQL = "SELECT Field1, Field2 " & _
  7.         "FROM Table1 " & _
  8.         "WHERE Field3 LIKE '*" & Me.Keyword & "*';"
  9.     DoCmd.RunSQL strSQL
  10. End Sub
This creates a SQL string and executes it. Without seeing your exact query and knowing exactly what you are trying to look for, this is really just stabbing in the dark for a solution.
Mar 4 '15 #4
amwkl4
11
Thanks for your time, I have finally found a solution. It is very simple, I just have to enclose the # with square brackets like so [#] when inputting the text in the textbox.
Mar 4 '15 #5
Rabbit
12,516 Expert Mod 8TB
The hash symbol # is a wildcard. In a like statement, it matches any numeric character.
Mar 4 '15 #6
jforbes
1,107 Expert 1GB
Your gonna get some weird results when you bump up against Reserved Characters/wildcards like:
Expand|Select|Wrap|Line Numbers
  1. #
  2. '
  3. "
  4. ?
  5. %
  6. ^
  7. _
I would recommend removing these characters out of the Where Clause before attempting to filter on them or else your program will return errors to you users, which will make it look as though the program is poorly written.

I use this trimForSQLWhere() function to accomplish this. It looks kinda of daunting at first, but it's not really that bad:
Expand|Select|Wrap|Line Numbers
  1. Public Function trimForSQLWhere(ByVal sTemp As String) As String
  2.     trimForSQLWhere = trimWithRegex(sTemp, "[^a-zA-Z0-9\\@~()\: .,_\-\t\n\r\/]")
  3. End Function
  4. Public Function trimWithRegex(ByVal sTemp As String, ByRef sPattern As String) As String
  5.     Dim RegEx As Object    
  6.     Set RegEx = CreateObject("VBScript.RegExp")
  7.     RegEx.Global = True
  8.     RegEx.Pattern = sPattern
  9.     trimWithRegex = RegEx.Replace(sTemp, "")
  10. End Function
It will remove most crazy characters and leave AlphaNumerics and some other things like Carriage Returns, Line Feeds and slashes.

For a neat reference on Regular Expressions, check out http://www.regexr.com/
Mar 4 '15 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Stu | last post by:
I have the following code which I am having difficulty getting to work. I think it may be a problem with the $got query that is being run as if I set that to a set value then my site seems to run...
2
by: scott | last post by:
Hi all, Iv got a slight problem with a datagrid and the ability to only display certain things in it. I have a Data grid which is connected to a data table. The data table is connected...
1
by: SC | last post by:
I'm developing a site that may eventually have a very large database of users (hopefully, but who knows). It will be a community website where users can search each other (think Friendster,...
7
by: Frankie | last post by:
I'm trying to run the following search query: $query = sprintf ("SELECT itemNumber, thumbnailURL, title, description, price FROM apparel,hats WHERE apparel.title OR apparel.description OR...
1
by: vHTML | last post by:
hello everyone :) I am trying to make a page which would take a "entered" on search query from the previous page and display results in google with that query in an <iframe> in the results.htm...
14
by: Simon Gare | last post by:
Hi, have a search.asp page with results.asp page drawing data from an SQL db, problem is the user has to type the whole field value into the search box to retrieve the value on results.asp, what...
2
by: rob21century | last post by:
Hello i will be a web designer one day but until then i need a little help I have a search query that searches the database for user entered string. See below: $query = "SELECT * From MyTable...
49
by: martin DH | last post by:
Hello all, I'm back with another SQL related problem. The details are below, but in short: I am using Access 2003. I have a table whose structure may include four different associate names per...
6
by: paankhate | last post by:
Hi, I have a task at hand to reduce the time taken for search query to execute. The query fetches records which will have to sorted by degrees away from the logged in user. I have a function...
2
by: fran7 | last post by:
Hi, I have this search query 'search feature If Request("SearchWord") <> "" Then strWd=Replace(Request("SearchWord"),"'","''") strSQL="Select...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.