How to Use DLookup in Microsoft Access

  Рет қаралды 19,099

Sean MacKenzie Data Engineering

Sean MacKenzie Data Engineering

Күн бұрын

DLookup is one of the most useful built-in functions in Microsoft Access. With this function, you can lookup a value from a table or query with ease. In most cases, it really makes the developer's job much easier, code simpler and easier to maintain, and to understand. In this video, learn how to use DLookup on forms, reports, VBA, and in queries. Plus, find out two pitfalls that you should watch out for while using this function.
Related Videos:
Getting Started with MS Access Visual Basic for Applications - VBA Code-Behind and Modules
• Getting Started with M...
VBA MsgBox - How to use message boxes in MS Access
• VBA MsgBox - How to us...
How to Use a Do Until Loop in MS Access VBA
• How to Use a Do Until ...
How to Use Iif in Microsoft Access
• How to Use Iif in Micr...
How to Use the Replace Function in Microsoft Access
• How to Use the Replace...
How to Use Nz in Microsoft Access to Handle Null and Empty Values
• How to Use Nz in Micro...
Iif, If Then Else, and Select Case in MS Access
• Iif, If Then Else, and...
How to Use DLookup in Microsoft Access
You are watching this video now!
How to Create and Configure a Custom Pop-Up Form in MS Access
• How to Create and Conf...
For developers looking for a new role, check out and sign up:
www.toptal.com/qKaO2b/worlds-...
Needing to hire technical resources for your project? Get the best:
www.toptal.com/qKaO2b/worlds-...
Want to get access to premium content made just for you and have a chat with me? Find me on Patreon :
/ mackenziedataengineering
Demo of my BZ RDP Cloaker:
www.patreon.com/posts/how-to-...
Want to work with me 1:1? Contact me today and book your free 20 min consultation!
Contact form you can find at www.mackenziemackenzie.com/
Follow me on social media:
/ mackenziedataanalytics
/ seamacke
/ seamacke
/ seamacke
/ psmackenzie
Get Microsoft Office including Access:
click.linksynergy.com/fs-bin/...
Got a KZbin Channel? I use TubeBuddy, it is awesome. Give it a try:
www.tubebuddy.com/seanmackenz...
• How to Use DLookup in ...

Пікірлер: 51
@balbumohshaba3588
@balbumohshaba3588 Жыл бұрын
Thank you sir for the tutorial. It's simple and easy to understand,
@seanmackenziedataengineering
@seanmackenziedataengineering Жыл бұрын
Glad it helped!
@grayquiksilver
@grayquiksilver Жыл бұрын
Another great tutorial - thanks Sean!!
@seanmackenziedataengineering
@seanmackenziedataengineering Жыл бұрын
Thanks!
@sakalansnow6579
@sakalansnow6579 2 жыл бұрын
Great thanks
@seanmackenziedataengineering
@seanmackenziedataengineering 2 жыл бұрын
You are welcome!
@sarak4617
@sarak4617 8 ай бұрын
Great video, thank you! Can you use DLookup with a continuous form? I have a continuous form and I would like to display the value from another table with each corresponding line of the continuous form. I have an identical linker in each table and I am using the continuous form as a sub form within another form for data entry (all fillable fields are from one table only, I want to display a value from another table along side the fillable data). I keep getting a #NAME? Error. Any suggestions on what I am doing wrong? I have checked over spelling many times.
@seanmackenziedataengineering
@seanmackenziedataengineering 8 ай бұрын
You bet! Yes you can do this, but you need to specify the field name on your form for the right parameters. For example, I did this one where the where clause needs quotes around the alphanumeric ID in the DLookup (you can also use multiple double-quotes instead of Chr 34): =DLookUp("[Country name]","CLIMATE_CHANGE_DATA","[Country code] = " & Chr(34) & [Country code] & Chr(34))
@letitiablake7243
@letitiablake7243 Жыл бұрын
Good afternoon. I have created inventory management for reselling mostly one-off items. I want to enter the product SKU in a textbox to look up the SKU of the product. Then have it return the record and all associated fields on the form. Can you suggest any video to me accomplish this? Thank you for your help.
@seanmackenziedataengineering
@seanmackenziedataengineering Жыл бұрын
Hi Letitia, you can do something similar to this, except use a "columnar" form instead of a continuous form: kzbin.info/www/bejne/q6KWlJqXfatpnMU The combo box will auto fill the SKU as you enter it, so eventually it auto-fills and you can select your SKU and the form updates.
@stanTrX
@stanTrX 5 ай бұрын
Hello Sean, thank you for the video. Which one would you recommend (considering performance etc) using dlookup in form level or in query level? Btw, does it also work properly in the form level, for continuoss forms also? (I remember some repetation problem i had before but maybe i was doing something wrong)
@seanmackenziedataengineering
@seanmackenziedataengineering 5 ай бұрын
It works on continuous forms and in queries. In continuous forms, you need to do the filter to the current record ID value or you will see duplicates. Either way is fine!
@mosjany
@mosjany 10 ай бұрын
Kindly i have a form frmivoice that has asubform frminvoicelines,how do I populate items from inventory table and prevent negative stockings
@seanmackenziedataengineering
@seanmackenziedataengineering 10 ай бұрын
Create a dropdown or text field and after the user chooses an item from inventory, check if there is inventory to fill the order using After Update (you can also use Before Update). If there isn't enough inventory, show a message and then clear the selection on that line. You can use this command: kzbin.info/www/bejne/qaW0maV8jpmebqc
@omarg5759
@omarg5759 2 жыл бұрын
Thanks Sean for the tutorial. Though I just have this challenging task, where there this two-tables database, the first one is linked from CSV and the other is just a table. The first table has column of two digit product codes and labels in the same cell, and the second has product codes on a column and different column for labels, which is the correct one I want to retrieve. What I tried to do is match the first two characters of the first table values with the codes of the second table through -> Dlookup(“Product labels”, “second table”, “left([Product codes and labels], 2) =“ & [Product codes]) but it didn’t work. Is there a way to do it through dlookup or I’m way too optimistic to try not to creat another query then link them?
@seanmackenziedataengineering
@seanmackenziedataengineering 2 жыл бұрын
If you have codes and labels in one field, you can make a query on the first table and split those like this: kzbin.info/www/bejne/rIK7YaeXhbZ_eJI Then, you can just use a dlookup on the product code, or create a query that joins by product code. You're better off to make a second query that gives all the rows you want using a join instead of dlookup, as dlookup might be slow if it is executed on every row. Good luck!
@omarg5759
@omarg5759 2 жыл бұрын
@@seanmackenziedataengineering Thanks a lot Sean for the reply and other structured tutorials. Happy holidays!
@caloebs
@caloebs Жыл бұрын
What does "1=1'" in the criteria argument mean/do? Dlookup('field','table',"1=1") - thanks for the video
@seanmackenziedataengineering
@seanmackenziedataengineering Жыл бұрын
1=1 is a starter expression that developers sometimes use when they are going to build a big dynamic Where clause on their query. If the user selected no criteria, then they can still use their SQL statement which returns all rows as their clause will be Where 1=1, which means all records. If a user chose something, then Where 1=1 And Field1 = 'ABC' will return additional filter for Field1, Where 1=1 And Field1 = 'ABC' And Field2 = 'DEF' etc. It is a lazy solution for the situation where you don't control whether the Where clause can be included or not (it must be included, but what if the user chooses nothing?)
@caloebs
@caloebs Жыл бұрын
@@seanmackenziedataengineering it looks like the prior programmer just wants the first record in the Table. I don't understand his logic but I guess that is what would happen with 1=1, correct? And many thanks
@seanmackenziedataengineering
@seanmackenziedataengineering Жыл бұрын
@@caloebs actually it just means True, allowing all records to be included. If you put 0 = 1 then it will kill the return set unless you use Or in the where clause. Funny hey?
@nemo9396
@nemo9396 2 жыл бұрын
What if my price is in a separate lookup table? Somehow I cannot make the Dlookup return the value in a different field, i.e. the foreign key.
@seanmackenziedataengineering
@seanmackenziedataengineering 2 жыл бұрын
That is ok! Perhaps fk = DLookup("key", "another table", "productname = 'abc'") Then price = DLookup("price", "this table", "key = '" & fk & "') Does that work?
@YvesAustin
@YvesAustin Жыл бұрын
Sean, as always great to review your videos. I am wondering if you have covered a topic equivalent to an Excel VLOOKUP() with a TRUE argument at the end (i.e. approximate match ascending sorted criteria). I am essentially trying to build a query where the related field should be based on an inequality: for bin sizes from 1 to 10 return "small", from 11 to 20 return "medium", from 21 t0 30 return "large", etc. As you can guess, the related table is much larger with about 15 to 20 bins. I initially attempted creating the inequality inside the SQL statement itself; it kind of worked for a while but crashes in a runtime version of Access and is not very robust (I will get runtime errors). I could create a master table with all sizes from 1 to 1000 with each their corresponding category, but that sounds like overkill. Managing a bunch of nested IIF() functions does not seem very efficient neither. Any tips from your end? Thanks again!
@seanmackenziedataengineering
@seanmackenziedataengineering Жыл бұрын
Great question. For this scenario, you can just plug a VBA function with Select Case in it. Something like: Function BinCategory(varValue) As String Dim lngValue As Long Dim strBinCategory As String lngValue = Nz(varValue, 0) Select Case lngValue Case Is > 30: strBinCategory = "X Large" Case Is > 20: strBinCategory = "Large" Case Is > 10: strBinCategory = "Medium" Case Else: strBinCategory = "Small" End Select BinCategory = strBinCategory End Function I did that in the comments editor so it might have mistakes but you get the idea. Then, in your query, just plug it in a field: MyBinCategory = BinCategory([BinCount]) And you're done! The order on the Select Case is important, so that it exits in the right place. ie. if you put Case is > 10 as the first Case then everything will be Medium and Small! Cheers
@YvesAustin
@YvesAustin Жыл бұрын
@@seanmackenziedataengineering Thanks for the quick reply. Yes, I will def use that criteria which is straightforward. I should have clarified that my initial inequality in the SQL statement was on the LEFT JOIN itself not in the WHERE clause. And that is why it certainly created errors (although it is an interesting exercise to attempt creating a join using an inequality!!).
@seanmackenziedataengineering
@seanmackenziedataengineering Жыл бұрын
@@YvesAustin That's a great exercise for SQL. While I rarely use less/greater than in joins, I see it in the wild a fair bit. Another neat one is leaving the join syntax out but then putting the join in the Where clause. It makes you realize the many different ways that one task can be accomplished!
@stanTrX
@stanTrX 5 ай бұрын
Sean, can you please give link to your video you mentioned here 14:31
@seanmackenziedataengineering
@seanmackenziedataengineering 5 ай бұрын
This is the video on lag and lead in MS Access: kzbin.info/www/bejne/b5q2pnxpmbdqa9E You can see how slow it will be with DLookup, if you have many rows. With just a few rows, it is fine though.
@stanTrX
@stanTrX 5 ай бұрын
@@seanmackenziedataengineering thank you 🙏
@tutsecret499
@tutsecret499 Жыл бұрын
DLookup and After Update. Instead of selecting, or typing from the cbo field. If I import or paste countries would the field cboCountry work, and populate the RaceGroup? Example: I have cboCountry, and populates the RaceGroup textbox. example: if it's typed or paste or select from cboCountry the Phillipines country, the RaceGroup would populate Filipino and so forth. So instead I click, select from the dropdown cbo, Sometimes I receive hundreds of rows to import where with countries and individuals, and the RaceGroup field needs to be populated with the RaceGroup: White or Hispanic, Filipino and so forth. I have to use excel to use the vlookup or xlookup to populate the RaceGroup in Excel then I import everything ready to Access. But I want to do this in Access. It's ridiculous we have to use Excel to help Access. This happens to other people too. The hand aches suffers injuries if clicking too much on the combo box and selecting when dealing with too much data daily.
@seanmackenziedataengineering
@seanmackenziedataengineering Жыл бұрын
If you imported the table with the country and group, you can use DLookup and After Update. Go for it! That will save you some typing. There are two kinds of After Update and you will use this one: kzbin.info/www/bejne/qaW0maV8jpmebqc Also, if you look closely, at 2:41 I briefly show DLookup with two conditions in the Where clause, in case you need Field1 = "abc" AND Field2 = "def". No need to hurt fingers with too much typing!
@tutsecret499
@tutsecret499 Жыл бұрын
@@seanmackenziedataengineering When I import or append data. There is no RaceGroup, only the countries, thus I need to populate the RaceGroup that is blank in my database that is blank. The imported/appended data is from external source and they don't provide the RaceGroup only countries. Thank you.
@afrinsir7479
@afrinsir7479 9 ай бұрын
dlookup is good but too slow is there any other technique for that ?
@seanmackenziedataengineering
@seanmackenziedataengineering 9 ай бұрын
Great question! DLookup will indeed be too slow, especially if you use it in a query where it must execute on every row. For those cases, you should use a set-based approach instead. You can see examples here: kzbin.info/www/bejne/a5TRqHuvo5mXpKs
@tamalchakraborty1277
@tamalchakraborty1277 2 жыл бұрын
Property sheets of all forms of a MS Access database are locked. How to unlock it?
@seanmackenziedataengineering
@seanmackenziedataengineering 2 жыл бұрын
What is the file extension? Is it .accdb or .accde?
@HenrySen-Opoku
@HenrySen-Opoku 5 ай бұрын
Sean, I love your videos. Can you use DLookup to look for values in an entire field not a specific value in a field. Eg. DLookup("AmountPaid","tblMain", "[Date]=Year(Date())-1)" . (Previous Year Payment) This code seeks to lookup for the values of the entire field but only works on the first record and repeat the same value on the other records. Maybe DLookup is not the appropriate code for this function, please advice me.
@seanmackenziedataengineering
@seanmackenziedataengineering 5 ай бұрын
Great question - DLookup is indeed only for one value. It looks like you are using DLookup in a query and just need one more criteria. ie. "[Date]=Year(Date())-1) And [CustomerID] = [IDField]" If in the same table, CustomerID and IDField might have the same name.
@henrysen-opoku590
@henrysen-opoku590 5 ай бұрын
Thank you. You are the best. Will try the suggested codes and get back to you.@@seanmackenziedataengineering
@satyabanukil779
@satyabanukil779 2 ай бұрын
Sir a very small and simple query. Does "On Got Focus" work in a tabular form ?
@seanmackenziedataengineering
@seanmackenziedataengineering 2 ай бұрын
You can test it - put a MsgBox in there and see if you can trigger it. Give it a try 👍
@satyabanukil779
@satyabanukil779 2 ай бұрын
@@seanmackenziedataengineering Thank you Sir. On Got Focus working in tabular form also. Still not successful in implementation of your advice sent 3 days ago on using "On Current" event. Sir if you get time may kindly look at that. Regards
@tomscroggin6582
@tomscroggin6582 7 ай бұрын
After all of the explanation, the one thing I need is the proper expression. Can't see it! Curser is on top and you didn't expand the text box enough so the expression can be read. Final got it, but it didn't work in my database.
@seanmackenziedataengineering
@seanmackenziedataengineering 7 ай бұрын
Check out the big red letters at the bottom of the screen at 6:25 - I put the expression I'm typing there so you can see it.
@HenrySen-Opoku
@HenrySen-Opoku 5 ай бұрын
Hi, Sean. Plaese, still waiting for your reply.
@seanmackenziedataengineering
@seanmackenziedataengineering 5 ай бұрын
Replied on your other thread
@harshmancegroupllc4517
@harshmancegroupllc4517 Жыл бұрын
Hi Sean, I am trying to geta Dlookup to find a price from another table but it is not working and has a #Error come up in the query table. I am trying to get [Price] from table "WorkPerformedPrices" by matching [Work Performed]. My code is: WPrice: DLookUp("Price","WorkPerformedPrices","Work Performed=" & [Work Performed]) Is the space in work performed causing the issue?
@harshmancegroupllc4517
@harshmancegroupllc4517 Жыл бұрын
When I click on the error box it says: Syntex error (missing operator) in query expression "Work Performed=Engineer" where Engineer is what is in the work performed box.
@seanmackenziedataengineering
@seanmackenziedataengineering Жыл бұрын
If [Work Performed] is text, you would need the last argument to be: "[Work Performed] = '" & [Work Performed] & "'" Note the single and double quotes used. Good luck!
@harshmancegroupllc4517
@harshmancegroupllc4517 Жыл бұрын
@@seanmackenziedataengineering Thank you so much!!
How to Create and Configure a Custom Pop-Up Form in MS Access
11:41
Sean MacKenzie Data Engineering
Рет қаралды 9 М.
How to Make Cascading Combo Boxes in MS Access
16:08
Sean MacKenzie Data Engineering
Рет қаралды 30 М.
Дибала против вратаря Легенды
00:33
Mr. Oleynik
Рет қаралды 4,5 МЛН
КАРМАНЧИК 2 СЕЗОН 7 СЕРИЯ ФИНАЛ
21:37
Inter Production
Рет қаралды 482 М.
Must-have gadget for every toilet! 🤩 #gadget
00:27
GiGaZoom
Рет қаралды 12 МЛН
How to use DLOOKUP function + AFTER UPDATE function in Ms Access.
8:33
Edcelle John Gulfan
Рет қаралды 10 М.
How to Open a RecordSet in Access VBA and Loop Through the Records
12:45
Sean MacKenzie Data Engineering
Рет қаралды 25 М.
What to do if DLookup is Slow in your Microsoft Access Database
15:05
Computer Learning Zone
Рет қаралды 3,2 М.
How to Use Form and Subform Variables in Microsoft Access
16:21
Sean MacKenzie Data Engineering
Рет қаралды 4,6 М.
Is Microsoft Access Still Viable in 2024?
21:19
Advantage Applications
Рет қаралды 37 М.
Microsoft Access Tips | How to use VBA Recordsets and Modules
19:23
LoopLearnings
Рет қаралды 2,7 М.
How to Use a Pass Through Query in MS Access - SQL Server Example
18:34
Sean MacKenzie Data Engineering
Рет қаралды 16 М.
How to Create a Lookup Field in a Table in Microsoft Access
13:37
MyExcelOnline.com
Рет қаралды 4,6 М.
1$ vs 500$ ВИРТУАЛЬНАЯ РЕАЛЬНОСТЬ !
23:20
GoldenBurst
Рет қаралды 1,5 МЛН
Blue Mobile 📲 Best For Long Audio Call 📞 💙
0:41
Tech Official
Рет қаралды 1 МЛН
Неразрушаемый смартфон
1:00
Status
Рет қаралды 2,3 МЛН
Best mobile of all time💥🗿 [Troll Face]
0:24
Special SHNTY 2.0
Рет қаралды 2,2 МЛН
Худший продукт Apple
0:53
Rozetked
Рет қаралды 135 М.
iPhone 16 с инновационным аккумулятором
0:45
ÉЖИ АКСЁНОВ
Рет қаралды 2 МЛН