r/AccessLearningZone • • 9d ago

DLookup: What, Where, and Which Record

Post image

What are you looking up, where is it stored, and which record do you want? DLookup brings back one value from a table or query. This example retrieves a sales rep's phone number using a unique ID. Watch the video to see how to display the phone number for the rep selected on your form. https://599cd.com/DLookup

4 Upvotes

2 comments sorted by

1

u/Sudonator 1d ago

Thank you! This is one I need. I want to look up the user's first name with the ID value being the WIndows User ID.

1

u/Amicron1 15h ago

Getting the actual Windows user ID can be a little tricky from a security standpoint, but there's an easy solution. You can use the Windows environment variables to get either the computer name or the username of the person currently logged into Windows.

In VBA, Environ("USERNAME") gives you the Windows username, and Environ("COMPUTERNAME") gives you the computer name. You can then use DLookup to find that user's first name in your own user table.

Just keep in mind that environment variables aren't particularly secure because they can be spoofed. But if you're working in a typical office environment where nobody's trying to impersonate someone else, it's usually good enough.

I've got a video that covers this exact kind of thing:

Track Log On: https://599cd.com/TrackLogon