Solved

Link to Access Databse and lookup values

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

777 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