How To Do A VLookup In Access

This post is in response to this question:

This really doesn’t need any VBA code. It just needs to be setup correctly, and it functions like the VLookup function
in Excel.

In the image, we want to change the “Unit Price” (“PUnitPrice”) value after changing the the “Product Name” (“OProductID”) in the form.

The real key to how to do this is in the way the query is designed, and then you’ll make the form’s recordsource your query.

Here is the structure of “qryOrders”

The dropdown on the form is going to be based on the foreign key

When we use the foreign key, we can “VLookup” necessary items in the main table.

Click here for the database.

Let me know if you have any questions.





By the way, if you got or are getting value from the VBA information, please click the "Donate" button to give me a small token of your appreciation, thanks!


These posts may help answer your question too...

Learn Access VBA: Understand Tables, Queries, Forms, and Reports

Learn Access VBA: From Zero to Database Hero If you’ve ever opened Microsoft Access and wondered how all the pieces fit together — tables, queries, forms, and reports — this tutorial is made for you. In just a few minutes, you’ll understand how Access works behind the scenes and see how VBA (Visual Basic for […]

How to Fix Run Time Error 1004 in Excel

If you work with Microsoft Excel frequently, chances ar ling for a solution. Fortunately, this error is well-documented, and there are several ways to resolve it. In this article, we’ll explore the causes of run time error 1004, practical steps to fix it, and preventive measures to reduce the chances of it happening again. What […]

How To Escape Apostrophe In SQL Update Query

If you are looping a table with thousands of records, you’ll probably run into at least one that has an apostrophe in the field name. Like “Mike’s” or “M’cormick”, or something else. Anyway, here is one way to escape the string when you are doing your update query. Option Compare Database Sub YDriveLoop() ‘4/23/24 erik@loeblcomservices.com […]

How To Parse A Flat File In Excel VBA

In another post I demonstrated how to access a file on your computer using the MS Office Library. Here it is if you don’t know what I’m talking about. In this post, I am going to show you how to access the file and load it into your spreadsheet. I will do the same thing […]


Support these sponsors:
Previous Post

How To Create Dynamic Combo Boxes In Access

Next Post

How to setup cascading comboboxes in datasheet subform