Avatar of Connie Jerdet-Skehan
Connie Jerdet-Skehan
Flag for United States of America asked on

query linked sql table field from access

I am using access 365 and Sql Server 2014

I have two buttons, one to show all records in a linked sql table,the other, to perform a search for keywords in the same linked sql table.
The table is linked and connected using adodb.connection when the access database is opened. Please show me what changes I need to make for the desired results.

The code I am using is not producing the results I am looking for.
below is my code for each

To show all records in table

dim sql as string.

sql = "SELECT company.companyId, company.companyName, company.companyAddress, company.companyCity, company.companyState, company.companyZip, company.companyPhone, company.InCareOfName, company.Exclude, company.Keep, company.Reason, company.AccessNumber, company.Change " _
    & "FROM company " _
    & "ORDER BY company.companyName "
   
   
    Me.txtPltfkeywords = ""
    Me.companyList.Form.RecordSource = sql
    Me.companyList.Form.Requery

To search for keywords within the table

Dim sql As String

    sql = "SELECT company.companyID, company.companyName, company.InCareOfName, company.Exclude, company.Reason, company.companyPhone, company.companyAddress, company.companyCity, company.companyState, company.companyZip, company.Keep, company.AccessNumber, company.Change " _
& "FROM company " _
& "WHERE companyName Like ""*" & txtPltfkeywords & "*"" Or companyAddress Like ""*" & txtPltfkeywords & "*"" Or companyCity Like ""*" & txtPltfkeywords & "*"" Or Reason Like ""*" & txtPltfkeywords & "*"" Or companyState Like ""*" & txtPltfkeywords & "*"" Or companyZip Like ""*" & txtPltfkeywords & "*"" Or companyPhone Like ""*" & txtPltfkeywords & "*"" Or InCareOfName Like ""*" & txtPltfkeywords & "*""" _
& "ORDER BY company.companyName "
   
    Me.companyList.Form.RecordSource = sql
    Me.companyList.Form.Requery
Microsoft AccessMicrosoft SQL Server

Avatar of undefined
Last Comment
John Tsioumpris

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Ryan Chong

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Nitin Sontakke

If I seeing it right, use % instead of *. That's the correct equivalent of * in SQL Server.
Connie Jerdet-Skehan

ASKER
Your suggestion worked after a typo error I made. Thank you.
John Tsioumpris

If you are querying a linked table then you will use *...if you are using a passthrough query you should use %
Take your query to SSMS and change the wildcard from * to %...check the results and report back...
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck