473,395 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to display SQL query results

I've been trying to build a search form in Access 2013 that takes the value of a single text box and searches it across a table.

What I would like it to do is search the table and if it finds a result, load the record into text boxes on the form for updating/exporting to another form/deleting.

After searching online I am using this search string:

Expand|Select|Wrap|Line Numbers
  1.  
  2. dim strSEARCH as string
  3. dim SQL ass string
  4.  
  5. SQL = "select * from tblcustdet where ((customername like ""*" & strSEARCH & "*"") or (Street like ""*" & strSEARCH & "*"") or (Suburb like ""*" & strSEARCH & "*"") or (PostCode like ""*" & strSEARCH & "*"") or (LandlineNumber like ""*" & strSEARCH & "*"") or (MobileNumber like ""*" & strSEARCH & "*"") or (EmailAddress like ""*" & strSEARCH & "*""))"
  6.  
It doesn't scream any errors at me when I run the string but I don't know how to make it display any results

Id love it to display a message box saying there are X results then load the first results into this table (http://imgur.com/rfehRRJ)

Maybe I over complicating things I honestly have no idea.

Edit: Does an SQL search look for the whole record or part? Like if you have first and last name as 1 field and you only enter the persons first name, will it still return a result?

Thanks
May 22 '16 #1
8 2361
PhilOfWalton
1,430 Expert 1GB
I'm not going to type the whole thing out, but you are missing a load of ampersands and too many double quotes.

Follow this pattern
Expand|Select|Wrap|Line Numbers
  1. WHERE ((customername like " & "*" & strSEARCH & "*")
  2.  OR (....))
  3.  
Phil
May 22 '16 #2
Thanks for the tip Phil.

Edit: why does it always, always generate new errors when putting the "correct" code in.... Time to find why it wants the end of a statement..
May 22 '16 #3
jforbes
1,107 Expert 1GB
I think part of your question is on how to display the results when you have them. Typically, for this, people use a Filter. This might help you: Example Filtering on a Form.
May 23 '16 #4
NeoPa
32,556 Expert Mod 16PB
Phil:
Follow this pattern
Or perhaps not exactly ;-) There appears to be an extraneous double-quote and ampersand (&) prior to the first asterisk string ("*"). Otherwise it should work. Jet/ACE SQL handles double-quotes (") as if they were proper SQL quotes (').

A generic template would be something like :
Expand|Select|Wrap|Line Numbers
  1. WHERE ([FieldName] Like '*XXX*')
  2.    OR (...)
where XXX represents the search item you want to filter on.

When creating your SQL string in VBA it will help use to use the standard SQL quotes (') as that won't be confused with the VBA string quotes (").

PS. There's nothing wrong with extra parentheses around your filter items, but it isn't necessary for SQL. If it helps you follow or read it then go for it. I find it easier to work without.
May 23 '16 #5
Thanks Neo

As I have been researching I found people creating sockets to their SQL DBs using declarations like:

Expand|Select|Wrap|Line Numbers
  1. Dim daMyName As New SqlDataAdapter
  2. Dim dsMyName As New DataSet
  3. Dim myConnection As New SqlConnection(myConnString)
  4. Dim myCommand As New SqlCommand(mySelectQuery, myConnection)
  5.  
but from what I can gather they are making external connections, IE connections to different servers. If everything is contained within 1 DB and not using an external SQL server, do I still need to envoke a SQL server connection to localhost?
May 24 '16 #6
NeoPa
32,556 Expert Mod 16PB
No idea. That's a separate question - and a good illustration of why only one should be included in a thread.

I would guess that's ADODB related, and I use that only when I have to. Post a new question and someone with that type of experience can pick it up and you won't need to rely on me for something I can't help with.

In DAO, for which there are no current plans to deprecate, as long as you're using local or linked tables, there would be no need to set up any type of connection to a separate database or server in your code.
May 24 '16 #7
Thanks a lot Neo. This is my first rodeo with SQL/DB programming.
Wish me luck
May 24 '16 #8
NeoPa
32,556 Expert Mod 16PB
Good luck Jailiin!!
May 25 '16 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: teddyparnell | last post by:
I have a slight problem as i am a bit weak on access skills, I am trying to run a query by selecting the criteria value from a combo box. I have got that to work and it produces results from the...
2
by: Steven Smith | last post by:
Hi guys What I'm trying to do today is display the results from an SQL query on one table in a Datagrid I'm using the following code to query the table. \\\ Try If...
16
by: dougmeece | last post by:
Good day everyone, I have a database with 2 main forms. The first form is used to add records to the database and contains a command button that opens the 2nd form for records searching. On...
4
by: dougmeece | last post by:
Good Morning again everyone, I am having trouble understanding how to display the results from my query in a subform instead of it opening a separate window. I have a form that queries a...
2
by: Amie | last post by:
Hi, how do you display the results of an sql query and display it onto the html form or html table Thanks
1
by: Arli | last post by:
I have the following linked tables: tblMainPL is my main table that I need to pull the information in from. It has the following fields: Autonumber1 -PK set as autonumber Date - short date...
4
by: kstevens | last post by:
(Yes... i capitalized the S on purpose) I didnt know before today that dlookup only found the first result. I am actually trying to display the results of a query in a report, but there are...
8
by: sunegtheoverlord | last post by:
Hello all, This is my first post and my first outing into the the world of web design and php so forgive me if i'm asking an obvious question. i have 2 php pages at the moment. a.php, calls...
3
by: Rob Wells | last post by:
Hi. I have a form with 5 buttons, each of which runs a slightly different query against the same table. I want to be able to display the query reults in a subform so that the user can click an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...

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.