Error: Extra ) in query expression

BrittKnee

Board Regular
Joined
Dec 4, 2017
Messages
82
I am receiving the below error when creating a form where my users can search for their clients. I keep getting the below error. I have run the query in design view and it runs without any error. Any help is appreciated!

Capture.PNG




SELECT Client_Data_qry.ID, Client_Data_qry.Client_Name, Client_Data_qry.Business_Type, Client_Data_qry.Contact_Person, Client_Data_qry.Contact_Nbr, Client_Data_qry.
Contact_Email_Add, Client_Data_qry.Client_Name AS Client_Data_qry.Business_Type AS [Business Type] FROM Client_Data_qry WHERE (((Client_Data_qry.Client_Name) Like "*" & Forms!frmAdvancedSearch_Client_Data!txtSearch2 & "*")) Or (((Client_Data_qry.Business_Type) Like "*" & Forms!frmAdvancedSearch_Client_Data!txtSearch2 & "*")) Or (((Client_Data_qry.Contact_Person) Like "*" & Forms!frmAdvancedSearch_Client_Data!txtSearch2 & "*")) Or (((Client_Data_qry.Contact_Nbr) Like "*" & Forms!frmAdvancedSearch_Client_Data!txtSearch2 & "*")) Or (((Client_Data_qry.Contact_Email_Add) Like "*" & Forms!frmAdvancedSearch_Client_Data!txtSearch2 & "*")) ORDER BY Client_Data_qry.ID DESC;
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
What exactly are you trying to accomplish with this?
What exactly is being added in all your Search box on the Form?
 
Upvote 0
I have created the below form.


Capture2.PNG









In the rows I would like the search to return:


ID

Client_Name
Business_Type
Contact_Person
Contact_Nbr

Contact_Email_Add

Thanks!
 
Upvote 0
So, is your query supposed to search EVERY single field, or just the Client Name field?
Can you tell us the specific value you are entering in when you get this error?
 
Upvote 0
BrittKnee

You don't really need any of the parentheses you have in the WHERE clause of the query.

Rich (BB code):
SELECT Client_Data_qry.ID, Client_Data_qry.Client_Name, Client_Data_qry.Business_Type, Client_Data_qry.Contact_Person, Client_Data_qry.Contact_Nbr, Client_Data_qry.Contact_Email_Add, Client_Data_qry.Client_Name AS Client_Data_qry.Business_Type AS [Business Type]
FROM Client_Data_qry
WHERE Client_Data_qry.Client_Name Like "*" & Forms!frmAdvancedSearch_Client_Data!txtSearch2 & "*"
       OR Client_Data_qry.Business_Type Like "*" & Forms!frmAdvancedSearch_Client_Data!txtSearch2 & "*"
       OR Client_Data_qry.Contact_Person Like "*" & Forms!frmAdvancedSearch_Client_Data!txtSearch2 & "*"
       OR Client_Data_qry.Contact_Nbr Like "*" & Forms!frmAdvancedSearch_Client_Data!txtSearch2 & "*"
       OR Client_Data_qry.Contact_Email_Add Like "*" & Forms!frmAdvancedSearch_Client_Data!txtSearch2 & "*"
ORDER BY Client_Data_qry.ID DESC;
 
Upvote 0
I notice ([Client_Name])) isn't in the query you posted.

Can we see Client_Data_qry?
 
Upvote 0
I have removed unnecessary "Client_Data_qry." and formatted your sql in post#5
VBA Code:
SELECT ID
    ,Client_Name
    ,Business_Type
    ,Contact_Person
    ,Contact_Nbr
    ,Contact_Email_Add
    ,Client_Name AS Business_Type AS [Business Type] '<<<<<<<<<SYNTAX??????
FROM Client_Data_qry
WHERE Client_Name LIKE "*" & Forms ! frmAdvancedSearch_Client_Data ! txtSearch2 & "*"
    OR Business_Type LIKE "*" & Forms ! frmAdvancedSearch_Client_Data ! txtSearch2 & "*"
    OR Contact_Person LIKE "*" & Forms ! frmAdvancedSearch_Client_Data ! txtSearch2 & "*"
    OR Contact_Nbr LIKE "*" & Forms ! frmAdvancedSearch_Client_Data ! txtSearch2 & "*"
    OR Contact_Email_Add LIKE "*" & Forms ! frmAdvancedSearch_Client_Data ! txtSearch2 & "*"
ORDER BY ID DESC;

Check the line I have noted with <<<SYNTAX Seems Client name was supposed to be aliased?????

Try this one: (But you have Business_Type identified twice in your sql)

VBA Code:
SELECT ID
    ,Client_Name
    ,[COLOR=rgb(44, 130, 201)]Business_Type[/COLOR]
    ,Contact_Person
    ,Contact_Nbr
    ,Contact_Email_Add
    ,Client_Name
    ,[COLOR=rgb(61, 142, 185)]Business_Type [/COLOR]AS [Business Type]
FROM Client_Data_qry
WHERE Client_Name LIKE "*" & Forms ! frmAdvancedSearch_Client_Data ! txtSearch2 & "*"
    OR Business_Type LIKE "*" & Forms ! frmAdvancedSearch_Client_Data ! txtSearch2 & "*"
    OR Contact_Person LIKE "*" & Forms ! frmAdvancedSearch_Client_Data ! txtSearch2 & "*"
    OR Contact_Nbr LIKE "*" & Forms ! frmAdvancedSearch_Client_Data ! txtSearch2 & "*"
    OR Contact_Email_Add LIKE "*" & Forms ! frmAdvancedSearch_Client_Data ! txtSearch2 & "*"
ORDER BY ID DESC;
 
Last edited:
Upvote 0
Sticks out a bit?
1591727636955.png
 

Attachments

  • 1591727579504.png
    1591727579504.png
    8.2 KB · Views: 5
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top