473,385 Members | 1,326 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,385 software developers and data experts.

How to write VBA code to search for a value through a database in Excel

Hello,

I really need help with this problem I'm facing. I'm writing a recipe guide program using VBA form. I got to the part where the user can type in an ingredient and I need the program to search through the Ingredients column in my data excel file.
For example, the user wants to look for recipe that contains ORANGE JUICE in the ingredient list.
If the ingredient is found in a cell, say E5, then I need to have a code that would be able to pick up the name of the recipe that contains the ingredients (name would be in D5). I attached a picture of how my data base look.



Also, since I have to use VBA form, I'm currently using a list box to output all of the results that the program can find from the database.

I tried to record macro and using the Find option in Excel but the result didn't turn out very well. The code I found
Range("D2:D19100").Select
Selection.Find(What:="Orange Juice", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate

need to have a Selection.FindNext(After:=ActiveCell).Activate after every line and there's no way the program can look at the column before it for the name and output it in my list box.

I really need help with this problem.

Thank you for your time reading this.
Dec 9 '09 #1
3 4115
Guido Geurs
767 Expert 512MB
dear,

Attached is a excel macro which find the ingredients in a list like yours.

If you have still problems, please let me know.

br,
Attached Files
File Type: zip search value trough data_v2.zip (10.7 KB, 362 views)
Dec 13 '09 #2
lorong
1
uhm let me ask first...
1.) are you using ADODC,DAO or ODBC?
2.) is your problem displaying the content of your table with specified values?

here is a sample using ADODC
first put adodc
next use jet engine to connect to database after that code this

with adodc1
.recordsource = "select from (your table name) where (field name) = ' " & (textbox or other ways to compare) & " ' "
'/note the formate for where is single cote(') then double cote(") amperes AND(&) then your field to be searched(i.e. text1.text) then do the reverse amperes AND(&) double cote(") single cote(')
.refresh
if .BOF = false then
.recordset.movefirst
end if
while not .recordset.EOF then

list1.additem = .recordset.fields(the field you want to display)

wend
end with


thats all.. email me if you still got probs using adodc (j_thugrhymz@yahoo.com)
Feb 19 '10 #3
@Guido Geurs
YOU-ARE-AWESOME!!! THANKS!
I didn't knew the INSTR function.
You saved me a lot of work.
Feb 18 '14 #4

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

Similar topics

1
by: karenmiddleol | last post by:
I want to create a Excel OWC component and read data from the Orders table of the Northwind database and write into the OWC component. Can you kindly share the code. Thanks Karen
8
by: jquest | last post by:
Hi Again; I have had help from this group before and want to thank everyone, especially PCDatasheet. My database includes a field called HomePhone, it uses the (xxx)xxx-xxx format to include...
6
by: allyn44 | last post by:
Hi---I have to import some data from excel into an Access table--the code below is working ok but I would like to condense it by running a loop. The number of records can vary from 1 to 30 in each...
8
by: Steph | last post by:
Hi. I'm very new to MS Access and have been presented with an Access database of contacts by my employer. I am trying to redesign the main form of the database so that a button entitled...
4
by: Seok Bee | last post by:
Dear Experts, I have created a script to extract the Event Logs from the system into an excel sheet. The logs are separated into 2 worksheets (Application Log and System Log). After this excel...
3
by: josh.kuo | last post by:
Sorry about the subject, I can't think of a better one. I recently wrote some PHP classes that I think might be of interest to this group. Since I have been reaping the benefits of reading news...
1
by: jrs_14618 | last post by:
Hello All, This post is essentially a reply a previous post/thread here on this mailing.database.myodbc group titled: MySQL 4.0, FULL-TEXT Indexing and Search Arabic Data, Unicode I was...
2
by: bbasberg | last post by:
I have been working hard to clean up my code but I am still wondering why all incoming records go to the "AddNew" part of the IF statement and never to the Edit alternative. I believe that it must be...
0
by: dprjessie | last post by:
Hello, I am a Web programmer and I'm working on my first desktop application as a favor for a friend. I'm sure I have a stupid error here, but there is no error being thrown so I can't figure out...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.