473,738 Members | 9,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 tblMiscellaneou s
WHERE (tblMiscellaneo us.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).C ontrols(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).C ontrols(strCtl) & "*"
End Function

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

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

strQry = strQry & "[SomeField] = ""*" & Me![txtUserEntryCon trol] & "*"""

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******** **********@news svr21.news.prod igy.com...
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 tblMiscellaneou s
WHERE (tblMiscellaneo us.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).C ontrols(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).C ontrols(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
7434
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 (using LIKE and "%" and "?"). But is it possible to match a concrete string against a database of wildcarded data? ("%" and LIKE do not work). For example: CREATE TABLE blacklist (
6
2132
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 selected in the relevant dialogue boxes and perform the query on these boxes. However my problem lies in the fact that if no choice is selected in the dialogue box I want the query to default (or get passed) a wildcard that will mean it will...
2
4177
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 to work in my query. In the example below, I have several records in tblEntity that begin with "m" and "mi" and one record with the company name "microsoft". I get a match only when I type in the full string "microsoft". Why no match before...
0
2909
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 ‘#’, ‘?’, and ‘*’ as wildcards, the results returned are always null. An example of a query that does work is: SELECT SampleIndex FROM SampInfo
3
2277
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, but I probably have not properly implemented the solutions I find. I am trying to make a page to allow personnel the ability to search our backend DB (which is Ingres 2.0) through a web interface. Ingres has a cgi program called ICE that can...
2
3998
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 a client account number. In the TableAdapter, I created a new query called "FillbyAccountNumber". When I created this, I set up the SELECT statement so that it selected all the fields I wanted and then used the following WHERE clause: WHERE...
9
3864
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 reference table with categories for the accounts. Table B is the main transactions table with actual activity by account. Table A's records have the account field utilizing wildcard characters, ex. "111##", to capture ranges of accounts. Table B's...
0
1526
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 search and return based on description. i've got a textbox on an aspx page for input of the search term (@DESC). when i put in T% into the textbox on the aspx page i get 0 results - if i put in T% for @DESC in the query builder and preview the...
0
2669
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 some code which will allow me to do it but i dont know how to change the code. Could someone please help me. I have added the code for you to. function MyQuery::OnClick(eventObj) { // Get the default SQL command for the form. var...
0
8788
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9335
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9263
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6751
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.