473,418 Members | 2,020 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,418 software developers and data experts.

How to use wildcard in SQL query?

I have a form where users can enter a string with asterisks to perform a
wildcard search. Currently, the string entered by the user looks like this:

*somestring*

The purpose is to match any database field containing "somestring". Is
there a way to avoid the need for the asterisks? This would make it easier
for the users and also I wouldn't have to explain that asterisks are
required when performing a wildcard search.

The query looks like this:

SELECT DISTINCT Entity_ID
FROM tblMiscellaneous
WHERE (tblMiscellaneous.Misc Like QryPrm("frm0", "txtFind"));

The function looks like this:

Public Function QryPrm(ByVal strFrm As String, ByVal strCtl As String) As
Variant
QryPrm = Forms(strFrm).Controls(strCtl)
End Function

Should I just rewrite the function like this:

Public Function QryPrm(ByVal strFrm As String, ByVal strCtl As String) As
Variant
QryPrm = "*" & Forms(strFrm).Controls(strCtl) & "*"
End Function

Is there a more efficient or better way to do wildcard searches?

Thanks in advance.
Nov 13 '05 #1
1 7217
In the code where you create the SQL, simply add the "*" to the value
entered by the user as:

strQry = strQry & "[SomeField] = ""*" & Me![txtUserEntryControl] & "*"""

There's no "wildcard without the wildcard characters" but you can add them
for the user.

Larry Linson
Microsoft Access MVP

"deko" <ww*******************************@nospam.com> wrote in message
news:48******************@newssvr21.news.prodigy.c om...
I have a form where users can enter a string with asterisks to perform a
wildcard search. Currently, the string entered by the user looks like this:
*somestring*

The purpose is to match any database field containing "somestring". Is
there a way to avoid the need for the asterisks? This would make it easier for the users and also I wouldn't have to explain that asterisks are
required when performing a wildcard search.

The query looks like this:

SELECT DISTINCT Entity_ID
FROM tblMiscellaneous
WHERE (tblMiscellaneous.Misc Like QryPrm("frm0", "txtFind"));

The function looks like this:

Public Function QryPrm(ByVal strFrm As String, ByVal strCtl As String) As
Variant
QryPrm = Forms(strFrm).Controls(strCtl)
End Function

Should I just rewrite the function like this:

Public Function QryPrm(ByVal strFrm As String, ByVal strCtl As String) As
Variant
QryPrm = "*" & Forms(strFrm).Controls(strCtl) & "*"
End Function

Is there a more efficient or better way to do wildcard searches?

Thanks in advance.

Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Robert Brown | last post by:
I have researched newsgroups and the web very thoroughly and unsuccessfully for a solution to what I believe is a very common problem. I know it's easy to do wildcard match against data in DB...
6
by: EJC | last post by:
Hi Folks, I've been trying to build a query from a form of dialogue boxes I have created that holds search criteria for my main database. I have been able to get the query to retrieve the data...
2
by: deko | last post by:
I'm trying to use a textbox to search and display records as each letter is typed in - similar to the behavior of a combo box. But for some reason I can't seem to get the wildcard search character...
0
by: Torsten | last post by:
I am attempting to issue an SQL query in C# to and Access database using the Microsoft.Jet.OLEDB.4.0 provider. The only wildcard character that seems to work is ‘%’. When using ‘#’,...
3
by: george.lengel | last post by:
Hello experts, I have been struggling for days to solve this problem and every suggestion I find via Google does not work for me. There is probably a solution out there that will do what I want,...
2
by: googlegroups.dsbl | last post by:
I'm really confused here, and am wondering if someone knows what could be the issue with my TableAdapter query. A few months ago, I created a really neat program that has th ability to search by...
9
by: romanko | last post by:
I'm running Access 2000 on Windows XP. I have a simple select query, with two tables joined at the "Account" field. The account field has 5 characters of text in both tables Table A is a...
0
by: Gordon.E.Anderson | last post by:
short description: i've got a .net web site set up using a tableadapter attached to a sql server table - returning results only, no update of data. i've got a query (qry code below) set up to...
0
by: savage678 | last post by:
Hi Everyone, I am new to this forum and am i dire need of some help. I am trying to use wildcard searches in infopath. I have it connected to an access database using data connection. I have...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.