Solved

Link to Access Databse and lookup values

Posted on 2011-09-06
1
208 Views
Last Modified: 2012-05-12
I want to accomplish the following:

1. Link to an Access 2007 database (I dont want to import the data, I want to link to a table "tblProfit"
2. Look up the proft in the table based on the value in 2 cells, Catalog and ItemNumber.

Thanks
0
Comment
Question by:vmccune
1 Comment
 
LVL 6

Accepted Solution

by:
TinTombStone earned 500 total points
ID: 36489857
A User Defined Function like this may do it

PID is the key to indicate the row to return

returnField is the field whose value you want

this can then be called the worksheet as a normal function, as in the sceenshot

you will need to change the code to suit.


 Excel Screenshot
Function GetAccessData(pid As String, returnField As String)

Dim rst As ADODB.Recordset
Dim cnn As ADODB.Connection
Dim sourceDB As String
Dim SQLstr As String

    strsql = "Select * from Customers where CustomerID ='" & pid & "'" 'enter sql string
    sourceDB = "C:\Users\Steve\Desktop\ADM Practice.accdb"  'enter full path and filename

    Set cnn = New ADODB.Connection
    cnn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & sourceDB

    Set rst = New ADODB.Recordset
    cnn.Open
    rst.Open strsql, cnn

    GetAccessData = rst.Fields(returnField)

End Function

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

864 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now