?
Solved

Link to Access Databse and lookup values

Posted on 2011-09-06
1
Medium Priority
?
215 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 2000 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

764 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