Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


vba code to query sql db from excel

Posted on 2008-11-04
Medium Priority
Last Modified: 2012-05-05
I have an excel sheet with 2 rows of information. the first row is numbers/id's. I have a sql db with more information for each id. I want to query the db and for each id, to return the rest of the info into excel. So Select where id=value in the cells in the first column. I can conect to the db so that part is working but I can't / do not know how to fit in the where properly. so here is the way i think it has to be. I get the id in cell one, search through the whole datatbase for that id and return the results in the next columns. then i move on cells 2 and so on. any help is appreciated
Question by:j8547
1 Comment

Accepted Solution

tony_angelopoulos earned 750 total points
ID: 22878204
I would hesitate about making a function connect to a database because you will be opening and closing connections and causing quite a mess.  I would in a separate spreadsheet connect to the database and pull in a range of records through ODBC (or ado if you don't want to use a hard connection).  Then I would use Vlookup to retrieve the records from the page you just pulled in.  You could hide the page from the end  user, and refresh the data when the workbook is opened.  It would be much quicker that way.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question