MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Mar 29th, 2002, 04:00 AM   #1
mnmhenry
Board Regular
 
Join Date: Mar 2002
Posts: 143
Default

I currently use vlookup to lookup products in a seperate woorkbook. Can I have this database of products in Access and still refer to the infomation from excel ?

If I can, How do I do it ?

Thanks.
Mark Henry
mnmhenry is offline   Reply With Quote
Old Mar 29th, 2002, 04:44 AM   #2
Ian Mac
MrExcel MVP
 
Join Date: Feb 2002
Location: Newcastle, UK
Posts: 1,174
Default

Yes! It does depend on what you want to do with the data, I use Database queries, check the help files for this function.
__________________
"Have a good time......all the time"
Ian Mac
Ian Mac is offline   Reply With Quote
Old Mar 29th, 2002, 04:47 AM   #3
dk
MrExcel MVP
 
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
Default

Hi,

I don't think there's a way of doing this with built in formulas (I may be wrong). You could use this function which works in a similar way to VLOOKUP but for Access databases. You need to set a reference to the Microsoft ActiveX Data Object 2.x Library (from Tools, References in the VB editor).

Code:
Dim adoCN As ADODB.Connection
Dim strSQL As String

Public Function DBVLookUp(TableName As String, LookUpFieldName As String, LookupValue As String, ReturnField As String) As Variant
Dim adoRS As ADODB.Recordset
If adoCN Is Nothing Then SetUpConnection

Set adoRS = New ADODB.Recordset
strSQL = "SELECT " & LookUpFieldName & ", " & ReturnField & " FROM " & TableName & " WHERE " & LookUpFieldName & _
         "='" & LookupValue & "';"    ' If lookup value is a number then remove the two '
adoRS.Open strSQL, adoCN, adOpenForwardOnly, adLockReadOnly
DBVLookUp = adoRS.Fields(ReturnField).Value
adoRS.Close
End Function

Sub SetUpConnection()
On Error GoTo ErrHandler

Set adoCN = New Connection

adoCN.Provider = "Microsoft.Jet.OLEDB.4.0"  'Change to 3.51 for Access 97
adoCN.ConnectionString = "K:financemanagement reportingfinance reporting 2002.mdb" 'Change to your DB path
adoCN.Open
Exit Sub

ErrHandler:
MsgBox Err.Description, vbExclamation, "An error occurred"

End Sub
Hopefully, the function should be straightforward to use. TableName is obviously the name of the table in the database, LookupFieldName is the name of the field whose values you are searching, LookupValue is the value in LookupfieldName you are looking for and ReturnField is the name of the field whose matching value you wish to return. If there are more than 2 entries matching LookupValue then it will only return the first one.

HTH, any problems please repost,

Regards,
D
dk is offline   Reply With Quote
Old Mar 29th, 2002, 07:32 AM   #4
wi_guy
Board Regular
 
Join Date: Mar 2002
Posts: 50
Default

Yes you can do it, as Ian Said, it's called ODBC linking (Open database Connectivity i think)....A very handy / powerful feature to pull from Access or mainframe or other databases. The only problem I've found is that it can be a bit tricky to set up the linking, but if you are familiar with access, it shouldn't be too bad. It's under: DATA:GET EXTERNAL DATA: CREATE NEW QUERY
it walks you through, asking where the database and tables reside. One important step is where it asks you if you want to save the query......if you are going to use this more than once, save it to a name, then you can go through the DATA:GET EXTERNAL DATA: RUN EXTERNAL QUERY and the data will repopulate. Hope this helps
wi_guy is offline   Reply With Quote
Old Mar 29th, 2002, 07:49 AM   #5
wi_guy
Board Regular
 
Join Date: Mar 2002
Posts: 50
Default

I have an MS-Word document that I created for a presentation that gives step by step instructions for this....I'll email it to you.
wi_guy is offline   Reply With Quote
Old Mar 29th, 2002, 02:21 PM   #6
Ziggy
Board Regular
 
Join Date: Feb 2002
Location: Ontario, Canada
Posts: 326
Default


From Access Use the link table(get external data or from new table button) option to create a link between Excel for each sheet.

Then you'll have 2 tables in access changes in access will be referenced in Excel and vice versa.

Then create a new query from the 2 tables, to keep it simple you can just drag a join between the 2 tables (in query). Right click the join line and choose the appropriate selection for you. Then put the fields in you want to include in the query.

I do this all the time I have one table with stock listing and the other with order info, the query tells me how much stock is available for the orders.
Ziggy is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 12:03 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes