troubleshooting Question

query linked sql table field from access

Avatar of Connie Jerdet-Skehan
Connie Jerdet-SkehanFlag for United States of America asked on
Microsoft AccessMicrosoft SQL Server
4 Comments1 Solution101 ViewsLast Modified:
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

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
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros