Solved

Link to Access Databse and lookup values

Posted on 2011-09-06
1
211 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
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 …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

740 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