Solved

Like search using chr(34)

Posted on 2016-07-23
11
43 Views
Last Modified: 2016-07-24
Hi EE

I am having problems with a like search using chr(34)
Here is my code
Search = "SELECT * FROM tblCustomer WHERE [SurName] = " & Chr(34) & Me!txtSurname & Chr(34)
I want to change to a like search. I have tried
Search = "SELECT * FROM tblCustomer WHERE [SurName] Like " * [" & Chr(34) & "] * " &  Me!txtSurname & Chr(34)"

Any help appreciated

I need to use chr(34) because we have a lot of O'Brians etc

chestera
0
Comment
Question by:chestera
11 Comments
 
LVL 27

Expert Comment

by:MacroShadow
ID: 41726115
Try:
Search = "SELECT * FROM tblCustomer WHERE [SurName] Like * " & Chr(39) & " * " &  Me!txtSurname

Open in new window

0
 

Author Comment

by:chestera
ID: 41726184
MacroShadow

I tried
Search = "SELECT * FROM tblCustomer WHERE [SurName] Like * " & Chr(39) & " * " & Me!txtSurname

Get message missing operator, should there be something after me!txtsurname

Alan
0
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 125 total points
ID: 41726191
the * need to be part of the string loke this

Search = "SELECT * FROM tblCustomer WHERE [SurName] Like  " & Chr(34) & "*" & Me!txtSurname & "*" & chr(34)
1
 
LVL 27

Accepted Solution

by:
MacroShadow earned 250 total points
ID: 41726197
Perhaps this:
Search = "SELECT * FROM tblCustomer WHERE [SurName] Like " & Chr(34) & Me!txtSurname & Chr(39) & "*" & Chr(34)
1
 
LVL 29

Assisted Solution

by:IrogSinta
IrogSinta earned 125 total points
ID: 41726229
Both of the following work.  For the latter I just used double quotation marks instead Chr(34).  Take your pick:
Search = "SELECT * FROM tblCustomer WHERE [SurName] LIKE " & Chr(34) & Me!txtSurname & Chr(34)
Search = "SELECT * FROM tblCustomer WHERE [SurName] LIKE """  & Me!txtSurname & """"

Open in new window


Ron
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:chestera
ID: 41726435
Macroshadow

Search = "SELECT * FROM tblCustomer WHERE [SurName] Like " & Chr(34) & Me!txtSurname & Chr(39) & "*" & Chr(34)

The above wont find any surname. I have for example I entered Jones which is a current surbname it didn't find it.

Alan
0
 

Author Comment

by:chestera
ID: 41726437
IrogSinta

Enter both
Search = "SELECT * FROM tblCustomer WHERE [SurName] LIKE " & Chr(34) & Me!txtSurname & Chr(34)
Search = "SELECT * FROM tblCustomer WHERE [SurName] LIKE """  & Me!txtSurname & """"

for example I searched for Jones and it finds all jones but if I enter Jon no luck

Your help is appreciated

Alan
0
 

Author Comment

by:chestera
ID: 41726440
Guy Hengel

Search = "SELECT * FROM tblCustomer WHERE [SurName] Like  " & Chr(39) & "*" & Me!txtSurname & "*" & chr(39)

It will find full name but not a partial name

Alan
0
 

Author Comment

by:chestera
ID: 41726449
Macroshadow

My Apologies. I must have a bug in the form I was using your code, I used another form an it worked.

I am going to ward point to all three in fairness. You was first so you get best solution.

Alan
0
 

Author Comment

by:chestera
ID: 41726450
IrogSinta

My Apologies. I must have a bug in the form I was using your code, I used another form an it worked.

I am going to ward point to all three in fairness
Alan
0
 

Author Comment

by:chestera
ID: 41726453
Guy Hengel

My Apologies. I must have a bug in the form I was using your code, I used another form an it worked.

I am going to ward point to all three in fairness. Alan
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Access creating a Chart from Search result on Form view 2 22
MS Access 2007 Count Unique Values in a Group 5 35
ms/access hyperlink/ftp 7 39
Track name AutoCorrect info 14 48
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now