Solved

Link to Access Databse and lookup values

Posted on 2011-09-06
1
206 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

707 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

20 Experts available now in Live!

Get 1:1 Help Now